Mercurial > vim
annotate src/os_win32.c @ 31010:4b9b76aac30c v9.0.0840
patch 9.0.0840: cannot change a slice of a const list
Commit: https://github.com/vim/vim/commit/adbc08fd69433b5216e609a404d674f3e67eea9c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 6 18:27:17 2022 +0000
patch 9.0.0840: cannot change a slice of a const list
Problem: Cannot change a slice of a const list. (Takumi KAGIYAMA)
Solution: Remove the const flag from the slice type. (closes https://github.com/vim/vim/issues/11490)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Nov 2022 19:30:08 +0100 |
parents | d63bb3fa9939 |
children | 467d950013a1 |
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; | |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
103 typedef int BOOLEAN; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
104 typedef int CALLBACK; |
7 | 105 typedef int COLORREF; |
106 typedef int CONSOLE_CURSOR_INFO; | |
107 typedef int COORD; | |
108 typedef int DWORD; | |
109 typedef int HANDLE; | |
7668
21b0a39d13ed
commit https://github.com/vim/vim/commit/ef26954a35207c3f17d6ed35d9a40c918d974892
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
110 typedef int LPHANDLE; |
7 | 111 typedef int HDC; |
112 typedef int HFONT; | |
113 typedef int HICON; | |
114 typedef int HINSTANCE; | |
115 typedef int HWND; | |
116 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
|
117 typedef int INT; |
7 | 118 typedef int KEY_EVENT_RECORD; |
119 typedef int LOGFONT; | |
120 typedef int LPBOOL; | |
121 typedef int LPCTSTR; | |
122 typedef int LPDWORD; | |
123 typedef int LPSTR; | |
124 typedef int LPTSTR; | |
125 typedef int LPVOID; | |
126 typedef int MOUSE_EVENT_RECORD; | |
127 typedef int PACL; | |
128 typedef int PDWORD; | |
129 typedef int PHANDLE; | |
130 typedef int PRINTDLG; | |
131 typedef int PSECURITY_DESCRIPTOR; | |
132 typedef int PSID; | |
133 typedef int SECURITY_INFORMATION; | |
134 typedef int SHORT; | |
135 typedef int SMALL_RECT; | |
136 typedef int TEXTMETRIC; | |
137 typedef int TOKEN_INFORMATION_CLASS; | |
138 typedef int TRUSTEE; | |
139 typedef int WORD; | |
140 typedef int WCHAR; | |
141 typedef void VOID; | |
3927 | 142 typedef int BY_HANDLE_FILE_INFORMATION; |
5112
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
143 typedef int SE_OBJECT_TYPE; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
144 typedef int PSNSECINFO; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
145 typedef int PSNSECINFOW; |
6359 | 146 typedef int STARTUPINFO; |
147 typedef int PROCESS_INFORMATION; | |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
148 typedef int LPSECURITY_ATTRIBUTES; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
149 # define __stdcall // empty |
7 | 150 #endif |
151 | |
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
|
152 #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
|
153 // Win32 Console handles for input and output |
7 | 154 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; |
155 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; | |
156 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
157 // Win32 Screen buffer,coordinate,console I/O information |
7 | 158 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
|
159 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
|
160 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
161 // 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
|
162 static WORD g_attrDefault = 7; // lightgray text on black background |
7 | 163 static WORD g_attrCurrent; |
164 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
165 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
|
166 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
|
167 static int g_fForceExit = FALSE; // set when forcefully exiting |
7 | 168 |
169 static void scroll(unsigned cLines); | |
170 static void set_scroll_region(unsigned left, unsigned top, | |
171 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
|
172 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
|
173 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
|
174 static void insert_lines(unsigned cLines); |
7 | 175 static void delete_lines(unsigned cLines); |
176 static void gotoxy(unsigned x, unsigned y); | |
177 static void standout(void); | |
178 static int s_cursor_visible = TRUE; | |
179 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
|
180 #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
|
181 #ifdef FEAT_GUI_MSWIN |
7 | 182 static int s_dont_use_vimrun = TRUE; |
183 static int need_vimrun_warning = FALSE; | |
184 static char *vimrun_path = "vimrun "; | |
185 #endif | |
186 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
187 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
188 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
|
189 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
190 |
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_working = 0; |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 |
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
|
197 #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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
204 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
|
205 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
|
206 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 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
|
211 |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
212 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
|
213 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
|
214 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
215 # ifdef FEAT_TERMGUICOLORS |
30013
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
216 static int default_console_color_bg = 0x000000; // black |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
217 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
|
218 # endif |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
219 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
220 # 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
|
221 # 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
|
222 # 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
|
223 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
224 # define 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
|
225 # 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
|
226 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
227 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
232 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
233 // 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
|
234 #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
|
235 # 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
|
236 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
237 |
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
|
238 #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
|
239 static int suppress_winsize = 1; // don't fiddle with console |
7 | 240 #endif |
241 | |
2612 | 242 static char_u *exe_path = NULL; |
243 | |
5633 | 244 static BOOL win8_or_later = FALSE; |
245 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
246 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
247 * 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
|
248 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
249 typedef BOOL (WINAPI *PfnRtlGetVersion)(LPOSVERSIONINFOW); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
250 #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
|
251 (((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
|
252 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
253 static DWORD |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
254 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
|
255 { |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
256 OSVERSIONINFOW osver; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
261 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
262 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
|
263 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
|
264 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
265 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
266 (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
|
267 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
|
268 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
|
269 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
|
270 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
|
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 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
|
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 |
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
|
275 #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
|
276 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
|
277 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
|
278 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
|
279 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
280 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
|
281 && 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
|
282 && 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
|
283 && 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
|
284 && ir->Event.KeyEvent.wVirtualScanCode == 0x38 |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
285 && ir->Event.KeyEvent.uChar.UnicodeChar == 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
|
286 && 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
|
287 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
288 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 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
|
293 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
294 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
|
295 down->Event.KeyEvent.wVirtualScanCode = 0; |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
296 down->Event.KeyEvent.uChar.UnicodeChar |
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
297 = up->Event.KeyEvent.uChar.UnicodeChar; |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
298 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
|
299 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
300 |
5580 | 301 /* |
302 * Version of ReadConsoleInput() that works with IME. | |
5590 | 303 * Works around problems on Windows 8. |
5580 | 304 */ |
305 static BOOL | |
306 read_console_input( | |
5590 | 307 HANDLE hInput, |
308 INPUT_RECORD *lpBuffer, | |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
309 int nLength, |
5590 | 310 LPDWORD lpEvents) |
5580 | 311 { |
312 enum | |
313 { | |
5590 | 314 IRSIZE = 10 |
5580 | 315 }; |
5590 | 316 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 317 static DWORD s_dwIndex = 0; |
318 static DWORD s_dwMax = 0; | |
5590 | 319 DWORD dwEvents; |
5635 | 320 int head; |
321 int tail; | |
322 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
|
323 static INPUT_RECORD s_irPseudo; |
5580 | 324 |
6981 | 325 if (nLength == -2) |
326 return (s_dwMax > 0) ? TRUE : FALSE; | |
327 | |
5633 | 328 if (!win8_or_later) |
329 { | |
330 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
331 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
332 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 333 } |
334 | |
5580 | 335 if (s_dwMax == 0) |
336 { | |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
337 if (!USE_WT && nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 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
|
342 ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents); |
5580 | 343 s_dwIndex = 0; |
5590 | 344 s_dwMax = dwEvents; |
345 if (dwEvents == 0) | |
5580 | 346 { |
5590 | 347 *lpEvents = 0; |
348 return TRUE; | |
5580 | 349 } |
5635 | 350 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 |
5635 | 355 if (s_dwMax > 1) |
356 { | |
357 head = 0; | |
358 tail = s_dwMax - 1; | |
359 while (head != tail) | |
360 { | |
361 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
362 && s_irCache[head + 1].EventType | |
363 == WINDOW_BUFFER_SIZE_EVENT) | |
364 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
365 // Remove duplicate event to avoid flicker. |
5635 | 366 for (i = head; i < tail; ++i) |
367 s_irCache[i] = s_irCache[i + 1]; | |
368 --tail; | |
369 continue; | |
370 } | |
371 head++; | |
372 } | |
373 s_dwMax = tail + 1; | |
374 } | |
5580 | 375 } |
5635 | 376 |
20183
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
377 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
|
378 { |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
379 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
|
380 { |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
381 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
|
382 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
|
383 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
|
384 *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
|
385 *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
|
386 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
|
387 } |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
388 } |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
389 |
5590 | 390 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 391 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 392 s_dwMax = 0; |
5590 | 393 *lpEvents = 1; |
5580 | 394 return TRUE; |
395 } | |
396 | |
397 /* | |
398 * Version of PeekConsoleInput() that works with IME. | |
399 */ | |
400 static BOOL | |
401 peek_console_input( | |
5590 | 402 HANDLE hInput, |
403 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
|
404 DWORD nLength UNUSED, |
5590 | 405 LPDWORD lpEvents) |
5580 | 406 { |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
407 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 408 } |
409 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
410 # ifdef FEAT_CLIENTSERVER |
6981 | 411 static DWORD |
412 msg_wait_for_multiple_objects( | |
413 DWORD nCount, | |
414 LPHANDLE pHandles, | |
415 BOOL fWaitAll, | |
416 DWORD dwMilliseconds, | |
417 DWORD dwWakeMask) | |
418 { | |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
419 if (read_console_input(NULL, NULL, -2, NULL)) |
6981 | 420 return WAIT_OBJECT_0; |
421 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
422 dwMilliseconds, dwWakeMask); | |
423 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
424 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
425 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
426 # ifndef FEAT_CLIENTSERVER |
6981 | 427 static DWORD |
428 wait_for_single_object( | |
429 HANDLE hHandle, | |
430 DWORD dwMilliseconds) | |
431 { | |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
432 if (read_console_input(NULL, NULL, -2, NULL)) |
6981 | 433 return WAIT_OBJECT_0; |
434 return WaitForSingleObject(hHandle, dwMilliseconds); | |
435 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
436 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
437 #endif |
6981 | 438 |
7 | 439 static void |
440 get_exe_name(void) | |
441 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
442 // 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
|
443 // as the maximum length that works (plus a NUL byte). |
2630 | 444 #define MAX_ENV_PATH_LEN 8192 |
445 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 446 char_u *p; |
7 | 447 |
448 if (exe_name == NULL) | |
449 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
450 // store the name of the executable, may be used for $VIM |
2630 | 451 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 452 if (*temp != NUL) |
453 exe_name = FullName_save((char_u *)temp, FALSE); | |
454 } | |
819 | 455 |
2612 | 456 if (exe_path == NULL && exe_name != NULL) |
819 | 457 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20593
diff
changeset
|
458 exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name); |
2612 | 459 if (exe_path != NULL) |
819 | 460 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
461 // 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
|
462 // "!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
|
463 // SearchPath() also looks there. |
2612 | 464 p = mch_getenv("PATH"); |
2630 | 465 if (p == NULL |
466 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 467 { |
2630 | 468 if (p == NULL || *p == NUL) |
469 temp[0] = NUL; | |
470 else | |
471 { | |
472 STRCPY(temp, p); | |
473 STRCAT(temp, ";"); | |
474 } | |
2612 | 475 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
476 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 477 } |
819 | 478 } |
479 } | |
7 | 480 } |
481 | |
2612 | 482 /* |
3361 | 483 * Unescape characters in "p" that appear in "escaped". |
484 */ | |
485 static void | |
486 unescape_shellxquote(char_u *p, char_u *escaped) | |
487 { | |
3386 | 488 int l = (int)STRLEN(p); |
3361 | 489 int n; |
490 | |
491 while (*p != NUL) | |
492 { | |
493 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
494 mch_memmove(p, p + 1, l--); | |
495 n = (*mb_ptr2len)(p); | |
496 p += n; | |
497 l -= n; | |
498 } | |
499 } | |
500 | |
501 /* | |
2612 | 502 * Load library "name". |
503 */ | |
504 HINSTANCE | |
27657
a077948be0f4
patch 8.2.4354: dynamic loading of libsodium not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
27581
diff
changeset
|
505 vimLoadLib(const char *name) |
2612 | 506 { |
3902 | 507 HINSTANCE dll = NULL; |
3889 | 508 |
24563
30ad18017e1c
patch 8.2.2821: MS-Windows: unnessarily loading libraries when registering OLE
Bram Moolenaar <Bram@vim.org>
parents:
24506
diff
changeset
|
509 // 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
|
510 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
|
511 return dll; |
30ad18017e1c
patch 8.2.2821: MS-Windows: unnessarily loading libraries when registering OLE
Bram Moolenaar <Bram@vim.org>
parents:
24506
diff
changeset
|
512 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
513 // 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
|
514 // vimLoadLib() recursively, which causes a stack overflow. |
2612 | 515 if (exe_path == NULL) |
516 get_exe_name(); | |
3902 | 517 if (exe_path != NULL) |
2612 | 518 { |
3902 | 519 WCHAR old_dirw[MAXPATHL]; |
520 | |
521 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
522 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
523 // 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
|
524 // 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
|
525 // in the current directory. |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
526 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 527 dll = LoadLibrary(name); |
528 SetCurrentDirectoryW(old_dirw); | |
529 return dll; | |
530 } | |
2612 | 531 } |
532 return dll; | |
533 } | |
534 | |
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
|
535 #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
|
536 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
537 * 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
|
538 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
539 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
|
540 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
|
541 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 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
|
554 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
555 #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
|
556 |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
557 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) \ |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
558 || defined(FEAT_PYTHON3) || defined(PROTO) |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
559 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
560 * 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
|
561 * 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
|
562 * If 'info' is 1, return the module name which the function is imported from. |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
563 * If 'info' is 2, hook the function with 'ptr', and return the original |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
564 * function address. |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
565 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
566 static void * |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
567 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info, |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
568 const void *ptr) |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
569 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 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
|
582 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
583 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
|
584 + 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
|
585 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
586 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
|
587 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
588 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
|
589 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
590 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
|
591 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
|
592 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
|
593 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
594 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
|
595 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
596 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
|
597 + (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
|
598 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
|
599 { |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
600 void *original; |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
601 DWORD old, new = PAGE_READWRITE; |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
602 |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
603 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
|
604 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 return (void *)(pImage + pImpDesc->Name); |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
609 case 2: |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
610 original = (void *)pIAT->u1.Function; |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
611 VirtualProtect(&pIAT->u1.Function, sizeof(void *), |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
612 new, &old); |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
613 pIAT->u1.Function = (UINT_PTR)ptr; |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
614 VirtualProtect(&pIAT->u1.Function, sizeof(void *), |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
615 old, &new); |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
616 return original; |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
617 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
618 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
|
619 } |
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 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
622 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
623 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
|
624 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
625 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
626 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
627 * 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
|
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 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
630 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
|
631 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
632 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
|
633 |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
634 modulename = (char *)get_imported_func_info(hInst, funcname, 1, NULL); |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 } |
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 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
641 * 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
|
642 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
643 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
644 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
|
645 { |
27581
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
646 return get_imported_func_info(hInst, funcname, 0, NULL); |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
647 } |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
648 |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
649 /* |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
650 * Hook the function named 'funcname' which is imported by 'hInst' DLL, |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
651 * and return the original function address. |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
652 */ |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
653 void * |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
654 hook_dll_import_func(HINSTANCE hInst, const char *funcname, const void *hook) |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
655 { |
78e3b38b0d33
patch 8.2.4317: MS-Windows: Vim exits when Python 3 initialisation fails
Bram Moolenaar <Bram@vim.org>
parents:
27533
diff
changeset
|
656 return get_imported_func_info(hInst, funcname, 2, hook); |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
657 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
658 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
659 |
7 | 660 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
661 # ifndef GETTEXT_DLL | |
662 # 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
|
663 # 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
|
664 # define GETTEXT_DLL_ALT2 "intl.dll" |
7 | 665 # endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
666 // Dummy functions |
36 | 667 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
|
668 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 669 static char *null_libintl_textdomain(const char *); |
670 static char *null_libintl_bindtextdomain(const char *, const char *); | |
671 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
|
672 static int null_libintl_wputenv(const wchar_t *); |
7 | 673 |
2612 | 674 static HINSTANCE hLibintlDLL = NULL; |
36 | 675 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
|
676 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
|
677 = null_libintl_ngettext; |
36 | 678 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
679 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 680 = null_libintl_bindtextdomain; |
36 | 681 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
682 = 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
|
683 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 684 |
685 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
686 dyn_libintl_init(void) |
7 | 687 { |
688 int i; | |
689 static struct | |
690 { | |
691 char *name; | |
692 FARPROC *ptr; | |
693 } libintl_entry[] = | |
694 { | |
695 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
696 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 697 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
698 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
699 {NULL, NULL} | |
700 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
701 HINSTANCE hmsvcrt; |
7 | 702 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
703 // 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
|
704 if (hLibintlDLL != NULL) |
7 | 705 return 1; |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
706 // 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
|
707 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
708 # ifdef GETTEXT_DLL_ALT1 |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
709 if (!hLibintlDLL) |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
710 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT1); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
711 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
712 # 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
|
713 if (!hLibintlDLL) |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
714 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
715 # endif |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
716 if (!hLibintlDLL) |
7 | 717 { |
2612 | 718 if (p_verbose > 0) |
7 | 719 { |
2612 | 720 verbose_enter(); |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
721 semsg(_(e_could_not_load_library_str_str), GETTEXT_DLL, GetWin32Error()); |
2612 | 722 verbose_leave(); |
7 | 723 } |
2612 | 724 return 0; |
7 | 725 } |
726 for (i = 0; libintl_entry[i].name != NULL | |
727 && libintl_entry[i].ptr != NULL; ++i) | |
728 { | |
27523
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27521
diff
changeset
|
729 if ((*libintl_entry[i].ptr = GetProcAddress(hLibintlDLL, |
7 | 730 libintl_entry[i].name)) == NULL) |
731 { | |
732 dyn_libintl_end(); | |
733 if (p_verbose > 0) | |
292 | 734 { |
735 verbose_enter(); | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
736 semsg(_(e_could_not_load_library_function_str), libintl_entry[i].name); |
292 | 737 verbose_leave(); |
738 } | |
7 | 739 return 0; |
740 } | |
741 } | |
36 | 742 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
743 // The bind_textdomain_codeset() function is optional. |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
744 dyn_libintl_bind_textdomain_codeset = (char *(*)(const char *, const char *)) |
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
745 GetProcAddress(hLibintlDLL, "bind_textdomain_codeset"); |
36 | 746 if (dyn_libintl_bind_textdomain_codeset == NULL) |
747 dyn_libintl_bind_textdomain_codeset = | |
748 null_libintl_bind_textdomain_codeset; | |
749 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
750 // _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
|
751 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
|
752 if (hmsvcrt != NULL) |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
753 dyn_libintl_wputenv = (int (*)(const wchar_t *)) |
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
754 GetProcAddress(hmsvcrt, "_wputenv"); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
755 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
|
756 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
|
757 |
7 | 758 return 1; |
759 } | |
760 | |
761 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
762 dyn_libintl_end(void) |
7 | 763 { |
764 if (hLibintlDLL) | |
765 FreeLibrary(hLibintlDLL); | |
766 hLibintlDLL = NULL; | |
767 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
|
768 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 769 dyn_libintl_textdomain = null_libintl_textdomain; |
770 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 771 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
|
772 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 773 } |
774 | |
775 static char * | |
26 | 776 null_libintl_gettext(const char *msgid) |
7 | 777 { |
778 return (char*)msgid; | |
779 } | |
780 | |
781 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
782 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
783 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
784 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
785 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
786 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
787 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
|
788 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
789 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
790 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
|
791 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
|
792 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
|
793 const char *dirname UNUSED) |
7 | 794 { |
795 return NULL; | |
796 } | |
797 | |
798 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
|
799 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
|
800 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
|
801 const char *codeset UNUSED) |
36 | 802 { |
803 return NULL; | |
804 } | |
805 | |
806 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
|
807 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 808 { |
809 return NULL; | |
810 } | |
811 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
812 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
|
813 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
|
814 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
815 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
|
816 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
817 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
818 #endif // DYNAMIC_GETTEXT |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
819 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
820 // This symbol is not defined in older versions of the SDK or Visual C++ |
7 | 821 |
822 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
823 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
824 #endif | |
825 | |
826 #ifdef HAVE_ACL | |
3927 | 827 # ifndef PROTO |
828 # include <aclapi.h> | |
829 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
830 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
831 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
832 # endif |
7 | 833 #endif |
834 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
835 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
836 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
837 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
838 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
839 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
840 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
841 { |
5590 | 842 BOOL bResult; |
843 LUID luid; | |
844 HANDLE hToken; | |
845 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
846 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
847 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
848 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
849 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
850 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
851 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
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 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
854 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
855 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
856 |
6047 | 857 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
858 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
859 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
860 SE_PRIVILEGE_ENABLED : 0; |
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 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
863 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
864 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
865 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
866 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
867 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
868 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
869 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
870 |
23090
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
871 #ifdef _MSC_VER |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
872 // 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
|
873 // It is needed for implementing "windowsversion()". |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
874 # pragma warning(push) |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
875 # pragma warning(disable: 4996) |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
876 #endif |
7 | 877 /* |
20478
af8feeaf167a
patch 8.2.0793: MS-Windows: cannot build GUI with small features
Bram Moolenaar <Bram@vim.org>
parents:
20439
diff
changeset
|
878 * Set "win8_or_later" and fill in "windowsVersion" if possible. |
7 | 879 */ |
880 void | |
881 PlatformId(void) | |
882 { | |
883 static int done = FALSE; | |
884 | |
885 if (!done) | |
886 { | |
887 OSVERSIONINFO ovi; | |
888 | |
889 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
890 GetVersionEx(&ovi); | |
891 | |
20478
af8feeaf167a
patch 8.2.0793: MS-Windows: cannot build GUI with small features
Bram Moolenaar <Bram@vim.org>
parents:
20439
diff
changeset
|
892 #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
|
893 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
|
894 (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
|
895 #endif |
5633 | 896 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
897 || ovi.dwMajorVersion > 6) | |
898 win8_or_later = TRUE; | |
899 | |
7 | 900 #ifdef HAVE_ACL |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
901 // 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
|
902 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 903 #endif |
904 done = TRUE; | |
905 } | |
906 } | |
23090
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
907 #ifdef _MSC_VER |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
908 # pragma warning(pop) |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
909 #endif |
7 | 910 |
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
|
911 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 912 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
913 # define SHIFT (SHIFT_PRESSED) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
914 # 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
|
915 # 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
|
916 # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) |
7 | 917 |
918 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
919 // 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
|
920 // 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
|
921 // 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
|
922 // 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
|
923 // 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
|
924 // combinations of function/arrow/etc keys. |
7 | 925 |
297 | 926 static const struct |
7 | 927 { |
928 WORD wVirtKey; | |
929 BOOL fAnsiKey; | |
930 int chAlone; | |
931 int chShift; | |
932 int chCtrl; | |
933 int chAlt; | |
934 } VirtKeyMap[] = | |
935 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
936 // Key ANSI alone shift ctrl alt |
7 | 937 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, |
938 | |
939 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
940 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
941 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
942 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
943 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
944 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
945 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
946 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
947 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
948 { 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
|
949 { 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
|
950 { 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
|
951 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
952 { 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
|
953 { 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
|
954 { 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
|
955 { 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
|
956 { 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
|
957 { 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
|
958 { 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
|
959 { 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
|
960 { 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
|
961 { 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
|
962 { 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
|
963 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
964 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, // PrtScrn |
7 | 965 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
966 # if 0 |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
967 // 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
|
968 { 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
|
969 { 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
|
970 { 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
|
971 { 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
|
972 { 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
|
973 { 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
|
974 { 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
|
975 { 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
|
976 # endif |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
977 { 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
|
978 { 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
|
979 // { 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
|
980 { 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
|
981 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
982 { 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
|
983 { 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
|
984 { 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
|
985 { 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
|
986 { 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
|
987 { 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
|
988 { 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
|
989 { 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
|
990 { 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
|
991 // 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
|
992 { VK_NUMPAD9,TRUE, '\376', '\377', '|', '}', }, |
7 | 993 }; |
994 | |
995 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
996 /* |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
997 * 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
|
998 */ |
7 | 999 static int |
1000 win32_kbd_patch_key( | |
26 | 1001 KEY_EVENT_RECORD *pker) |
7 | 1002 { |
1003 UINT uMods = pker->dwControlKeyState; | |
1004 static int s_iIsDead = 0; | |
1005 static WORD awAnsiCode[2]; | |
1006 static BYTE abKeystate[256]; | |
1007 | |
1008 | |
1009 if (s_iIsDead == 2) | |
1010 { | |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1011 pker->uChar.UnicodeChar = (WCHAR) awAnsiCode[1]; |
7 | 1012 s_iIsDead = 0; |
1013 return 1; | |
1014 } | |
1015 | |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1016 if (pker->uChar.UnicodeChar != 0) |
7 | 1017 return 1; |
1018 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19983
diff
changeset
|
1019 CLEAR_FIELD(abKeystate); |
7 | 1020 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1021 // Clear any pending dead keys |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1022 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 1023 |
1024 if (uMods & SHIFT_PRESSED) | |
1025 abKeystate[VK_SHIFT] = 0x80; | |
1026 if (uMods & CAPSLOCK_ON) | |
1027 abKeystate[VK_CAPITAL] = 1; | |
1028 | |
1029 if ((uMods & ALT_GR) == ALT_GR) | |
1030 { | |
1031 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
1032 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
1033 } | |
1034 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1035 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
|
1036 abKeystate, awAnsiCode, 2, 0); |
7 | 1037 |
1038 if (s_iIsDead > 0) | |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1039 pker->uChar.UnicodeChar = (WCHAR) awAnsiCode[0]; |
7 | 1040 |
1041 return s_iIsDead; | |
1042 } | |
1043 | |
1044 static BOOL g_fJustGotFocus = FALSE; | |
1045 | |
1046 /* | |
1047 * Decode a KEY_EVENT into one or two keystrokes | |
1048 */ | |
1049 static BOOL | |
1050 decode_key_event( | |
1051 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1052 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1053 WCHAR *pch2, |
7 | 1054 int *pmodifiers, |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
1055 BOOL fDoPost UNUSED) |
7 | 1056 { |
1057 int i; | |
1058 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
1059 | |
1060 *pch = *pch2 = NUL; | |
1061 g_fJustGotFocus = FALSE; | |
1062 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1063 // ignore key up events |
7 | 1064 if (!pker->bKeyDown) |
1065 return FALSE; | |
1066 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1067 // ignore some keystrokes |
7 | 1068 switch (pker->wVirtualKeyCode) |
1069 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1070 // modifiers |
7 | 1071 case VK_SHIFT: |
1072 case VK_CONTROL: | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1073 case VK_MENU: // Alt key |
7 | 1074 return FALSE; |
1075 | |
1076 default: | |
1077 break; | |
1078 } | |
1079 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1080 // special cases |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1081 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 |
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1082 && pker->uChar.UnicodeChar == NUL) |
7 | 1083 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1084 // Ctrl-6 is Ctrl-^ |
7 | 1085 if (pker->wVirtualKeyCode == '6') |
1086 { | |
1087 *pch = Ctrl_HAT; | |
1088 return TRUE; | |
1089 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1090 // Ctrl-2 is Ctrl-@ |
7 | 1091 else if (pker->wVirtualKeyCode == '2') |
1092 { | |
1093 *pch = NUL; | |
1094 return TRUE; | |
1095 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1096 // Ctrl-- is Ctrl-_ |
7 | 1097 else if (pker->wVirtualKeyCode == 0xBD) |
1098 { | |
1099 *pch = Ctrl__; | |
1100 return TRUE; | |
1101 } | |
1102 } | |
1103 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1104 // Shift-TAB |
7 | 1105 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) |
1106 { | |
1107 *pch = K_NUL; | |
1108 *pch2 = '\017'; | |
1109 return TRUE; | |
1110 } | |
1111 | |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24749
diff
changeset
|
1112 for (i = ARRAY_LENGTH(VirtKeyMap); --i >= 0; ) |
7 | 1113 { |
1114 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1115 { | |
1116 if (nModifs == 0) | |
1117 *pch = VirtKeyMap[i].chAlone; | |
1118 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1119 *pch = VirtKeyMap[i].chShift; | |
1120 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1121 *pch = VirtKeyMap[i].chCtrl; | |
1122 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1123 *pch = VirtKeyMap[i].chAlt; | |
1124 | |
1125 if (*pch != 0) | |
1126 { | |
1127 if (VirtKeyMap[i].fAnsiKey) | |
1128 { | |
1129 *pch2 = *pch; | |
1130 *pch = K_NUL; | |
1131 } | |
1132 | |
1133 return TRUE; | |
1134 } | |
1135 } | |
1136 } | |
1137 | |
1138 i = win32_kbd_patch_key(pker); | |
1139 | |
1140 if (i < 0) | |
1141 *pch = NUL; | |
1142 else | |
1143 { | |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1144 *pch = (i > 0) ? pker->uChar.UnicodeChar : NUL; |
7 | 1145 |
1146 if (pmodifiers != NULL) | |
1147 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1148 // 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
|
1149 // with CTRL (which is ALTGR). |
7 | 1150 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) |
1151 *pmodifiers |= MOD_MASK_ALT; | |
1152 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1153 // 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
|
1154 // it's already included with the character. |
7 | 1155 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) |
1156 *pmodifiers |= MOD_MASK_SHIFT; | |
1157 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1158 // 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
|
1159 // 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
|
1160 // combined with ALT (which is ALTGR). |
7 | 1161 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 |
1162 && *pch >= 0x20 && *pch < 0x80) | |
1163 *pmodifiers |= MOD_MASK_CTRL; | |
1164 } | |
1165 } | |
1166 | |
1167 return (*pch != NUL); | |
1168 } | |
1169 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1170 #endif // FEAT_GUI_MSWIN |
7 | 1171 |
1172 | |
1173 /* | |
1174 * For the GUI the mouse handling is in gui_w32.c. | |
1175 */ | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1176 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 1177 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
|
1178 mch_setmouse(int on UNUSED) |
7 | 1179 { |
1180 } | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1181 #else |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 static int g_yMouse; // mouse y coordinate |
28844
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
1187 static DWORD g_cmodein = 0; // Original console input mode |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
1188 static DWORD g_cmodeout = 0; // Original console output mode |
7 | 1189 |
1190 /* | |
1191 * Enable or disable mouse input | |
1192 */ | |
1193 void | |
26 | 1194 mch_setmouse(int on) |
7 | 1195 { |
1196 DWORD cmodein; | |
1197 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1198 # 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
|
1199 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
|
1200 return; |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1201 # endif |
7 | 1202 if (!g_fMouseAvail) |
1203 return; | |
1204 | |
1205 g_fMouseActive = on; | |
1206 GetConsoleMode(g_hConIn, &cmodein); | |
1207 | |
1208 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
|
1209 { |
7 | 1210 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
|
1211 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
|
1212 } |
7 | 1213 else |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1214 { |
7 | 1215 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
|
1216 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
|
1217 } |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1218 |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1219 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 1220 } |
1221 | |
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
|
1222 |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1223 # 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
|
1224 /* |
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 * 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
|
1226 */ |
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 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
|
1228 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
|
1229 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1230 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
|
1231 } |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1232 # 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
|
1233 |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1234 /* |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1235 * Win32 console mouse scroll event handler. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1236 * Loosely based on the _OnMouseWheel() function in gui_w32.c |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1237 * |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1238 * This encodes the mouse scroll direction and keyboard modifiers into |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1239 * g_nMouseClick, and the mouse position into g_xMouse and g_yMouse |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1240 * |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1241 * The direction of the scroll is decoded from two fields of the win32 console |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1242 * mouse event record; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1243 * 1. The axis - vertical or horizontal flag - from dwEventFlags, and |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1244 * 2. The sign - positive or negative (aka delta flag) - from dwButtonState |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1245 * |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1246 * When scroll axis is HORIZONTAL |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1247 * - If the high word of the dwButtonState member contains a positive |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1248 * value, the wheel was rotated to the right. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1249 * - Otherwise, the wheel was rotated to the left. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1250 * When scroll axis is VERTICAL |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1251 * - If the high word of the dwButtonState member contains a positive value, |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1252 * the wheel was rotated forward, away from the user. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1253 * - Otherwise, the wheel was rotated backward, toward the user. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1254 */ |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1255 static void |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1256 decode_mouse_wheel(MOUSE_EVENT_RECORD *pmer) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1257 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1258 win_T *wp; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1259 int horizontal = (pmer->dwEventFlags == MOUSE_HWHEELED); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1260 int zDelta = pmer->dwButtonState; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1261 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1262 g_xMouse = pmer->dwMousePosition.X; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1263 g_yMouse = pmer->dwMousePosition.Y; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1264 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1265 #ifdef FEAT_PROP_POPUP |
30918
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1266 int lcol = g_xMouse; |
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1267 int lrow = g_yMouse; |
30936
38d20a201beb
patch 9.0.0802: MS-Windows: cannot map console mouse scroll events
Bram Moolenaar <Bram@vim.org>
parents:
30918
diff
changeset
|
1268 wp = mouse_find_win(&lrow, &lcol, FIND_POPUP); |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1269 if (wp != NULL && popup_is_popup(wp)) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1270 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1271 g_nMouseClick = -1; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1272 cmdarg_T cap; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1273 oparg_T oa; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1274 CLEAR_FIELD(cap); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1275 clear_oparg(&oa); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1276 cap.oap = &oa; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1277 if (horizontal) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1278 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1279 cap.arg = zDelta < 0 ? MSCR_LEFT : MSCR_RIGHT; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1280 cap.cmdchar = zDelta < 0 ? K_MOUSELEFT : K_MOUSERIGHT; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1281 } |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1282 else |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1283 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1284 cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1285 cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1286 } |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1287 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1288 // Mouse hovers over popup window, scroll it if possible. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1289 mouse_row = wp->w_winrow; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1290 mouse_col = wp->w_wincol; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1291 nv_mousescroll(&cap); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1292 update_screen(0); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1293 setcursor(); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1294 out_flush(); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1295 return; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1296 } |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1297 #endif |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1298 mouse_col = g_xMouse; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1299 mouse_row = g_yMouse; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1300 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1301 char_u modifiers = 0; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1302 char_u direction = 0; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1303 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1304 // Decode the direction into an event that Vim can process |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1305 if (horizontal) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1306 direction = zDelta >= 0 ? KE_MOUSELEFT : KE_MOUSERIGHT; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1307 else |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1308 direction = zDelta >= 0 ? KE_MOUSEDOWN : KE_MOUSEUP; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1309 |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30936
diff
changeset
|
1310 // Decode the win32 console key modifiers into Vim mouse modifiers. |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1311 if (pmer->dwControlKeyState & SHIFT_PRESSED) |
30918
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1312 modifiers |= MOD_MASK_SHIFT; // MOUSE_SHIFT; |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1313 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) |
30918
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1314 modifiers |= MOD_MASK_CTRL; // MOUSE_CTRL; |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1315 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1316 modifiers |= MOD_MASK_ALT; // MOUSE_ALT; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1317 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1318 // add (bitwise or) the scroll direction and the key modifier chars |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1319 // together. |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1320 g_nMouseClick = ((direction << 8) | modifiers); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1321 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1322 return; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1323 } |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1324 |
7 | 1325 /* |
1326 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1327 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1328 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1329 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1330 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1331 * and we return the mouse position in g_xMouse and g_yMouse. | |
1332 * | |
1333 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1334 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1335 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1336 * | |
1337 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1338 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1339 * | |
1340 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1341 * moves, even if it stays within the same character cell. We ignore | |
1342 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1343 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1344 * we're only interested in MOUSE_DRAG). | |
1345 * | |
1346 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1347 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1348 * In practice, it's almost impossible to click both at the same time, | |
1349 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1350 * in such cases, if the user is clicking quickly. | |
1351 */ | |
1352 static BOOL | |
1353 decode_mouse_event( | |
26 | 1354 MOUSE_EVENT_RECORD *pmer) |
7 | 1355 { |
1356 static int s_nOldButton = -1; | |
1357 static int s_nOldMouseClick = -1; | |
1358 static int s_xOldMouse = -1; | |
1359 static int s_yOldMouse = -1; | |
1360 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
|
1361 # ifdef FEAT_DIFF |
7 | 1362 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
|
1363 # endif |
7 | 1364 static int s_cClicks = 1; |
1365 static BOOL s_fReleased = TRUE; | |
1366 static DWORD s_dwLastClickTime = 0; | |
1367 static BOOL s_fNextIsMiddle = FALSE; | |
1368 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1369 static DWORD cButtons = 0; // number of buttons supported |
7 | 1370 |
1371 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1372 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1373 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1374 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1375 | |
1376 int nButton; | |
1377 | |
1378 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1379 cButtons = 2; | |
1380 | |
1381 if (!g_fMouseAvail || !g_fMouseActive) | |
1382 { | |
1383 g_nMouseClick = -1; | |
1384 return FALSE; | |
1385 } | |
1386 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1387 // get a spurious MOUSE_EVENT immediately after receiving focus; ignore |
7 | 1388 if (g_fJustGotFocus) |
1389 { | |
1390 g_fJustGotFocus = FALSE; | |
1391 return FALSE; | |
1392 } | |
1393 | |
30918
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1394 // If there is an unprocessed mouse click drop this one. |
7 | 1395 if (g_nMouseClick != -1) |
1396 return TRUE; | |
30918
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1397 |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1398 if (pmer->dwEventFlags == MOUSE_WHEELED |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1399 || pmer->dwEventFlags == MOUSE_HWHEELED) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1400 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1401 decode_mouse_wheel(pmer); |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1402 return TRUE; // we now should have a mouse scroll in g_nMouseClick |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
1403 } |
30918
6a2a38b26caf
patch 9.0.0793: MS-Windows: mouse scroll events only work with the dll
Bram Moolenaar <Bram@vim.org>
parents:
30916
diff
changeset
|
1404 |
7 | 1405 nButton = -1; |
1406 g_xMouse = pmer->dwMousePosition.X; | |
1407 g_yMouse = pmer->dwMousePosition.Y; | |
1408 | |
1409 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1410 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1411 // 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
|
1412 // events even when the mouse moves only within a char cell.) |
7 | 1413 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) |
1414 return FALSE; | |
1415 } | |
1416 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1417 // If no buttons are pressed... |
7 | 1418 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) |
1419 { | |
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
|
1420 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
|
1421 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1422 // If the last thing returned was MOUSE_RELEASE, ignore this |
7 | 1423 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
|
1424 { |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1425 # ifdef FEAT_BEVAL_TERM |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1426 // 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
|
1427 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
|
1428 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
|
1429 else |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1430 # 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
|
1431 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
|
1432 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1433 |
7 | 1434 s_fReleased = TRUE; |
1435 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1436 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
|
1437 { |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1438 // 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
|
1439 // simultaneously to get MIDDLE. |
7 | 1440 |
1441 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1442 { | |
1443 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1444 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1445 // 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
|
1446 // next mouse event has both of them pressed |
7 | 1447 if (dwLR == LEFT || dwLR == RIGHT) |
1448 { | |
1449 for (;;) | |
1450 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1451 // wait a short time for next input event |
7 | 1452 if (WaitForSingleObject(g_hConIn, p_mouset / 3) |
1453 != WAIT_OBJECT_0) | |
1454 break; | |
1455 else | |
1456 { | |
1457 DWORD cRecords = 0; | |
1458 INPUT_RECORD ir; | |
1459 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1460 | |
5580 | 1461 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1462 |
1463 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1464 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1465 break; | |
1466 else | |
1467 { | |
1468 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1469 { | |
5580 | 1470 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1471 |
1472 return decode_mouse_event(pmer2); | |
1473 } | |
1474 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1475 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1476 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1477 // throw away spurious mouse move |
5580 | 1478 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1479 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1480 // are there any more mouse events in queue? |
5580 | 1481 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1482 |
1483 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1484 break; | |
1485 } | |
1486 else | |
1487 break; | |
1488 } | |
1489 } | |
1490 } | |
1491 } | |
1492 } | |
1493 | |
1494 if (s_fNextIsMiddle) | |
1495 { | |
1496 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1497 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1498 s_fNextIsMiddle = FALSE; | |
1499 } | |
1500 else if (cButtons == 2 && | |
1501 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1502 { | |
1503 nButton = MOUSE_MIDDLE; | |
1504 | |
1505 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1506 { | |
1507 s_fNextIsMiddle = TRUE; | |
1508 nButton = MOUSE_RELEASE; | |
1509 } | |
1510 } | |
1511 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1512 nButton = MOUSE_LEFT; | |
1513 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1514 nButton = MOUSE_MIDDLE; | |
1515 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1516 nButton = MOUSE_RIGHT; | |
1517 | |
1518 if (! s_fReleased && ! s_fNextIsMiddle | |
1519 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1520 return FALSE; | |
1521 | |
1522 s_fReleased = s_fNextIsMiddle; | |
1523 } | |
1524 | |
1525 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1526 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1527 // button pressed or released, without mouse moving |
7 | 1528 if (nButton != -1 && nButton != MOUSE_RELEASE) |
1529 { | |
1530 DWORD dwCurrentTime = GetTickCount(); | |
1531 | |
1532 if (s_xOldMouse != g_xMouse | |
1533 || s_yOldMouse != g_yMouse | |
1534 || s_nOldButton != nButton | |
1535 || 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
|
1536 # ifdef FEAT_DIFF |
7 | 1537 || 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
|
1538 # endif |
7 | 1539 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) |
1540 { | |
1541 s_cClicks = 1; | |
1542 } | |
1543 else if (++s_cClicks > 4) | |
1544 { | |
1545 s_cClicks = 1; | |
1546 } | |
1547 | |
1548 s_dwLastClickTime = dwCurrentTime; | |
1549 } | |
1550 } | |
1551 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1552 { | |
1553 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1554 nButton = MOUSE_DRAG; | |
1555 | |
1556 s_cClicks = 1; | |
1557 } | |
1558 | |
1559 if (nButton == -1) | |
1560 return FALSE; | |
1561 | |
1562 if (nButton != MOUSE_RELEASE) | |
1563 s_nOldButton = nButton; | |
1564 | |
1565 g_nMouseClick = nButton; | |
1566 | |
1567 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1568 g_nMouseClick |= MOUSE_SHIFT; | |
1569 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1570 g_nMouseClick |= MOUSE_CTRL; | |
1571 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1572 g_nMouseClick |= MOUSE_ALT; | |
1573 | |
1574 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1575 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1576 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1577 // only pass on interesting (i.e., different) mouse events |
7 | 1578 if (s_xOldMouse == g_xMouse |
1579 && s_yOldMouse == g_yMouse | |
1580 && s_nOldMouseClick == g_nMouseClick) | |
1581 { | |
1582 g_nMouseClick = -1; | |
1583 return FALSE; | |
1584 } | |
1585 | |
1586 s_xOldMouse = g_xMouse; | |
1587 s_yOldMouse = g_yMouse; | |
1588 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
|
1589 # ifdef FEAT_DIFF |
7 | 1590 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
|
1591 # endif |
7 | 1592 s_nOldMouseClick = g_nMouseClick; |
1593 | |
1594 return TRUE; | |
1595 } | |
1596 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1597 #endif // FEAT_GUI_MSWIN |
7 | 1598 |
1599 | |
1600 #ifdef MCH_CURSOR_SHAPE | |
1601 /* | |
1602 * Set the shape of the cursor. | |
1603 * 'thickness' can be from 1 (thin) to 99 (block) | |
1604 */ | |
1605 static void | |
1606 mch_set_cursor_shape(int thickness) | |
1607 { | |
30019
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1608 if (USE_VTP || USE_WT) |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1609 { |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1610 if (*T_CSI == NUL) |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1611 { |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1612 // If 't_SI' is not set, use the default cursor styles. |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1613 if (thickness < 50) |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1614 vtp_printf("\033[3 q"); // underline |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1615 else |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1616 vtp_printf("\033[0 q"); // default |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1617 } |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1618 } |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1619 else |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1620 { |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1621 CONSOLE_CURSOR_INFO ConsoleCursorInfo; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1622 ConsoleCursorInfo.dwSize = thickness; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1623 ConsoleCursorInfo.bVisible = s_cursor_visible; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1624 |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1625 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1626 if (s_cursor_visible) |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1627 SetConsoleCursorPosition(g_hConOut, g_coord); |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
1628 } |
7 | 1629 } |
1630 | |
1631 void | |
1632 mch_update_cursor(void) | |
1633 { | |
1634 int idx; | |
1635 int thickness; | |
1636 | |
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
|
1637 # 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
|
1638 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
|
1639 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
|
1640 # 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
|
1641 |
7 | 1642 /* |
1643 * How the cursor is drawn depends on the current mode. | |
1644 */ | |
1645 idx = get_shape_idx(FALSE); | |
1646 | |
1647 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
|
1648 thickness = 99; // 100 doesn't work on W95 |
7 | 1649 else |
1650 thickness = shape_table[idx].percentage; | |
1651 mch_set_cursor_shape(thickness); | |
1652 } | |
1653 #endif | |
1654 | |
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
|
1655 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1656 /* |
1657 * Handle FOCUS_EVENT. | |
1658 */ | |
1659 static void | |
1660 handle_focus_event(INPUT_RECORD ir) | |
1661 { | |
1662 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1663 ui_focus_change((int)g_fJustGotFocus); | |
1664 } | |
1665 | |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1666 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
|
1667 |
7 | 1668 /* |
1669 * Wait until console input from keyboard or mouse is available, | |
1670 * 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
|
1671 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1672 * Return TRUE if something is available FALSE if not. |
1673 */ | |
1674 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1675 WaitForChar(long msec, int ignore_input) |
7 | 1676 { |
1677 DWORD dwNow = 0, dwEndTime = 0; | |
1678 INPUT_RECORD ir; | |
1679 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1680 WCHAR ch, ch2; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1681 # ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1682 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
|
1683 # endif |
7 | 1684 |
1685 if (msec > 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1686 // Wait until the specified time has elapsed. |
7 | 1687 dwEndTime = GetTickCount() + msec; |
1688 else if (msec < 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1689 // Wait forever. |
7 | 1690 dwEndTime = INFINITE; |
1691 | |
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
|
1692 // 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
|
1693 // we might get multiple unusable mouse events in that time. |
7 | 1694 for (;;) |
1695 { | |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1696 // 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
|
1697 if (msec != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1698 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1699 # 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
|
1700 parse_queued_messages(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1701 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1702 # 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
|
1703 mzvim_check_threads(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1704 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1705 # 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
|
1706 serverProcessPendingMessages(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1707 # endif |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1708 } |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1709 |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1710 if (g_nMouseClick != -1 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1711 # ifdef FEAT_CLIENTSERVER |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1712 || (!ignore_input && input_available()) |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1713 # endif |
7 | 1714 ) |
1715 return TRUE; | |
1716 | |
1717 if (msec > 0) | |
1718 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1719 // 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
|
1720 // GetTickCount() may wrap around (overflow). |
7 | 1721 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1722 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1723 break; |
1724 } | |
1725 if (msec != 0) | |
1726 { | |
14 | 1727 DWORD dwWaitTime = dwEndTime - dwNow; |
1728 | |
23060
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1729 // 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
|
1730 // 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
|
1731 // 'balloonexpr'. |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1732 if (dwWaitTime > 11) |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1733 dwWaitTime = 11; |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1734 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1735 # 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
|
1736 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
|
1737 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
|
1738 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1739 # ifdef FEAT_TIMERS |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1740 // 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
|
1741 if (dwWaitTime > 10) |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1742 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1743 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1744 |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1745 // 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
|
1746 // 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
|
1747 due_time = check_due_timer(); |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1748 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
|
1749 { |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1750 // timer may have used feedkeys(). |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1751 return FALSE; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1752 } |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1753 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
|
1754 dwWaitTime = due_time; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1755 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1756 # endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1757 if ( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1758 # ifdef FEAT_CLIENTSERVER |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1759 // 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
|
1760 // 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
|
1761 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
|
1762 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
|
1763 # else |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1764 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
|
1765 != WAIT_OBJECT_0 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1766 # endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1767 ) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1768 continue; |
7 | 1769 } |
1770 | |
1771 cRecords = 0; | |
5580 | 1772 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1773 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1774 # 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
|
1775 // 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
|
1776 // Only when not peeking. |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28763
diff
changeset
|
1777 if (State == MODE_CMDLINE && msg_row == Rows - 1 && msec != 0) |
7 | 1778 { |
1779 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1780 | |
1781 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1782 { | |
1783 if (csbi.dwCursorPosition.Y != msg_row) | |
1784 { | |
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
|
1785 // 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
|
1786 // line and later all the windows. |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29245
diff
changeset
|
1787 redraw_all_later(UPD_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
|
1788 compute_cmdrow(); |
7 | 1789 redrawcmd(); |
1790 } | |
1791 } | |
1792 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1793 # endif |
7 | 1794 |
1795 if (cRecords > 0) | |
1796 { | |
1797 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1798 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1799 # ifdef FEAT_MBYTE_IME |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1800 // 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
|
1801 // wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 |
27533
4f1c67a5f446
patch 8.2.4294: MS-Windows: #ifdefs for Cygwin are too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
1802 if (ir.Event.KeyEvent.uChar.UnicodeChar == 0 |
7 | 1803 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1804 { | |
5580 | 1805 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1806 continue; |
1807 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1808 # endif |
7 | 1809 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, |
1810 NULL, FALSE)) | |
1811 return TRUE; | |
1812 } | |
1813 | |
5580 | 1814 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1815 |
1816 if (ir.EventType == FOCUS_EVENT) | |
1817 handle_focus_event(ir); | |
1818 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
|
1819 { |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1820 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
|
1821 |
18876
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1822 // 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
|
1823 // 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
|
1824 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
|
1825 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1826 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
|
1827 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
|
1828 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
|
1829 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
|
1830 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
|
1831 { |
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1832 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
|
1833 shell_resized(); |
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1834 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1835 } |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1836 } |
7 | 1837 else if (ir.EventType == MOUSE_EVENT |
1838 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1839 return TRUE; | |
1840 } | |
1841 else if (msec == 0) | |
1842 break; | |
1843 } | |
1844 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1845 # ifdef FEAT_CLIENTSERVER |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1846 // Something might have been received while we were waiting. |
7 | 1847 if (input_available()) |
1848 return TRUE; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1849 # endif |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1850 |
7 | 1851 return FALSE; |
1852 } | |
1853 | |
1854 /* | |
1855 * return non-zero if a character is available | |
1856 */ | |
1857 int | |
26 | 1858 mch_char_avail(void) |
7 | 1859 { |
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
|
1860 # 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
|
1861 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
|
1862 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
|
1863 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1864 return WaitForChar(0L, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1865 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1866 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1867 # 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
|
1868 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1869 * 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
|
1870 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1871 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1872 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1873 { |
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
|
1874 # 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
|
1875 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
|
1876 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
|
1877 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1878 return WaitForChar(0L, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1879 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1880 # endif |
7 | 1881 |
1882 /* | |
1883 * Create the console input. Used when reading stdin doesn't work. | |
1884 */ | |
1885 static void | |
1886 create_conin(void) | |
1887 { | |
1888 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1889 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1890 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1891 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1892 did_create_conin = TRUE; |
1893 } | |
1894 | |
1895 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1896 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1897 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1898 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1899 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1900 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1901 WCHAR ch; |
7 | 1902 |
1903 for (;;) | |
1904 { | |
1905 INPUT_RECORD ir; | |
1906 DWORD cRecords = 0; | |
1907 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1908 # ifdef FEAT_CLIENTSERVER |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1909 (void)WaitForChar(-1L, FALSE); |
7 | 1910 if (input_available()) |
1911 return 0; | |
1912 if (g_nMouseClick != -1) | |
1913 return 0; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1914 # endif |
5580 | 1915 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1916 { |
1917 if (did_create_conin) | |
1918 read_error_exit(); | |
1919 create_conin(); | |
1920 continue; | |
1921 } | |
1922 | |
1923 if (ir.EventType == KEY_EVENT) | |
1924 { | |
1925 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1926 pmodifiers, TRUE)) | |
1927 return ch; | |
1928 } | |
1929 else if (ir.EventType == FOCUS_EVENT) | |
1930 handle_focus_event(ir); | |
1931 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1932 shell_resized(); | |
1933 else if (ir.EventType == MOUSE_EVENT) | |
1934 { | |
1935 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1936 return 0; | |
1937 } | |
1938 } | |
1939 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1940 #endif // !FEAT_GUI_MSWIN |
7 | 1941 |
1942 | |
1943 /* | |
3622 | 1944 * mch_inchar(): low-level input function. |
7 | 1945 * Get one or more characters from the keyboard or the mouse. |
1946 * If time == 0, do not wait for characters. | |
1947 * If time == n, wait a short time for characters. | |
1948 * If time == -1, wait forever for characters. | |
1949 * Returns the number of characters read into buf. | |
1950 */ | |
1951 int | |
1952 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
|
1953 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
|
1954 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
|
1955 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
|
1956 int tb_change_cnt UNUSED) |
7 | 1957 { |
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
|
1958 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1959 |
1960 int len; | |
1961 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
|
1962 # ifdef VIMDLL |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1963 // 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
|
1964 # 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
|
1965 # else |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1966 # 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
|
1967 # endif |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1968 # define TYPEAHEADLEN (20 + TYPEAHEADSPACE) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1969 static char_u typeahead[TYPEAHEADLEN]; // previously typed bytes. |
7 | 1970 static int typeaheadlen = 0; |
1971 | |
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
|
1972 # 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
|
1973 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
|
1974 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
|
1975 # 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
|
1976 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1977 // First use any typeahead that was kept because "buf" was too small. |
7 | 1978 if (typeaheadlen > 0) |
1979 goto theend; | |
1980 | |
1981 if (time >= 0) | |
1982 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1983 if (!WaitForChar(time, FALSE)) // no character available |
7 | 1984 return 0; |
1985 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1986 else // time == -1, wait forever |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1987 { |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1988 mch_set_winsize_now(); // Allow winsize changes from now on |
7 | 1989 |
203 | 1990 /* |
1991 * If there is no character available within 2 seconds (default) | |
1992 * write the autoscript file to disk. Or cause the CursorHold event | |
1993 * to be triggered. | |
1994 */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1995 if (!WaitForChar(p_ut, FALSE)) |
7 | 1996 { |
609 | 1997 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1998 { |
203 | 1999 buf[0] = K_SPECIAL; |
2000 buf[1] = KS_EXTRA; | |
2001 buf[2] = (int)KE_CURSORHOLD; | |
2002 return 3; | |
7 | 2003 } |
368 | 2004 before_blocking(); |
7 | 2005 } |
2006 } | |
2007 | |
2008 /* | |
2009 * Try to read as many characters as there are, until the buffer is full. | |
2010 */ | |
2011 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2012 // we will get at least one key. Get more if they are available. |
7 | 2013 g_fCBrkPressed = FALSE; |
2014 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2015 # ifdef MCH_WRITE_DUMP |
7 | 2016 if (fdDump) |
2017 fputc('[', fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2018 # endif |
7 | 2019 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2020 // 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
|
2021 // 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
|
2022 // 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
|
2023 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) |
28844
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2024 && typeaheadlen + 5 + TYPEAHEADSPACE <= TYPEAHEADLEN) |
7 | 2025 { |
2026 if (typebuf_changed(tb_change_cnt)) | |
2027 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2028 // "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
|
2029 // typeahead buffer and "buf" is in the typeahead buffer. |
7 | 2030 typeaheadlen = 0; |
2031 break; | |
2032 } | |
2033 if (g_nMouseClick != -1) | |
2034 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2035 # ifdef MCH_WRITE_DUMP |
7 | 2036 if (fdDump) |
2037 fprintf(fdDump, "{%02x @ %d, %d}", | |
2038 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
|
2039 # endif |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2040 char_u modifiers = ((char_u *)(&g_nMouseClick))[0]; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2041 char_u scroll_dir = ((char_u *)(&g_nMouseClick))[1]; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2042 |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2043 if (scroll_dir == KE_MOUSEDOWN |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2044 || scroll_dir == KE_MOUSEUP |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2045 || scroll_dir == KE_MOUSELEFT |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2046 || scroll_dir == KE_MOUSERIGHT) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2047 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2048 if (modifiers > 0) |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2049 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2050 typeahead[typeaheadlen++] = CSI; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2051 typeahead[typeaheadlen++] = KS_MODIFIER; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2052 typeahead[typeaheadlen++] = modifiers; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2053 } |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2054 typeahead[typeaheadlen++] = CSI; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2055 typeahead[typeaheadlen++] = KS_EXTRA; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2056 typeahead[typeaheadlen++] = scroll_dir; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2057 g_nMouseClick = -1; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2058 } |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2059 else |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2060 { |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2061 typeahead[typeaheadlen++] = ESC + 128; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2062 typeahead[typeaheadlen++] = 'M'; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2063 typeahead[typeaheadlen++] = g_nMouseClick; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2064 typeahead[typeaheadlen++] = g_xMouse + '!'; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2065 typeahead[typeaheadlen++] = g_yMouse + '!'; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2066 g_nMouseClick = -1; |
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
2067 } |
7 | 2068 } |
2069 else | |
2070 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2071 WCHAR ch2 = NUL; |
7 | 2072 int modifiers = 0; |
2073 | |
2074 c = tgetch(&modifiers, &ch2); | |
2075 | |
2076 if (typebuf_changed(tb_change_cnt)) | |
2077 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2078 // "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
|
2079 // typeahead buffer and "buf" is in the typeahead buffer. |
7 | 2080 typeaheadlen = 0; |
2081 break; | |
2082 } | |
2083 | |
2084 if (c == Ctrl_C && ctrl_c_interrupts) | |
2085 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2086 # if defined(FEAT_CLIENTSERVER) |
7 | 2087 trash_input_buf(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2088 # endif |
7 | 2089 got_int = TRUE; |
2090 } | |
2091 | |
2092 if (g_nMouseClick == -1) | |
2093 { | |
2094 int n = 1; | |
6047 | 2095 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2096 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2097 { |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2098 int i, j; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2099 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2100 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2101 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2102 ch[0] = c; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2103 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
|
2104 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2105 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2106 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2107 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2108 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2109 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2110 { |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2111 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
|
2112 { |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2113 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
|
2114 # ifdef VIMDLL |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2115 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
|
2116 { |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2117 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
|
2118 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
|
2119 } |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2120 # endif |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2121 } |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2122 n = j; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2123 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2124 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2125 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2126 else |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2127 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
2128 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
|
2129 # ifdef VIMDLL |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2130 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
|
2131 { |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2132 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
|
2133 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
|
2134 n = 3; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2135 } |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2136 # endif |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
2137 } |
7 | 2138 if (ch2 != NUL) |
2139 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2140 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
|
2141 { |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2142 switch (ch2) |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2143 { |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2144 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
|
2145 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
|
2146 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
|
2147 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
|
2148 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
|
2149 n++; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2150 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2151 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2152 default: |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2153 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
|
2154 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
|
2155 n += 2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2156 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2157 } |
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
|
2158 } |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
2159 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
|
2160 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
2161 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
|
2162 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
|
2163 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
|
2164 } |
6047 | 2165 } |
2166 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2167 // 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
|
2168 // 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
|
2169 // 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
|
2170 // byte). |
7 | 2171 if ((modifiers & MOD_MASK_ALT) |
2172 && n == 1 | |
2173 && (typeahead[typeaheadlen] & 0x80) == 0 | |
2174 && !enc_dbcs | |
2175 ) | |
2176 { | |
1443 | 2177 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, |
2178 typeahead + typeaheadlen); | |
7 | 2179 modifiers &= ~MOD_MASK_ALT; |
2180 } | |
2181 | |
2182 if (modifiers != 0) | |
2183 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2184 // Prepend modifiers to the character. |
7 | 2185 mch_memmove(typeahead + typeaheadlen + 3, |
2186 typeahead + typeaheadlen, n); | |
2187 typeahead[typeaheadlen++] = K_SPECIAL; | |
2188 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
2189 typeahead[typeaheadlen++] = modifiers; | |
2190 } | |
2191 | |
2192 typeaheadlen += n; | |
2193 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2194 # ifdef MCH_WRITE_DUMP |
7 | 2195 if (fdDump) |
2196 fputc(c, fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2197 # endif |
7 | 2198 } |
2199 } | |
2200 } | |
2201 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2202 # ifdef MCH_WRITE_DUMP |
7 | 2203 if (fdDump) |
2204 { | |
2205 fputs("]\n", fdDump); | |
2206 fflush(fdDump); | |
2207 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2208 # endif |
7 | 2209 |
2210 theend: | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2211 // Move typeahead to "buf", as much as fits. |
7 | 2212 len = 0; |
2213 while (len < maxlen && typeaheadlen > 0) | |
2214 { | |
2215 buf[len++] = typeahead[0]; | |
2216 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
2217 } | |
27521
3ad379c0ab28
patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27455
diff
changeset
|
2218 # ifdef FEAT_JOB_CHANNEL |
22065
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2219 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
|
2220 { |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2221 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
|
2222 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
|
2223 } |
27521
3ad379c0ab28
patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27455
diff
changeset
|
2224 # endif |
7 | 2225 return len; |
2226 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2227 #else // FEAT_GUI_MSWIN |
7 | 2228 return 0; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2229 #endif // FEAT_GUI_MSWIN |
7 | 2230 } |
2231 | |
3927 | 2232 #ifndef PROTO |
2233 # ifndef __MINGW32__ | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2234 # include <shellapi.h> // required for FindExecutable() |
3927 | 2235 # endif |
7 | 2236 #endif |
2237 | |
9 | 2238 /* |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2239 * 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
|
2240 * 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
|
2241 * the allocated memory. |
10 | 2242 * TODO: Should somehow check if it's really executable. |
9 | 2243 */ |
7 | 2244 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
|
2245 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
|
2246 { |
28702
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2247 int attrs = win32_getattrs((char_u *)name); |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2248 |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2249 // The file doesn't exist or is a folder. |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2250 if (attrs == -1 || (attrs & FILE_ATTRIBUTE_DIRECTORY)) |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2251 return FALSE; |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2252 // Check if the file is an AppExecLink, a special alias used by Windows |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2253 // Store for its apps. |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2254 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2255 { |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2256 char_u *res = resolve_appexeclink((char_u *)name); |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2257 if (res == NULL) |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2258 return FALSE; |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2259 // The path is already absolute. |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2260 if (path != NULL) |
28702
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2261 *path = res; |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2262 else |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2263 vim_free(res); |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2264 } |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2265 else if (path != NULL) |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2266 *path = FullName_save((char_u *)name, FALSE); |
99729fe344f7
patch 8.2.4875: MS-Windows: some .exe files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
28672
diff
changeset
|
2267 return TRUE; |
20593
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 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2270 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2271 * 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
|
2272 * 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
|
2273 * 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
|
2274 * 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
|
2275 * 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
|
2276 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2277 static int |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2278 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
|
2279 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2280 // 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
|
2281 // 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
|
2282 // UTF-8. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2283 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
|
2284 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
|
2285 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
|
2286 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
|
2287 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
|
2288 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
|
2289 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
|
2290 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
|
2291 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
|
2292 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
|
2293 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2294 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
|
2295 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
|
2296 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2297 // 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
|
2298 shname = gettail(p_sh); |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
2299 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
|
2300 !(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
|
2301 || 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
|
2302 noext = TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2303 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2304 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
|
2305 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2306 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
|
2307 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
|
2308 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
|
2309 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2310 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
|
2311 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2312 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2313 * 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
|
2314 * 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
|
2315 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2316 p = pathext; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2317 while (*p) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2318 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2319 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
|
2320 || (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
|
2321 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2322 // 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
|
2323 ++p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2324 continue; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2325 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2326 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
|
2327 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
|
2328 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
|
2329 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
|
2330 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2331 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
|
2332 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2333 noext = TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2334 break; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2335 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2336 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2337 p = e; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2338 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2339 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2340 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2341 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
2342 // 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
|
2343 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
|
2344 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
|
2345 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
|
2346 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2347 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
|
2348 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
|
2349 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
|
2350 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2351 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2352 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2353 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2354 STRCPY(pathextbuf, ".;"); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2355 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
|
2356 pathext = pathextbuf; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2357 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2358 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2359 // 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
|
2360 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
|
2361 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2362 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
|
2363 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
|
2364 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2365 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
|
2366 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
|
2367 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2368 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2369 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2370 } |
28672
e4de5b5193b4
patch 8.2.4860: MS-Windows: always uses current directory for executables
Bram Moolenaar <Bram@vim.org>
parents:
28517
diff
changeset
|
2371 |
e4de5b5193b4
patch 8.2.4860: MS-Windows: always uses current directory for executables
Bram Moolenaar <Bram@vim.org>
parents:
28517
diff
changeset
|
2372 if (mch_getenv("NoDefaultCurrentDirectoryInExePath") == NULL) |
e4de5b5193b4
patch 8.2.4860: MS-Windows: always uses current directory for executables
Bram Moolenaar <Bram@vim.org>
parents:
28517
diff
changeset
|
2373 STRCPY(pathbuf, ".;"); |
e4de5b5193b4
patch 8.2.4860: MS-Windows: always uses current directory for executables
Bram Moolenaar <Bram@vim.org>
parents:
28517
diff
changeset
|
2374 else |
e4de5b5193b4
patch 8.2.4860: MS-Windows: always uses current directory for executables
Bram Moolenaar <Bram@vim.org>
parents:
28517
diff
changeset
|
2375 *pathbuf = NUL; |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2376 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
|
2377 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2378 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2379 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2380 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2381 * 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
|
2382 * 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
|
2383 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2384 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
|
2385 while (*p) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2386 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2387 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
|
2388 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2389 ++p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2390 continue; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2391 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2392 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
|
2393 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
|
2394 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
|
2395 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2396 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
|
2397 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2398 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2399 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2400 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2401 // 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
|
2402 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
|
2403 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
|
2404 else |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2405 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2406 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
|
2407 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
|
2408 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
|
2409 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2410 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
|
2411 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2412 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2413 * 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
|
2414 * 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
|
2415 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2416 p = pathext; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2417 while (*p) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2418 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2419 if (*p == ';') |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2420 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2421 // 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
|
2422 ++p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2423 continue; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2424 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2425 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
|
2426 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
|
2427 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
|
2428 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2429 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
|
2430 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2431 // 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
|
2432 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
|
2433 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2434 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2435 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2436 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2437 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
|
2438 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2439 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
|
2440 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2441 retval = TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2442 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2443 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2444 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2445 p = e2; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2446 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2447 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2448 p = e; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2449 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2450 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2451 theend: |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2452 free(pathextbuf); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2453 free(pathbuf); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2454 return retval; |
7 | 2455 } |
2456 | |
15955
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2457 #if (defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x800) || \ |
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2458 (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 2459 /* |
2460 * Bad parameter handler. | |
2461 * | |
2462 * Certain MS CRT functions will intentionally crash when passed invalid | |
2463 * parameters to highlight possible security holes. Setting this function as | |
2464 * the bad parameter handler will prevent the crash. | |
2465 * | |
2466 * In debug builds the parameters contain CRT information that might help track | |
2467 * down the source of a problem, but in non-debug builds the arguments are all | |
2468 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
2469 * worth allowing these to make debugging of issues easier. | |
2470 */ | |
2471 static void | |
29113
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
29105
diff
changeset
|
2472 bad_param_handler(const wchar_t *expression UNUSED, |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
29105
diff
changeset
|
2473 const wchar_t *function UNUSED, |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
29105
diff
changeset
|
2474 const wchar_t *file UNUSED, |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
29105
diff
changeset
|
2475 unsigned int line UNUSED, |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
29105
diff
changeset
|
2476 uintptr_t pReserved UNUSED) |
2584 | 2477 { |
2478 } | |
2479 | |
2480 # define SET_INVALID_PARAM_HANDLER \ | |
2481 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2482 #else | |
2483 # define SET_INVALID_PARAM_HANDLER | |
2484 #endif | |
2485 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2486 #ifdef FEAT_GUI_MSWIN |
7 | 2487 |
2488 /* | |
2489 * GUI version of mch_init(). | |
2490 */ | |
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
|
2491 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
|
2492 mch_init_g(void) |
7 | 2493 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2494 # ifndef __MINGW32__ |
7 | 2495 extern int _fmode; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2496 # endif |
7 | 2497 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2498 // Silently handle invalid parameters to CRT functions |
2584 | 2499 SET_INVALID_PARAM_HANDLER; |
2500 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2501 // 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
|
2502 // for the timestamp test to work on removed floppies. |
7 | 2503 SetErrorMode(SEM_FAILCRITICALERRORS); |
2504 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2505 _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
|
2506 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2507 // Specify window size. Is there a place to get the default from? |
7 | 2508 Rows = 25; |
2509 Columns = 80; | |
2510 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2511 // Look for 'vimrun' |
7 | 2512 { |
2513 char_u vimrun_location[_MAX_PATH + 4]; | |
2514 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2515 // First try in same directory as gvim.exe |
7 | 2516 STRCPY(vimrun_location, exe_name); |
2517 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2518 if (mch_getperm(vimrun_location) >= 0) | |
2519 { | |
2520 if (*skiptowhite(vimrun_location) != NUL) | |
2521 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2522 // Enclose path with white space in double quotes. |
7 | 2523 mch_memmove(vimrun_location + 1, vimrun_location, |
2524 STRLEN(vimrun_location) + 1); | |
2525 *vimrun_location = '"'; | |
2526 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2527 } | |
2528 else | |
2529 STRCPY(gettail(vimrun_location), "vimrun "); | |
2530 | |
2531 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2532 s_dont_use_vimrun = FALSE; | |
2533 } | |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2534 else if (executable_exists("vimrun.exe", NULL, TRUE, FALSE)) |
7 | 2535 s_dont_use_vimrun = FALSE; |
2536 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2537 // 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
|
2538 // 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
|
2539 // not need vimrun.exe. |
7 | 2540 if (s_dont_use_vimrun) |
2541 need_vimrun_warning = TRUE; | |
2542 } | |
2543 | |
2544 /* | |
2545 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2546 * Otherwise the default "findstr /n" is used. | |
2547 */ | |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2548 if (!executable_exists("findstr.exe", NULL, TRUE, FALSE)) |
28517 | 2549 set_option_value_give_err((char_u *)"grepprg", |
2550 0, (char_u *)"grep -n", 0); | |
7 | 2551 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2552 # ifdef FEAT_CLIPBOARD |
4168 | 2553 win_clip_init(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2554 # 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
|
2555 |
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
|
2556 vtp_flag_init(); |
7 | 2557 } |
2558 | |
2559 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2560 #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
|
2561 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2562 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 2563 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2564 # 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
|
2565 # define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) |
7 | 2566 |
2567 /* | |
2568 * ClearConsoleBuffer() | |
2569 * Description: | |
2570 * Clears the entire contents of the console screen buffer, using the | |
2571 * specified attribute. | |
2572 * Returns: | |
2573 * TRUE on success | |
2574 */ | |
2575 static BOOL | |
2576 ClearConsoleBuffer(WORD wAttribute) | |
2577 { | |
2578 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2579 COORD coord; | |
2580 DWORD NumCells, dummy; | |
2581 | |
2582 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2583 return FALSE; | |
2584 | |
2585 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2586 coord.X = 0; | |
2587 coord.Y = 0; | |
2588 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2589 coord, &dummy)) | |
2590 return FALSE; | |
2591 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2592 coord, &dummy)) | |
2593 return FALSE; | |
2594 | |
2595 return TRUE; | |
2596 } | |
2597 | |
2598 /* | |
2599 * FitConsoleWindow() | |
2600 * Description: | |
2601 * Checks if the console window will fit within given buffer dimensions. | |
2602 * Also, if requested, will shrink the window to fit. | |
2603 * Returns: | |
2604 * TRUE on success | |
2605 */ | |
2606 static BOOL | |
2607 FitConsoleWindow( | |
2608 COORD dwBufferSize, | |
2609 BOOL WantAdjust) | |
2610 { | |
2611 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2612 COORD dwWindowSize; | |
2613 BOOL NeedAdjust = FALSE; | |
2614 | |
2615 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2616 { | |
2617 /* | |
2618 * A buffer resize will fail if the current console window does | |
2619 * not lie completely within that buffer. To avoid this, we might | |
2620 * have to move and possibly shrink the window. | |
2621 */ | |
2622 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2623 { | |
2624 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2625 if (dwWindowSize.X > dwBufferSize.X) | |
2626 dwWindowSize.X = dwBufferSize.X; | |
2627 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2628 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2629 NeedAdjust = TRUE; | |
2630 } | |
2631 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2632 { | |
2633 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2634 if (dwWindowSize.Y > dwBufferSize.Y) | |
2635 dwWindowSize.Y = dwBufferSize.Y; | |
2636 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2637 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2638 NeedAdjust = TRUE; | |
2639 } | |
2640 if (NeedAdjust && WantAdjust) | |
2641 { | |
2642 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2643 return FALSE; | |
2644 } | |
2645 return TRUE; | |
2646 } | |
2647 | |
2648 return FALSE; | |
2649 } | |
2650 | |
2651 typedef struct ConsoleBufferStruct | |
2652 { | |
26 | 2653 BOOL IsValid; |
2654 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2655 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2656 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
|
2657 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
|
2658 int NumRegions; |
7 | 2659 } ConsoleBuffer; |
2660 | |
2661 /* | |
2662 * SaveConsoleBuffer() | |
2663 * Description: | |
2664 * Saves important information about the console buffer, including the | |
2665 * actual buffer contents. The saved information is suitable for later | |
2666 * restoration by RestoreConsoleBuffer(). | |
2667 * Returns: | |
2668 * TRUE if all information was saved; FALSE otherwise | |
2669 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2670 */ | |
2671 static BOOL | |
2672 SaveConsoleBuffer( | |
2673 ConsoleBuffer *cb) | |
2674 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2675 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2676 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2677 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2678 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
|
2679 int i, numregions; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2680 |
7 | 2681 if (cb == NULL) |
2682 return FALSE; | |
2683 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2684 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2685 { |
2686 cb->IsValid = FALSE; | |
2687 return FALSE; | |
2688 } | |
2689 cb->IsValid = TRUE; | |
2690 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2691 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2692 * 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
|
2693 * 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
|
2694 * 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
|
2695 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2696 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2697 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
|
2698 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
|
2699 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2700 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
|
2701 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
|
2702 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
|
2703 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
|
2704 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
|
2705 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2706 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2707 } |
7 | 2708 |
2709 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2710 * 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
|
2711 * 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
|
2712 * 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
|
2713 * 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
|
2714 * 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
|
2715 * 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
|
2716 * height of each chunk will be (12000 / width). |
7 | 2717 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2718 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2719 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2720 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
|
2721 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
|
2722 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2723 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
|
2724 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
|
2725 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2726 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
|
2727 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
|
2728 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
|
2729 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
|
2730 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2731 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
|
2732 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
|
2733 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2734 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2735 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2736 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr) |
7 | 2737 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2738 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2739 * 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
|
2740 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2741 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2742 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2743 * 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
|
2744 * 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
|
2745 * 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
|
2746 * 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
|
2747 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2748 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2749 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
|
2750 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
|
2751 cb->Buffer, // our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2752 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
|
2753 BufferCoord, // offset in our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2754 &ReadRegion)) // region to save |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2755 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2756 VIM_CLEAR(cb->Buffer); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2757 VIM_CLEAR(cb->Regions); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2758 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2759 } |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2760 cb->Regions[i] = ReadRegion; |
7 | 2761 } |
2762 | |
2763 return TRUE; | |
2764 } | |
2765 | |
2766 /* | |
2767 * RestoreConsoleBuffer() | |
2768 * Description: | |
2769 * Restores important information about the console buffer, including the | |
2770 * actual buffer contents, if desired. The information to restore is in | |
2771 * the same format used by SaveConsoleBuffer(). | |
2772 * Returns: | |
2773 * TRUE on success | |
2774 */ | |
2775 static BOOL | |
2776 RestoreConsoleBuffer( | |
26 | 2777 ConsoleBuffer *cb, |
2778 BOOL RestoreScreen) | |
7 | 2779 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2780 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2781 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
|
2782 int i; |
7 | 2783 |
2784 if (cb == NULL || !cb->IsValid) | |
2785 return FALSE; | |
2786 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2787 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2788 * 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
|
2789 * 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
|
2790 * 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
|
2791 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2792 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2793 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2794 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2795 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2796 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
|
2797 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2798 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
|
2799 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2800 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2801 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2802 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2803 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2804 * 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
|
2805 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2806 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2807 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2808 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2809 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
|
2810 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2811 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
|
2812 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2813 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2814 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2815 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2816 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2817 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2818 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2819 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
|
2820 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2821 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
|
2822 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
|
2823 WriteRegion = cb->Regions[i]; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2824 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
|
2825 cb->Buffer, // our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2826 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
|
2827 BufferCoord, // offset in our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2828 &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
|
2829 return FALSE; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2830 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2831 } |
7 | 2832 |
2833 return TRUE; | |
2834 } | |
2835 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2836 # define FEAT_RESTORE_ORIG_SCREEN |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2837 # ifdef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2838 static ConsoleBuffer g_cbOrig = { 0 }; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2839 # endif |
7 | 2840 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2841 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2842 | |
2843 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
|
2844 HWND g_hWnd = NULL; // also used in os_mswin.c |
7 | 2845 static HICON g_hOrigIconSmall = NULL; |
2846 static HICON g_hOrigIcon = NULL; | |
2847 static HICON g_hVimIcon = NULL; | |
2848 static BOOL g_fCanChangeIcon = FALSE; | |
2849 | |
2850 /* | |
2851 * GetConsoleIcon() | |
2852 * Description: | |
2853 * Attempts to retrieve the small icon and/or the big icon currently in | |
2854 * use by a given window. | |
2855 * Returns: | |
2856 * TRUE on success | |
2857 */ | |
2858 static BOOL | |
2859 GetConsoleIcon( | |
26 | 2860 HWND hWnd, |
2861 HICON *phIconSmall, | |
2862 HICON *phIcon) | |
7 | 2863 { |
2864 if (hWnd == NULL) | |
2865 return FALSE; | |
2866 | |
2867 if (phIconSmall != NULL) | |
26 | 2868 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2869 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2870 if (phIcon != NULL) |
26 | 2871 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2872 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2873 return TRUE; |
2874 } | |
2875 | |
2876 /* | |
2877 * SetConsoleIcon() | |
2878 * Description: | |
2879 * Attempts to change the small icon and/or the big icon currently in | |
2880 * use by a given window. | |
2881 * Returns: | |
2882 * TRUE on success | |
2883 */ | |
2884 static BOOL | |
2885 SetConsoleIcon( | |
26 | 2886 HWND hWnd, |
2887 HICON hIconSmall, | |
2888 HICON hIcon) | |
7 | 2889 { |
2890 if (hWnd == NULL) | |
2891 return FALSE; | |
2892 | |
2893 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2894 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2895 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2896 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2897 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2898 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2899 return TRUE; |
2900 } | |
2901 | |
2902 /* | |
2903 * SaveConsoleTitleAndIcon() | |
2904 * Description: | |
2905 * Saves the current console window title in g_szOrigTitle, for later | |
2906 * restoration. Also, attempts to obtain a handle to the console window, | |
2907 * and use it to save the small and big icons currently in use by the | |
2908 * console window. This is not always possible on some versions of Windows; | |
2909 * nor is it possible when running Vim remotely using Telnet (since the | |
2910 * console window the user sees is owned by a remote process). | |
2911 */ | |
2912 static void | |
2913 SaveConsoleTitleAndIcon(void) | |
2914 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2915 // Save the original title. |
7 | 2916 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) |
2917 return; | |
2918 | |
2919 /* | |
2920 * Obtain a handle to the console window using GetConsoleWindow() from | |
2921 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2922 * This function only exists on NT-based Windows, starting with Windows | |
2923 * 2000. On older operating systems, we can't change the window icon | |
2924 * anyway. | |
2925 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2926 g_hWnd = GetConsoleWindow(); |
7 | 2927 if (g_hWnd == NULL) |
2928 return; | |
2929 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2930 // Save the original console window icon. |
7 | 2931 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); |
2932 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2933 return; | |
2934 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2935 // Extract the first icon contained in the Vim executable. |
30200
499c766d0c14
patch 9.0.0436: CI: running tests in parallel causes flakiness
Bram Moolenaar <Bram@vim.org>
parents:
30112
diff
changeset
|
2936 if ( |
499c766d0c14
patch 9.0.0436: CI: running tests in parallel causes flakiness
Bram Moolenaar <Bram@vim.org>
parents:
30112
diff
changeset
|
2937 # ifdef FEAT_LIBCALL |
499c766d0c14
patch 9.0.0436: CI: running tests in parallel causes flakiness
Bram Moolenaar <Bram@vim.org>
parents:
30112
diff
changeset
|
2938 mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || |
499c766d0c14
patch 9.0.0436: CI: running tests in parallel causes flakiness
Bram Moolenaar <Bram@vim.org>
parents:
30112
diff
changeset
|
2939 # endif |
499c766d0c14
patch 9.0.0436: CI: running tests in parallel causes flakiness
Bram Moolenaar <Bram@vim.org>
parents:
30112
diff
changeset
|
2940 g_hVimIcon == NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2941 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2942 if (g_hVimIcon != NULL) |
2943 g_fCanChangeIcon = TRUE; | |
2944 } | |
2945 | |
2946 static int g_fWindInitCalled = FALSE; | |
2947 static int g_fTermcapMode = FALSE; | |
2948 static CONSOLE_CURSOR_INFO g_cci; | |
2949 | |
2950 /* | |
2951 * non-GUI version of mch_init(). | |
2952 */ | |
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
|
2953 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
|
2954 mch_init_c(void) |
7 | 2955 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2956 # ifndef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2957 CONSOLE_SCREEN_BUFFER_INFO csbi; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2958 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2959 # ifndef __MINGW32__ |
7 | 2960 extern int _fmode; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2961 # endif |
7 | 2962 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2963 // Silently handle invalid parameters to CRT functions |
2584 | 2964 SET_INVALID_PARAM_HANDLER; |
2965 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2966 // 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
|
2967 // for the timestamp test to work on removed floppies. |
7 | 2968 SetErrorMode(SEM_FAILCRITICALERRORS); |
2969 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2970 _fmode = O_BINARY; // we do our own CR-LF translation |
7 | 2971 out_flush(); |
2972 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2973 // Obtain handles for the standard Console I/O devices |
7 | 2974 if (read_cmd_fd == 0) |
2975 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2976 else | |
2977 create_conin(); | |
2978 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
|
2979 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2980 # 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
|
2981 // 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
|
2982 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2983 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
|
2984 # else |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2985 // Get current text attributes |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2986 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2987 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
|
2988 # endif |
7 | 2989 if (cterm_normal_fg_color == 0) |
2990 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2991 if (cterm_normal_bg_color == 0) | |
2992 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2993 | |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
2994 // 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
|
2995 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
|
2996 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
|
2997 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2998 // set termcap codes to current text attributes |
7 | 2999 update_tcap(g_attrCurrent); |
3000 | |
3001 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
3002 GetConsoleMode(g_hConIn, &g_cmodein); | |
3003 GetConsoleMode(g_hConOut, &g_cmodeout); | |
3004 | |
3005 SaveConsoleTitleAndIcon(); | |
3006 /* | |
3007 * Set both the small and big icons of the console window to Vim's icon. | |
3008 * Note that Vim presently only has one size of icon (32x32), but it | |
3009 * automatically gets scaled down to 16x16 when setting the small icon. | |
3010 */ | |
3011 if (g_fCanChangeIcon) | |
3012 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
3013 | |
3014 ui_get_shellsize(); | |
3015 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3016 # ifdef MCH_WRITE_DUMP |
7 | 3017 fdDump = fopen("dump", "wt"); |
3018 | |
3019 if (fdDump) | |
3020 { | |
3021 time_t t; | |
3022 | |
3023 time(&t); | |
3024 fputs(ctime(&t), fdDump); | |
3025 fflush(fdDump); | |
3026 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3027 # endif |
7 | 3028 |
3029 g_fWindInitCalled = TRUE; | |
3030 | |
3031 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
3032 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3033 # ifdef FEAT_CLIPBOARD |
4168 | 3034 win_clip_init(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3035 # 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
|
3036 |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3037 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
|
3038 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
|
3039 wt_init(); |
7 | 3040 } |
3041 | |
3042 /* | |
3043 * non-GUI version of mch_exit(). | |
3044 * Shut down and exit with status `r' | |
3045 * Careful: mch_exit() may be called before mch_init()! | |
3046 */ | |
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
|
3047 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
|
3048 mch_exit_c(int r) |
7 | 3049 { |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
3050 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
|
3051 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3052 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
|
3053 |
7 | 3054 stoptermcap(); |
3055 if (g_fWindInitCalled) | |
3056 settmode(TMODE_COOK); | |
3057 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3058 ml_close_all(TRUE); // remove all memfiles |
7 | 3059 |
3060 if (g_fWindInitCalled) | |
3061 { | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14473
diff
changeset
|
3062 mch_restore_title(SAVE_RESTORE_BOTH); |
7 | 3063 /* |
3064 * Restore both the small and big icons of the console window to | |
3065 * what they were at startup. Don't do this when the window is | |
3066 * closed, Vim would hang here. | |
3067 */ | |
3068 if (g_fCanChangeIcon && !g_fForceExit) | |
3069 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
|
3070 |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3071 # ifdef MCH_WRITE_DUMP |
7 | 3072 if (fdDump) |
3073 { | |
3074 time_t t; | |
3075 | |
3076 time(&t); | |
3077 fputs(ctime(&t), fdDump); | |
3078 fclose(fdDump); | |
3079 } | |
3080 fdDump = NULL; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3081 # endif |
7 | 3082 } |
3083 | |
3084 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
|
3085 SetConsoleMode(g_hConIn, g_cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 3086 SetConsoleMode(g_hConOut, g_cmodeout); |
3087 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3088 # ifdef DYNAMIC_GETTEXT |
7 | 3089 dyn_libintl_end(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3090 # endif |
7 | 3091 |
3092 exit(r); | |
3093 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3094 #endif // !FEAT_GUI_MSWIN |
7 | 3095 |
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
|
3096 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
|
3097 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
|
3098 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3099 #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
|
3100 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
|
3101 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
|
3102 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
|
3103 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
|
3104 #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
|
3105 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
|
3106 #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
|
3107 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
|
3108 #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
|
3109 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3110 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3111 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
|
3112 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
|
3113 { |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
3114 #ifdef FEAT_NETBEANS_INTG |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
3115 netbeans_send_disconnect(); |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
3116 #endif |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
3117 |
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
|
3118 #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
|
3119 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
|
3120 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
|
3121 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
|
3122 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
|
3123 #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
|
3124 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
|
3125 #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
|
3126 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
|
3127 #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
|
3128 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3129 |
7 | 3130 /* |
3131 * Do we have an interactive window? | |
3132 */ | |
3133 int | |
3134 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
|
3135 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
|
3136 char **argv UNUSED) |
7 | 3137 { |
3138 get_exe_name(); | |
3139 | |
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
|
3140 #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
|
3141 return OK; // GUI always has a tty |
7 | 3142 #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
|
3143 # 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
|
3144 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
|
3145 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
|
3146 # endif |
7 | 3147 if (isatty(1)) |
3148 return OK; | |
3149 return FAIL; | |
3150 #endif | |
3151 } | |
3152 | |
5326 | 3153 /* |
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
|
3154 * Set the case of the file name, if it already exists. |
7 | 3155 * When "len" is > 0, also expand short to long filenames. |
3156 */ | |
3157 void | |
3158 fname_case( | |
3159 char_u *name, | |
3160 int len) | |
3161 { | |
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
|
3162 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
|
3163 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
|
3164 WCHAR buf[_MAX_PATH + 1]; |
7 | 3165 |
434 | 3166 flen = (int)STRLEN(name); |
5326 | 3167 if (flen == 0) |
7 | 3168 return; |
3169 | |
3170 slash_adjust(name); | |
3171 | |
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
|
3172 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
|
3173 if (p == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3174 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
|
3175 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3176 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
|
3177 { |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3178 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
|
3179 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3180 if (q != NULL) |
7 | 3181 { |
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
|
3182 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
|
3183 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
|
3184 vim_free(q); |
7 | 3185 } |
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
|
3186 } |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3187 vim_free(p); |
7 | 3188 } |
3189 | |
3190 | |
3191 /* | |
3192 * Insert user name in s[len]. | |
3193 */ | |
3194 int | |
3195 mch_get_user_name( | |
26 | 3196 char_u *s, |
3197 int len) | |
7 | 3198 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3199 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
|
3200 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
|
3201 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3202 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
|
3203 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3204 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
|
3205 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3206 if (p != NULL) |
5549 | 3207 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3208 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
|
3209 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
|
3210 return OK; |
5549 | 3211 } |
3212 } | |
7 | 3213 s[0] = NUL; |
3214 return FAIL; | |
3215 } | |
3216 | |
3217 | |
3218 /* | |
3219 * Insert host name in s[len]. | |
3220 */ | |
3221 void | |
3222 mch_get_host_name( | |
3223 char_u *s, | |
3224 int len) | |
3225 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3226 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
|
3227 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
|
3228 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3229 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
|
3230 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3231 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
|
3232 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3233 if (p != NULL) |
5551 | 3234 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3235 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
|
3236 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
|
3237 return; |
5551 | 3238 } |
3239 } | |
7 | 3240 } |
3241 | |
3242 | |
3243 /* | |
3244 * return process ID | |
3245 */ | |
3246 long | |
26 | 3247 mch_get_pid(void) |
7 | 3248 { |
3249 return (long)GetCurrentProcessId(); | |
3250 } | |
3251 | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3252 /* |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3253 * 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
|
3254 */ |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3255 int |
16455
1ae13586edf8
patch 8.1.1232: can't build on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3256 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
|
3257 { |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3258 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
|
3259 DWORD status = 0; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3260 int ret = FALSE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3261 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3262 if (hProcess == NULL) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3263 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
|
3264 if (GetExitCodeProcess(hProcess, &status) ) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3265 ret = status == STILL_ACTIVE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3266 CloseHandle(hProcess); |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3267 return ret; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3268 } |
7 | 3269 |
3270 /* | |
3271 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
3272 * Return OK for success, FAIL for failure. | |
3273 */ | |
3274 int | |
3275 mch_dirname( | |
3276 char_u *buf, | |
3277 int len) | |
3278 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3279 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
|
3280 |
7 | 3281 /* |
3282 * Originally this was: | |
3283 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
3284 * But the Win32s known bug list says that getcwd() doesn't work | |
3285 * so use the Win32 system call instead. <Negri> | |
3286 */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3287 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
|
3288 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3289 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
|
3290 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
|
3291 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3292 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0) |
7 | 3293 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3294 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
|
3295 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
|
3296 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3297 // long path name is too long, fall back to short one |
7 | 3298 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
|
3299 p = NULL; |
7 | 3300 } |
3301 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3302 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
|
3303 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
|
3304 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3305 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
|
3306 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3307 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
|
3308 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
|
3309 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
|
3310 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3311 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3312 return FAIL; |
7 | 3313 } |
3314 | |
3315 /* | |
5494 | 3316 * Get file permissions for "name". |
3317 * Return mode_t or -1 for error. | |
7 | 3318 */ |
3319 long | |
26 | 3320 mch_getperm(char_u *name) |
7 | 3321 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
3322 stat_T st; |
5494 | 3323 int n; |
3324 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3325 n = mch_stat((char *)name, &st); |
5588 | 3326 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 3327 } |
3328 | |
3329 | |
3330 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3331 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3332 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3333 * Return FAIL for failure, OK otherwise. |
7 | 3334 */ |
3335 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3336 mch_setperm(char_u *name, long perm) |
7 | 3337 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3338 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
|
3339 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
|
3340 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3341 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
|
3342 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
|
3343 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
|
3344 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3345 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
|
3346 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3347 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3348 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3349 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3350 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3351 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3352 return OK; |
7 | 3353 } |
3354 | |
3355 /* | |
3356 * Set hidden flag for "name". | |
3357 */ | |
3358 void | |
3359 mch_hide(char_u *name) | |
3360 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3361 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3362 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3363 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3364 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3365 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3366 win32_setattrs(name, attrs); |
7 | 3367 } |
3368 | |
3369 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3370 * 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
|
3371 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3372 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3373 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3374 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3375 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3376 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3377 if (f == -1) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3378 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
|
3379 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3380 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3381 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3382 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3383 /* |
7 | 3384 * return TRUE if "name" is a directory |
3385 * return FALSE if "name" is not a directory or upon error | |
3386 */ | |
3387 int | |
3388 mch_isdir(char_u *name) | |
3389 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3390 int f = win32_getattrs(name); |
7 | 3391 |
3392 if (f == -1) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3393 return FALSE; // file does not exist at all |
7 | 3394 |
3395 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3396 } | |
3397 | |
3398 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3399 * 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
|
3400 * 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
|
3401 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3402 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3403 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3404 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3405 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3406 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
|
3407 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3408 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3409 /* |
2803 | 3410 * Create directory "name". |
3411 * Return 0 on success, -1 on error. | |
3412 */ | |
3413 int | |
3414 mch_mkdir(char_u *name) | |
3415 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3416 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
|
3417 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
|
3418 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3419 p = 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
|
3420 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
|
3421 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
|
3422 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
|
3423 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
|
3424 return retval; |
2803 | 3425 } |
3426 | |
3427 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3428 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3429 * 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
|
3430 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3431 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3432 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3433 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3434 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
|
3435 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
|
3436 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3437 p = 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
|
3438 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
|
3439 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
|
3440 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
|
3441 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
|
3442 return retval; |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3443 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3444 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3445 /* |
696 | 3446 * Return TRUE if file "fname" has more than one link. |
3447 */ | |
3448 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3449 mch_is_hard_link(char_u *fname) |
696 | 3450 { |
2793 | 3451 BY_HANDLE_FILE_INFORMATION info; |
3452 | |
3453 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3454 && info.nNumberOfLinks > 1; | |
3455 } | |
3456 | |
3457 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3458 * 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
|
3459 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3460 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3461 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3462 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3463 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3464 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3465 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
|
3466 WCHAR *wn; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3467 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3468 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3469 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
|
3470 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
|
3471 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
|
3472 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3473 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
|
3474 vim_free(wn); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3475 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
|
3476 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3477 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
|
3478 reparseTag = findDataW.dwReserved0; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3479 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
|
3480 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3481 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3482 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
|
3483 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3484 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3485 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3486 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3487 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3488 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3489 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3490 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3491 * 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
|
3492 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3493 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3494 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3495 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3496 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3497 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
|
3498 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3499 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3500 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3501 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3502 /* |
2793 | 3503 * Get the by-handle-file-information for "fname". |
3504 * Returns FILEINFO_OK when OK. | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3505 * Returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. |
2793 | 3506 * Returns FILEINFO_READ_FAIL when CreateFile() failed. |
3507 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3508 */ | |
3509 int | |
3510 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3511 { | |
696 | 3512 HANDLE hFile; |
2793 | 3513 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
|
3514 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
|
3515 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3516 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
|
3517 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
|
3518 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
|
3519 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3520 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
|
3521 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
|
3522 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
|
3523 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
|
3524 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
|
3525 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
|
3526 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
|
3527 vim_free(wn); |
696 | 3528 |
3529 if (hFile != INVALID_HANDLE_VALUE) | |
3530 { | |
2793 | 3531 if (GetFileInformationByHandle(hFile, info) != 0) |
3532 res = FILEINFO_OK; | |
3533 else | |
3534 res = FILEINFO_INFO_FAIL; | |
696 | 3535 CloseHandle(hFile); |
3536 } | |
3537 | |
3538 return res; | |
3539 } | |
3540 | |
3541 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3542 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3543 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3544 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3545 */ |
5494 | 3546 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3547 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3548 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3549 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
|
3550 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
|
3551 |
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 = 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
|
3553 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
|
3554 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
|
3555 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3556 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
|
3557 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3558 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3559 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3560 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3561 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3562 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3563 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3564 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3565 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3566 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3567 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3568 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
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 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
|
3571 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
|
3572 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3573 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
|
3574 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
|
3575 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
|
3576 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3577 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
|
3578 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3579 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3580 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3581 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3582 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3583 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3584 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3585 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3586 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3587 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3588 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3589 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3590 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3591 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3592 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3593 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3594 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3595 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3596 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3597 /* |
7 | 3598 * Return TRUE if file or directory "name" is writable (not readonly). |
3599 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3600 * delete a file. Let's say this means it is writable. | |
3601 */ | |
3602 int | |
3603 mch_writable(char_u *name) | |
3604 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3605 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3606 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3607 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3608 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3609 } |
3610 | |
3611 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3612 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3613 * 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
|
3614 * 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
|
3615 * the allocated memory. |
7 | 3616 */ |
3617 int | |
29096
d2ef7d649fcb
patch 8.2.5069: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
29071
diff
changeset
|
3618 mch_can_exe(char_u *name, char_u **path, int use_path UNUSED) |
7 | 3619 { |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
3620 return executable_exists((char *)name, path, TRUE, TRUE); |
7 | 3621 } |
3622 | |
3623 /* | |
3624 * Check what "name" is: | |
3625 * NODE_NORMAL: file or directory (or doesn't exist) | |
3626 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3627 * NODE_OTHER: non-writable things | |
3628 */ | |
3629 int | |
3630 mch_nodetype(char_u *name) | |
3631 { | |
3632 HANDLE hFile; | |
3633 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
|
3634 WCHAR *wn; |
7 | 3635 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3636 // 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
|
3637 // 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
|
3638 // here. |
1004 | 3639 if (STRNCMP(name, "\\\\.\\", 4) == 0) |
3640 return NODE_WRITABLE; | |
3641 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3642 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
|
3643 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
|
3644 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
|
3645 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3646 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
|
3647 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
|
3648 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
|
3649 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
|
3650 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
|
3651 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
|
3652 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
|
3653 vim_free(wn); |
7 | 3654 if (hFile == INVALID_HANDLE_VALUE) |
3655 return NODE_NORMAL; | |
3656 | |
3657 type = GetFileType(hFile); | |
3658 CloseHandle(hFile); | |
3659 if (type == FILE_TYPE_CHAR) | |
3660 return NODE_WRITABLE; | |
3661 if (type == FILE_TYPE_DISK) | |
3662 return NODE_NORMAL; | |
3663 return NODE_OTHER; | |
3664 } | |
3665 | |
3666 #ifdef HAVE_ACL | |
3667 struct my_acl | |
3668 { | |
3669 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3670 PSID pSidOwner; | |
3671 PSID pSidGroup; | |
3672 PACL pDacl; | |
3673 PACL pSacl; | |
3674 }; | |
3675 #endif | |
3676 | |
3677 /* | |
3678 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3679 * Return NULL if the ACL is not available for whatever reason. | |
3680 */ | |
3681 vim_acl_T | |
26 | 3682 mch_get_acl(char_u *fname) |
7 | 3683 { |
3684 #ifndef HAVE_ACL | |
3685 return (vim_acl_T)NULL; | |
3686 #else | |
3687 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3688 DWORD err; |
7 | 3689 |
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
|
3690 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
|
3691 if (p != NULL) |
7 | 3692 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3693 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
|
3694 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3695 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
|
3696 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
|
3697 { |
3b476f974406
patch 8.2.1975: Win32: memory leak when encoding conversion fails
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
3698 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
|
3699 return NULL; |
22856
3b476f974406
patch 8.2.1975: Win32: memory leak when encoding conversion fails
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
3700 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3701 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3702 // 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
|
3703 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
|
3704 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
|
3705 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
|
3706 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
|
3707 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
|
3708 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
|
3709 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
|
3710 &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
|
3711 &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
|
3712 &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
|
3713 &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
|
3714 &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
|
3715 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
|
3716 err == ERROR_PRIVILEGE_NOT_HELD) |
7 | 3717 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3718 // 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
|
3719 (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
|
3720 wn, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3721 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
|
3722 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
|
3723 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3724 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3725 &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
|
3726 NULL, |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3727 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3728 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3729 if (p->pSecurityDescriptor == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3730 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3731 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
|
3732 p = NULL; |
7 | 3733 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3734 vim_free(wn); |
7 | 3735 } |
3736 | |
3737 return (vim_acl_T)p; | |
3738 #endif | |
3739 } | |
3740 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3741 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3742 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3743 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3744 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3745 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3746 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3747 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3748 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3749 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3750 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3751 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3752 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3753 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3754 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3755 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3756 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3757 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3758 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3759 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3760 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3761 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3762 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3763 |
7 | 3764 /* |
3765 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3766 * Errors are ignored. | |
3767 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3768 */ | |
3769 void | |
26 | 3770 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3771 { |
3772 #ifdef HAVE_ACL | |
3773 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
|
3774 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
|
3775 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
|
3776 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3777 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
|
3778 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3779 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3780 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
|
3781 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
|
3782 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3783 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3784 // 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
|
3785 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
|
3786 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
|
3787 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
|
3788 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
|
3789 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
|
3790 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3791 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
|
3792 // 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
|
3793 // 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
|
3794 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
|
3795 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
|
3796 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3797 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
|
3798 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
|
3799 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3800 (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
|
3801 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
|
3802 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
|
3803 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
|
3804 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
|
3805 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
|
3806 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
|
3807 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
|
3808 ); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3809 vim_free(wn); |
7 | 3810 #endif |
3811 } | |
3812 | |
3813 void | |
26 | 3814 mch_free_acl(vim_acl_T acl) |
7 | 3815 { |
3816 #ifdef HAVE_ACL | |
3817 struct my_acl *p = (struct my_acl *)acl; | |
3818 | |
3819 if (p != NULL) | |
3820 { | |
3821 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3822 vim_free(p); | |
3823 } | |
3824 #endif | |
3825 } | |
3826 | |
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
|
3827 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 3828 |
3829 /* | |
3830 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3831 */ | |
3832 static BOOL WINAPI | |
3833 handler_routine( | |
3834 DWORD dwCtrlType) | |
3835 { | |
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
|
3836 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
|
3837 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
|
3838 |
7 | 3839 switch (dwCtrlType) |
3840 { | |
3841 case CTRL_C_EVENT: | |
3842 if (ctrl_c_interrupts) | |
3843 g_fCtrlCPressed = TRUE; | |
3844 return TRUE; | |
3845 | |
3846 case CTRL_BREAK_EVENT: | |
3847 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
|
3848 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
|
3849 // 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
|
3850 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
|
3851 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
|
3852 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
|
3853 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
|
3854 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
|
3855 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
|
3856 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
|
3857 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3858 return TRUE; |
3859 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3860 // fatal events: shut down gracefully |
7 | 3861 case CTRL_CLOSE_EVENT: |
3862 case CTRL_LOGOFF_EVENT: | |
3863 case CTRL_SHUTDOWN_EVENT: | |
3864 windgoto((int)Rows - 1, 0); | |
3865 g_fForceExit = TRUE; | |
3866 | |
1569 | 3867 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3868 (dwCtrlType == CTRL_CLOSE_EVENT |
3869 ? _("close") | |
3870 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3871 ? _("logoff") | |
3872 : _("shutdown"))); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3873 # ifdef DEBUG |
7 | 3874 OutputDebugString(IObuff); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3875 # endif |
7 | 3876 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3877 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
|
3878 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3879 return TRUE; // not reached |
7 | 3880 |
3881 default: | |
3882 return FALSE; | |
3883 } | |
3884 } | |
3885 | |
3886 | |
3887 /* | |
3888 * set the tty in (raw) ? "raw" : "cooked" mode | |
3889 */ | |
3890 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
|
3891 mch_settmode(tmode_T tmode) |
7 | 3892 { |
3893 DWORD cmodein; | |
3894 DWORD cmodeout; | |
3895 BOOL bEnableHandler; | |
3896 | |
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
|
3897 # 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
|
3898 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
|
3899 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
|
3900 # endif |
7 | 3901 GetConsoleMode(g_hConIn, &cmodein); |
3902 GetConsoleMode(g_hConOut, &cmodeout); | |
3903 if (tmode == TMODE_RAW) | |
3904 { | |
3905 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3906 ENABLE_ECHO_INPUT); | |
3907 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
|
3908 { |
7 | 3909 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
|
3910 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
|
3911 } |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3912 else |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3913 { |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3914 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
|
3915 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3916 cmodeout &= ~( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3917 # ifdef FEAT_TERMGUICOLORS |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3918 // 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
|
3919 // 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
|
3920 ((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
|
3921 # 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
|
3922 ENABLE_PROCESSED_OUTPUT | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3923 # 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
|
3924 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3925 bEnableHandler = TRUE; |
3926 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3927 else // cooked |
7 | 3928 { |
3929 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3930 ENABLE_ECHO_INPUT); | |
3931 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3932 bEnableHandler = FALSE; | |
3933 } | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3934 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 3935 SetConsoleMode(g_hConOut, cmodeout); |
3936 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3937 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3938 # ifdef MCH_WRITE_DUMP |
7 | 3939 if (fdDump) |
3940 { | |
3941 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3942 tmode == TMODE_RAW ? "raw" : | |
3943 tmode == TMODE_COOK ? "cooked" : "normal", | |
3944 cmodein, cmodeout); | |
3945 fflush(fdDump); | |
3946 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3947 # endif |
7 | 3948 } |
3949 | |
3950 | |
3951 /* | |
3952 * Get the size of the current window in `Rows' and `Columns' | |
3953 * Return OK when size could be determined, FAIL otherwise. | |
3954 */ | |
3955 int | |
26 | 3956 mch_get_shellsize(void) |
7 | 3957 { |
3958 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3959 | |
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
|
3960 # 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
|
3961 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
|
3962 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
|
3963 # endif |
7 | 3964 if (!g_fTermcapMode && g_cbTermcap.IsValid) |
3965 { | |
3966 /* | |
3967 * For some reason, we are trying to get the screen dimensions | |
3968 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3969 * variables are really intended to mean the size of Vim screen | |
3970 * while in termcap mode. | |
3971 */ | |
3972 Rows = g_cbTermcap.Info.dwSize.Y; | |
3973 Columns = g_cbTermcap.Info.dwSize.X; | |
3974 } | |
3975 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3976 { | |
3977 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3978 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3979 } | |
3980 else | |
3981 { | |
3982 Rows = 25; | |
3983 Columns = 80; | |
3984 } | |
3985 return OK; | |
3986 } | |
3987 | |
3988 /* | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3989 * 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
|
3990 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3991 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3992 ResizeConBuf( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3993 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3994 COORD coordScreen) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3995 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3996 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
|
3997 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3998 # 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
|
3999 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4000 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4001 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
|
4002 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4003 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4004 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4005 # endif |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4006 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4007 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4008 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4009 /* |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4010 * 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
|
4011 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4012 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4013 ResizeWindow( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4014 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4015 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
|
4016 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4017 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
|
4018 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4019 # 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
|
4020 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4021 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4022 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
|
4023 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4024 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4025 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4026 # endif |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4027 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4028 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4029 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4030 /* |
7 | 4031 * Set a console window to `xSize' * `ySize' |
4032 */ | |
4033 static void | |
4034 ResizeConBufAndWindow( | |
26 | 4035 HANDLE hConsole, |
4036 int xSize, | |
4037 int ySize) | |
7 | 4038 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4039 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
|
4040 SMALL_RECT srWindowRect; // hold the new console size |
7 | 4041 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
|
4042 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
|
4043 static int resized = FALSE; |
7 | 4044 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4045 # ifdef MCH_WRITE_DUMP |
7 | 4046 if (fdDump) |
4047 { | |
4048 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
4049 fflush(fdDump); | |
4050 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4051 # endif |
7 | 4052 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4053 // get the largest size we can size the console window to |
7 | 4054 coordScreen = GetLargestConsoleWindowSize(hConsole); |
4055 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4056 // define the new console window size and scroll position |
7 | 4057 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; |
4058 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
4059 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
4060 | |
4061 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
4062 { | |
4063 int sx, sy; | |
4064 | |
4065 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
4066 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
4067 if (sy < ySize || sx < xSize) | |
4068 { | |
4069 /* | |
4070 * Increasing number of lines/columns, do buffer first. | |
4071 * Use the maximal size in x and y direction. | |
4072 */ | |
4073 if (sy < ySize) | |
4074 coordScreen.Y = ySize; | |
4075 else | |
4076 coordScreen.Y = sy; | |
4077 if (sx < xSize) | |
4078 coordScreen.X = xSize; | |
4079 else | |
4080 coordScreen.X = sx; | |
4081 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
4082 } | |
4083 } | |
4084 | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4085 // define the new console buffer size |
7 | 4086 coordScreen.X = xSize; |
4087 coordScreen.Y = ySize; | |
4088 | |
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
|
4089 // 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
|
4090 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
|
4091 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4092 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
|
4093 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
|
4094 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4095 else |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4096 { |
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
|
4097 // 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
|
4098 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
|
4099 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
|
4100 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
|
4101 |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4102 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
|
4103 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
|
4104 resized = TRUE; |
7 | 4105 } |
4106 } | |
4107 | |
4108 | |
4109 /* | |
4110 * Set the console window to `Rows' * `Columns' | |
4111 */ | |
4112 void | |
26 | 4113 mch_set_shellsize(void) |
7 | 4114 { |
4115 COORD coordScreen; | |
4116 | |
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
|
4117 # 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
|
4118 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
|
4119 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
|
4120 # endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4121 // Don't change window size while still starting up |
7 | 4122 if (suppress_winsize != 0) |
4123 { | |
4124 suppress_winsize = 2; | |
4125 return; | |
4126 } | |
4127 | |
4128 if (term_console) | |
4129 { | |
4130 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
4131 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4132 // Clamp Rows and Columns to reasonable values |
7 | 4133 if (Rows > coordScreen.Y) |
4134 Rows = coordScreen.Y; | |
4135 if (Columns > coordScreen.X) | |
4136 Columns = coordScreen.X; | |
4137 | |
4138 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
4139 } | |
4140 } | |
4141 | |
4142 /* | |
4143 * Rows and/or Columns has changed. | |
4144 */ | |
4145 void | |
26 | 4146 mch_new_shellsize(void) |
7 | 4147 { |
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
|
4148 # 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
|
4149 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
|
4150 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
|
4151 # endif |
7 | 4152 set_scroll_region(0, 0, Columns - 1, Rows - 1); |
4153 } | |
4154 | |
4155 | |
4156 /* | |
4157 * Called when started up, to set the winsize that was delayed. | |
4158 */ | |
4159 void | |
26 | 4160 mch_set_winsize_now(void) |
7 | 4161 { |
4162 if (suppress_winsize == 2) | |
4163 { | |
4164 suppress_winsize = 0; | |
4165 mch_set_shellsize(); | |
4166 shell_resized(); | |
4167 } | |
4168 suppress_winsize = 0; | |
4169 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4170 #endif // FEAT_GUI_MSWIN |
7 | 4171 |
5547 | 4172 static BOOL |
4173 vim_create_process( | |
5556 | 4174 char *cmd, |
5569 | 4175 BOOL inherit_handles, |
5547 | 4176 DWORD flags, |
4177 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
|
4178 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
|
4179 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4180 char *cwd) |
5547 | 4181 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4182 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
|
4183 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
|
4184 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4185 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
|
4186 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
|
4187 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
|
4188 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
|
4189 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4190 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
|
4191 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
|
4192 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
|
4193 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4194 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4195 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
|
4196 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
|
4197 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
|
4198 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
|
4199 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
|
4200 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
|
4201 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
|
4202 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
|
4203 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
|
4204 (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
|
4205 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
|
4206 theend: |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4207 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
|
4208 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
|
4209 return ret; |
5547 | 4210 } |
7 | 4211 |
4212 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4213 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
|
4214 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
|
4215 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
|
4216 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
|
4217 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4218 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
|
4219 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
|
4220 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4221 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
|
4222 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
|
4223 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
|
4224 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4225 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
|
4226 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
|
4227 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
|
4228 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4229 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4230 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4231 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) |
7 | 4232 |
4233 /* | |
4234 * Specialised version of system() for Win32 GUI mode. | |
4235 * This version proceeds as follows: | |
4236 * 1. Create a console window for use by the subprocess | |
4237 * 2. Run the subprocess (it gets the allocated console by default) | |
4238 * 3. Wait for the subprocess to terminate and get its exit code | |
4239 * 4. Prompt the user to press a key to close the console window | |
4240 */ | |
4241 static int | |
2935 | 4242 mch_system_classic(char *cmd, int options) |
7 | 4243 { |
4244 STARTUPINFO si; | |
4245 PROCESS_INFORMATION pi; | |
4246 DWORD ret = 0; | |
4247 HWND hwnd = GetFocus(); | |
4248 | |
4249 si.cb = sizeof(si); | |
4250 si.lpReserved = NULL; | |
4251 si.lpDesktop = NULL; | |
4252 si.lpTitle = NULL; | |
4253 si.dwFlags = STARTF_USESHOWWINDOW; | |
4254 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4255 * It's nicer to run a filter command in a minimized window. |
2643 | 4256 * Don't activate the window to keep focus on Vim. |
7 | 4257 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4258 if (options & SHELL_DOOUT) |
2643 | 4259 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 4260 else |
4261 si.wShowWindow = SW_SHOWNORMAL; | |
4262 si.cbReserved2 = 0; | |
4263 si.lpReserved2 = NULL; | |
4264 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4265 // Now, run the command |
5547 | 4266 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
|
4267 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
|
4268 &si, &pi, NULL, NULL); |
7 | 4269 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4270 // Wait for the command to terminate before continuing |
7 | 4271 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4272 # ifdef FEAT_GUI |
7 | 4273 int delay = 1; |
4274 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4275 // Keep updating the window while waiting for the shell to finish. |
7 | 4276 for (;;) |
4277 { | |
4278 MSG msg; | |
4279 | |
27283
b4d92a69035b
patch 8.2.4170: MS-Windows: still using old message API calls
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4280 if (PeekMessageW(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 4281 { |
4282 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
|
4283 DispatchMessageW(&msg); |
3720 | 4284 delay = 1; |
4285 continue; | |
7 | 4286 } |
4287 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4288 break; | |
4289 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4290 // 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
|
4291 // 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
|
4292 // consume too much overhead when it's slow. |
7 | 4293 if (delay < 50) |
4294 delay += 10; | |
4295 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4296 # else |
7 | 4297 WaitForSingleObject(pi.hProcess, INFINITE); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4298 # endif |
7 | 4299 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4300 // Get the command exit code |
7 | 4301 GetExitCodeProcess(pi.hProcess, &ret); |
4302 } | |
4303 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4304 // Close the handles to the subprocess, so that it goes away |
7 | 4305 CloseHandle(pi.hThread); |
4306 CloseHandle(pi.hProcess); | |
4307 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4308 // Try to get input focus back. Doesn't always work though. |
7 | 4309 PostMessage(hwnd, WM_SETFOCUS, 0, 0); |
4310 | |
4311 return ret; | |
4312 } | |
2935 | 4313 |
4314 /* | |
4315 * Thread launched by the gui to send the current buffer data to the | |
4316 * process. This way avoid to hang up vim totally if the children | |
4317 * process take a long time to process the lines. | |
4318 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4319 static unsigned int __stdcall |
2935 | 4320 sub_process_writer(LPVOID param) |
4321 { | |
4322 HANDLE g_hChildStd_IN_Wr = param; | |
4323 linenr_T lnum = curbuf->b_op_start.lnum; | |
4324 DWORD len = 0; | |
4325 DWORD l; | |
4326 char_u *lp = ml_get(lnum); | |
4327 char_u *s; | |
4328 int written = 0; | |
4329 | |
4330 for (;;) | |
4331 { | |
4332 l = (DWORD)STRLEN(lp + written); | |
4333 if (l == 0) | |
4334 len = 0; | |
4335 else if (lp[written] == NL) | |
4336 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4337 // NL -> NUL translation |
2935 | 4338 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); |
4339 } | |
4340 else | |
4341 { | |
4342 s = vim_strchr(lp + written, NL); | |
4343 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4344 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4345 &len, NULL); | |
4346 } | |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
4347 if (len == l) |
2935 | 4348 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4349 // 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
|
4350 // one. |
2935 | 4351 if (lnum != curbuf->b_op_end.lnum |
6933 | 4352 || (!curbuf->b_p_bin |
4353 && curbuf->b_p_fixeol) | |
2935 | 4354 || (lnum != curbuf->b_no_eol_lnum |
4355 && (lnum != curbuf->b_ml.ml_line_count | |
4356 || curbuf->b_p_eol))) | |
4357 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4358 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
|
4359 (LPDWORD)&vim_ignored, NULL); |
2935 | 4360 } |
4361 | |
4362 ++lnum; | |
4363 if (lnum > curbuf->b_op_end.lnum) | |
4364 break; | |
4365 | |
4366 lp = ml_get(lnum); | |
4367 written = 0; | |
4368 } | |
4369 else if (len > 0) | |
4370 written += len; | |
4371 } | |
4372 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4373 // finished all the lines, close pipe |
2935 | 4374 CloseHandle(g_hChildStd_IN_Wr); |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4375 return 0; |
2935 | 4376 } |
4377 | |
4378 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4379 # define BUFLEN 100 // length for buffer, stolen from unix version |
2935 | 4380 |
4381 /* | |
4382 * This function read from the children's stdout and write the | |
4383 * data on screen or in the buffer accordingly. | |
4384 */ | |
4385 static void | |
4386 dump_pipe(int options, | |
4387 HANDLE g_hChildStd_OUT_Rd, | |
4388 garray_T *ga, | |
4389 char_u buffer[], | |
4390 DWORD *buffer_off) | |
4391 { | |
4392 DWORD availableBytes = 0; | |
4393 DWORD i; | |
4394 int ret; | |
4395 DWORD len; | |
4396 DWORD toRead; | |
4397 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4398 // 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
|
4399 // 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
|
4400 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
|
4401 NULL, // optional buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4402 0, // buffer size |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4403 NULL, // number of read bytes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4404 &availableBytes, // available bytes total |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4405 NULL); // byteLeft |
2935 | 4406 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4407 // We got real data in the pipe, read it |
3622 | 4408 while (ret != 0 && availableBytes > 0) |
2935 | 4409 { |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4410 toRead = (DWORD)(BUFLEN - *buffer_off); |
2935 | 4411 toRead = availableBytes < toRead ? availableBytes : toRead; |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4412 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); |
2935 | 4413 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4414 // If we haven't read anything, there is a problem |
2935 | 4415 if (len == 0) |
4416 break; | |
4417 | |
4418 availableBytes -= len; | |
4419 | |
4420 if (options & SHELL_READ) | |
4421 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4422 // 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
|
4423 // lines to the current buffer. |
2935 | 4424 for (i = 0; i < len; ++i) |
4425 { | |
4426 if (buffer[i] == NL) | |
4427 append_ga_line(ga); | |
4428 else if (buffer[i] == NUL) | |
4429 ga_append(ga, NL); | |
4430 else | |
4431 ga_append(ga, buffer[i]); | |
4432 } | |
4433 } | |
4434 else if (has_mbyte) | |
4435 { | |
4436 int l; | |
3030 | 4437 int c; |
4438 char_u *p; | |
2935 | 4439 |
4440 len += *buffer_off; | |
4441 buffer[len] = NUL; | |
4442 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4443 // 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
|
4444 // 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
|
4445 // round. |
2935 | 4446 for (p = buffer; p < buffer + len; p += l) |
4447 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4448 l = MB_CPTR2LEN(p); |
2935 | 4449 if (l == 0) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4450 l = 1; // NUL byte? |
2935 | 4451 else if (MB_BYTE2LEN(*p) != l) |
4452 break; | |
4453 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4454 if (p == buffer) // no complete character |
2935 | 4455 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4456 // avoid getting stuck at an illegal byte |
2935 | 4457 if (len >= 12) |
4458 ++p; | |
4459 else | |
4460 { | |
4461 *buffer_off = len; | |
4462 return; | |
4463 } | |
4464 } | |
4465 c = *p; | |
4466 *p = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4467 msg_puts((char *)buffer); |
2935 | 4468 if (p < buffer + len) |
4469 { | |
4470 *p = c; | |
4471 *buffer_off = (DWORD)((buffer + len) - p); | |
4472 mch_memmove(buffer, p, *buffer_off); | |
4473 return; | |
4474 } | |
4475 *buffer_off = 0; | |
4476 } | |
4477 else | |
4478 { | |
4479 buffer[len] = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4480 msg_puts((char *)buffer); |
2935 | 4481 } |
4482 | |
4483 windgoto(msg_row, msg_col); | |
4484 cursor_on(); | |
4485 out_flush(); | |
4486 } | |
4487 } | |
4488 | |
4489 /* | |
4490 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4491 * for communication and doesn't open any new window. | |
4492 */ | |
4493 static int | |
4494 mch_system_piped(char *cmd, int options) | |
4495 { | |
4496 STARTUPINFO si; | |
4497 PROCESS_INFORMATION pi; | |
4498 DWORD ret = 0; | |
4499 | |
4500 HANDLE g_hChildStd_IN_Rd = NULL; | |
4501 HANDLE g_hChildStd_IN_Wr = NULL; | |
4502 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4503 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4504 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4505 char_u buffer[BUFLEN + 1]; // reading buffer + size |
2935 | 4506 DWORD len; |
4507 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4508 // buffer used to receive keys |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4509 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
|
4510 int ta_len = 0; // valid bytes in ta_buf[] |
2935 | 4511 |
4512 DWORD i; | |
4513 int noread_cnt = 0; | |
4514 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
|
4515 int delay = 1; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4516 DWORD buffer_off = 0; // valid bytes in buffer[] |
3361 | 4517 char *p = NULL; |
2935 | 4518 |
4519 SECURITY_ATTRIBUTES saAttr; | |
4520 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4521 // Set the bInheritHandle flag so pipe handles are inherited. |
2935 | 4522 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
4523 saAttr.bInheritHandle = TRUE; | |
4524 saAttr.lpSecurityDescriptor = NULL; | |
4525 | |
4526 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
|
4527 // 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
|
4528 || ! 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
|
4529 // Create a pipe for the child process's STDIN. |
2935 | 4530 || ! 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
|
4531 // 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
|
4532 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4533 { |
4534 CloseHandle(g_hChildStd_IN_Rd); | |
4535 CloseHandle(g_hChildStd_IN_Wr); | |
4536 CloseHandle(g_hChildStd_OUT_Rd); | |
4537 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
|
4538 msg_puts(_("\nCannot create pipes\n")); |
2935 | 4539 } |
4540 | |
4541 si.cb = sizeof(si); | |
4542 si.lpReserved = NULL; | |
4543 si.lpDesktop = NULL; | |
4544 si.lpTitle = NULL; | |
4545 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4546 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4547 // set-up our file redirection |
2935 | 4548 si.hStdError = g_hChildStd_OUT_Wr; |
4549 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4550 si.hStdInput = g_hChildStd_IN_Rd; | |
4551 si.wShowWindow = SW_HIDE; | |
4552 si.cbReserved2 = 0; | |
4553 si.lpReserved2 = NULL; | |
4554 | |
4555 if (options & SHELL_READ) | |
4556 ga_init2(&ga, 1, BUFLEN); | |
4557 | |
3361 | 4558 if (cmd != NULL) |
4559 { | |
4560 p = (char *)vim_strsave((char_u *)cmd); | |
4561 if (p != NULL) | |
4562 unescape_shellxquote((char_u *)p, p_sxe); | |
4563 else | |
4564 p = cmd; | |
4565 } | |
4566 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4567 // Now, run the command. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4568 // 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
|
4569 // 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
|
4570 // 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
|
4571 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
|
4572 &si, &pi, NULL, NULL); |
2935 | 4573 |
3361 | 4574 if (p != cmd) |
4575 vim_free(p); | |
2935 | 4576 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4577 // Close our unused side of the pipes |
2935 | 4578 CloseHandle(g_hChildStd_IN_Rd); |
4579 CloseHandle(g_hChildStd_OUT_Wr); | |
4580 | |
4581 if (options & SHELL_WRITE) | |
4582 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4583 HANDLE thread = (HANDLE) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4584 _beginthreadex(NULL, // security attributes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4585 0, // default stack size |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4586 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
|
4587 g_hChildStd_IN_Wr, // parameter |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4588 0, // creation flag, start immediately |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4589 NULL); // we don't care about thread id |
2935 | 4590 CloseHandle(thread); |
4591 g_hChildStd_IN_Wr = NULL; | |
4592 } | |
4593 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4594 // Keep updating the window while waiting for the shell to finish. |
2935 | 4595 for (;;) |
4596 { | |
4597 MSG msg; | |
4598 | |
27283
b4d92a69035b
patch 8.2.4170: MS-Windows: still using old message API calls
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4599 if (PeekMessageW(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4600 { |
4601 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
|
4602 DispatchMessageW(&msg); |
2935 | 4603 } |
4604 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4605 // write pipe information in the window |
2935 | 4606 if ((options & (SHELL_READ|SHELL_WRITE)) |
4607 # ifdef FEAT_GUI | |
4608 || gui.in_use | |
4609 # endif | |
4610 ) | |
4611 { | |
4612 len = 0; | |
4613 if (!(options & SHELL_EXPAND) | |
4614 && ((options & | |
4615 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4616 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4617 # ifdef FEAT_GUI | |
4618 || gui.in_use | |
4619 # endif | |
4620 ) | |
4621 && (ta_len > 0 || noread_cnt > 4)) | |
4622 { | |
4623 if (ta_len == 0) | |
4624 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4625 // 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
|
4626 // counter and timer. |
2935 | 4627 noread_cnt = 0; |
4628 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4629 } | |
4630 if (ta_len > 0 || len > 0) | |
4631 { | |
4632 /* | |
4633 * For pipes: Check for CTRL-C: send interrupt signal to | |
4634 * child. Check for CTRL-D: EOF, close pipe to child. | |
4635 */ | |
4636 if (len == 1 && cmd != NULL) | |
4637 { | |
4638 if (ta_buf[ta_len] == Ctrl_C) | |
4639 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4640 // 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
|
4641 // now put 9 as SIGKILL |
2935 | 4642 TerminateProcess(pi.hProcess, 9); |
4643 } | |
4644 if (ta_buf[ta_len] == Ctrl_D) | |
4645 { | |
4646 CloseHandle(g_hChildStd_IN_Wr); | |
4647 g_hChildStd_IN_Wr = NULL; | |
4648 } | |
4649 } | |
4650 | |
30641
1207b6d6cf9e
patch 9.0.0655: passing modifier codes to a shell running in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30637
diff
changeset
|
4651 len = term_replace_keycodes(ta_buf, ta_len, len); |
2935 | 4652 |
4653 /* | |
4654 * For pipes: echo the typed characters. For a pty this | |
4655 * does not seem to work. | |
4656 */ | |
4657 for (i = ta_len; i < ta_len + len; ++i) | |
4658 { | |
4659 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4660 msg_putchar(ta_buf[i]); | |
4661 else if (has_mbyte) | |
4662 { | |
4663 int l = (*mb_ptr2len)(ta_buf + i); | |
4664 | |
4665 msg_outtrans_len(ta_buf + i, l); | |
4666 i += l - 1; | |
4667 } | |
4668 else | |
4669 msg_outtrans_len(ta_buf + i, 1); | |
4670 } | |
4671 windgoto(msg_row, msg_col); | |
4672 out_flush(); | |
4673 | |
4674 ta_len += len; | |
4675 | |
4676 /* | |
4677 * Write the characters to the child, unless EOF has been | |
4678 * typed for pipes. Write one character at a time, to | |
4679 * avoid losing too much typeahead. When writing buffer | |
4680 * lines, drop the typed characters (only check for | |
4681 * CTRL-C). | |
4682 */ | |
4683 if (options & SHELL_WRITE) | |
4684 ta_len = 0; | |
4685 else if (g_hChildStd_IN_Wr != NULL) | |
4686 { | |
4687 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4688 1, &len, NULL); | |
4689 // if we are typing in, we want to keep things reactive | |
4690 delay = 1; | |
4691 if (len > 0) | |
4692 { | |
4693 ta_len -= len; | |
4694 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4695 } | |
4696 } | |
4697 } | |
4698 } | |
4699 } | |
4700 | |
4701 if (ta_len) | |
4702 ui_inchar_undo(ta_buf, ta_len); | |
4703 | |
4704 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4705 { | |
3030 | 4706 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4707 break; |
4708 } | |
4709 | |
4710 ++noread_cnt; | |
3030 | 4711 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4712 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4713 // 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
|
4714 // 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
|
4715 // consume too much overhead when it's slow. |
2935 | 4716 if (delay < 50) |
4717 delay += 10; | |
4718 } | |
4719 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4720 // Close the pipe |
2935 | 4721 CloseHandle(g_hChildStd_OUT_Rd); |
4722 if (g_hChildStd_IN_Wr != NULL) | |
4723 CloseHandle(g_hChildStd_IN_Wr); | |
4724 | |
4725 WaitForSingleObject(pi.hProcess, INFINITE); | |
4726 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4727 // Get the command exit code |
2935 | 4728 GetExitCodeProcess(pi.hProcess, &ret); |
4729 | |
4730 if (options & SHELL_READ) | |
4731 { | |
4732 if (ga.ga_len > 0) | |
4733 { | |
4734 append_ga_line(&ga); | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4735 // remember that the NL was missing |
2935 | 4736 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
4737 } | |
4738 else | |
4739 curbuf->b_no_eol_lnum = 0; | |
4740 ga_clear(&ga); | |
4741 } | |
4742 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4743 // Close the handles to the subprocess, so that it goes away |
2935 | 4744 CloseHandle(pi.hThread); |
4745 CloseHandle(pi.hProcess); | |
4746 | |
4747 return ret; | |
4748 } | |
4749 | |
4750 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
|
4751 mch_system_g(char *cmd, int options) |
2935 | 4752 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4753 // 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
|
4754 if (!p_stmp) |
2935 | 4755 return mch_system_piped(cmd, options); |
4756 else | |
4757 return mch_system_classic(cmd, options); | |
4758 } | |
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
|
4759 #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
|
4760 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4761 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5547 | 4762 static int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
4763 mch_system_c(char *cmd, int options UNUSED) |
5547 | 4764 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4765 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
|
4766 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
|
4767 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
|
4768 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
|
4769 |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4770 // 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
|
4771 // 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
|
4772 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
|
4773 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
|
4774 { |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4775 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
|
4776 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
|
4777 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
|
4778 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
|
4779 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
|
4780 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
|
4781 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
|
4782 } |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4783 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
|
4784 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
|
4785 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4786 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
|
4787 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
|
4788 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4789 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
|
4790 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
|
4791 return ret; |
5547 | 4792 } |
7 | 4793 |
4794 #endif | |
4795 | |
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
|
4796 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
|
4797 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
|
4798 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4799 #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
|
4800 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
|
4801 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
|
4802 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
|
4803 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
|
4804 #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
|
4805 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
|
4806 #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
|
4807 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
|
4808 #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
|
4809 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4810 |
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
|
4811 #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
|
4812 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4813 * 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
|
4814 */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4815 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
|
4816 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
|
4817 char_u *cmd, |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4818 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
|
4819 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4820 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
|
4821 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
|
4822 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
|
4823 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
|
4824 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
|
4825 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
|
4826 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
|
4827 aco_save_T aco; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4828 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
|
4829 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4830 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4831 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
|
4832 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4833 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
|
4834 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
|
4835 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
|
4836 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4837 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4838 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4839 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
|
4840 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
|
4841 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4842 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4843 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4844 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
|
4845 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
|
4846 } |
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
|
4847 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4848 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
|
4849 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4850 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
|
4851 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
|
4852 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
|
4853 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
|
4854 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
|
4855 { |
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4856 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
|
4857 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
|
4858 } |
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
|
4859 |
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
|
4860 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
|
4861 ++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
|
4862 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4863 // 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
|
4864 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
|
4865 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4866 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
|
4867 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
|
4868 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4869 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
|
4870 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4871 // 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
|
4872 // 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
|
4873 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
|
4874 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
|
4875 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4876 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
|
4877 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
|
4878 } |
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
|
4879 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
|
4880 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
|
4881 |
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
|
4882 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
|
4883 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4884 // 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
|
4885 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
|
4886 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4887 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
|
4888 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
|
4889 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4890 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
|
4891 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
|
4892 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4893 #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
|
4894 |
7 | 4895 /* |
4896 * Either execute a command by calling the shell or start a new shell | |
4897 */ | |
4898 int | |
4899 mch_call_shell( | |
26 | 4900 char_u *cmd, |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4901 int options) // SHELL_*, see vim.h |
7 | 4902 { |
4903 int x = 0; | |
4904 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
|
4905 WCHAR szShellTitle[512]; |
6293 | 4906 |
28435
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
27657
diff
changeset
|
4907 #ifdef FEAT_JOB_CHANNEL |
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
27657
diff
changeset
|
4908 ch_log(NULL, "executing shell command: %s", cmd); |
0533e7466ef0
patch 8.2.4742: there is no way to start logging very early in startup
Bram Moolenaar <Bram@vim.org>
parents:
27657
diff
changeset
|
4909 #endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4910 // 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
|
4911 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
|
4912 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4913 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
|
4914 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
|
4915 else |
6290 | 4916 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4917 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
|
4918 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4919 if (wn != NULL) |
6290 | 4920 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4921 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
|
4922 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
|
4923 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
|
4924 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
|
4925 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
|
4926 vim_free(wn); |
6290 | 4927 } |
4928 } | |
4929 } | |
7 | 4930 |
4931 out_flush(); | |
4932 | |
4933 #ifdef MCH_WRITE_DUMP | |
4934 if (fdDump) | |
4935 { | |
4936 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4937 fflush(fdDump); | |
4938 } | |
4939 #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
|
4940 #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
|
4941 // 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
|
4942 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
|
4943 # 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
|
4944 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
|
4945 # endif |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4946 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
|
4947 && (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
|
4948 { |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4949 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
|
4950 |
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
|
4951 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
|
4952 // 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
|
4953 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
|
4954 ++cmdbase; |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4955 |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4956 // 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
|
4957 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
|
4958 || !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
|
4959 { |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4960 // 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
|
4961 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
|
4962 resettitle(); |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4963 return x; |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4964 } |
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
|
4965 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4966 #endif |
7 | 4967 |
4968 /* | |
4969 * Catch all deadly signals while running the external command, because a | |
4970 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4971 */ | |
4972 signal(SIGINT, SIG_IGN); | |
4973 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4974 signal(SIGKILL, SIG_IGN); | |
4975 #else | |
4976 signal(SIGBREAK, SIG_IGN); | |
4977 #endif | |
4978 signal(SIGILL, SIG_IGN); | |
4979 signal(SIGFPE, SIG_IGN); | |
4980 signal(SIGSEGV, SIG_IGN); | |
4981 signal(SIGTERM, SIG_IGN); | |
4982 signal(SIGABRT, SIG_IGN); | |
4983 | |
4984 if (options & SHELL_COOKED) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4985 settmode(TMODE_COOK); // set to normal mode |
7 | 4986 |
4987 if (cmd == NULL) | |
4988 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4989 x = mch_system((char *)p_sh, options); |
7 | 4990 } |
4991 else | |
4992 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4993 // we use "command" or "cmd" to start the shell; slow but easy |
3363 | 4994 char_u *newcmd = NULL; |
4995 char_u *cmdbase = cmd; | |
4996 long_u cmdlen; | |
3361 | 4997 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4998 // Skip a leading ", ( and "(. |
3361 | 4999 if (*cmdbase == '"' ) |
5000 ++cmdbase; | |
5001 if (*cmdbase == '(') | |
5002 ++cmdbase; | |
5003 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5004 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 5005 { |
5006 STARTUPINFO si; | |
5007 PROCESS_INFORMATION pi; | |
5008 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
|
5009 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 5010 char_u *p; |
5011 | |
5627 | 5012 ZeroMemory(&si, sizeof(si)); |
3361 | 5013 si.cb = sizeof(si); |
5014 si.lpReserved = NULL; | |
5015 si.lpDesktop = NULL; | |
5016 si.lpTitle = NULL; | |
5017 si.dwFlags = 0; | |
5018 si.cbReserved2 = 0; | |
5019 si.lpReserved2 = NULL; | |
5020 | |
5021 cmdbase = skipwhite(cmdbase + 5); | |
5022 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
|
5023 && VIM_ISWHITE(cmdbase[4])) |
3361 | 5024 { |
5025 cmdbase = skipwhite(cmdbase + 4); | |
5026 si.dwFlags = STARTF_USESHOWWINDOW; | |
5027 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
|
5028 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 5029 } |
5030 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
|
5031 && VIM_ISWHITE(cmdbase[2])) |
3361 | 5032 { |
5033 cmdbase = skipwhite(cmdbase + 2); | |
5034 flags = CREATE_NO_WINDOW; | |
5035 si.dwFlags = STARTF_USESTDHANDLES; | |
5036 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 5037 GENERIC_READ, // Access flags |
3361 | 5038 0, // Share flags |
3363 | 5039 NULL, // Security att. |
5040 OPEN_EXISTING, // Open flags | |
5041 FILE_ATTRIBUTE_NORMAL, // File att. | |
5042 NULL); // Temp file | |
3361 | 5043 si.hStdOutput = si.hStdInput; |
5044 si.hStdError = si.hStdInput; | |
5045 } | |
5046 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5047 // 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
|
5048 // at the start of the command. |
3361 | 5049 if (cmdbase > cmd) |
5050 { | |
5051 p = cmdbase + STRLEN(cmdbase); | |
5052 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
5053 *--p = NUL; | |
5054 if (p > cmdbase && p[-1] == ')' | |
5055 && (*cmd =='(' || cmd[1] == '(')) | |
5056 *--p = NUL; | |
5057 } | |
5058 | |
3363 | 5059 newcmd = cmdbase; |
5060 unescape_shellxquote(cmdbase, p_sxe); | |
5061 | |
3361 | 5062 /* |
3363 | 5063 * If creating new console, arguments are passed to the |
5064 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
5065 * correctly for current 'cmd.exe'. So unescape characters in | |
5066 * shellxescape except '|' for avoiding to be treated as | |
5067 * argument to them. Pass the arguments to sub-shell. | |
3361 | 5068 */ |
3363 | 5069 if (flags != CREATE_NEW_CONSOLE) |
5070 { | |
5071 char_u *subcmd; | |
3367 | 5072 char_u *cmd_shell = mch_getenv("COMSPEC"); |
5073 | |
5074 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
|
5075 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5076 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5077 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5078 (char_u *)"|", '^', FALSE); |
3363 | 5079 if (subcmd != NULL) |
5080 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5081 // make "cmd.exe /c arguments" |
3363 | 5082 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
|
5083 newcmd = alloc(cmdlen); |
3363 | 5084 if (newcmd != NULL) |
5085 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 5086 cmd_shell, subcmd); |
3363 | 5087 else |
5088 newcmd = cmdbase; | |
3367 | 5089 vim_free(subcmd); |
3363 | 5090 } |
5091 } | |
3361 | 5092 |
5093 /* | |
5094 * Now, start the command as a process, so that it doesn't | |
5095 * inherit our handles which causes unpleasant dangling swap | |
5096 * files if we exit before the spawned process | |
5097 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5098 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
|
5099 &si, &pi, NULL, NULL)) |
3361 | 5100 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
|
5101 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
|
5102 > (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
|
5103 x = 0; |
3361 | 5104 else |
5105 { | |
5106 x = -1; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5107 #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
|
5108 # 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
|
5109 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
|
5110 # endif |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5111 emsg(_(e_command_not_found)); |
3361 | 5112 #endif |
5113 } | |
3363 | 5114 |
5115 if (newcmd != cmdbase) | |
5116 vim_free(newcmd); | |
5117 | |
5627 | 5118 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 5119 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5120 // Close the handle to \\.\NUL created above. |
3361 | 5121 CloseHandle(si.hStdInput); |
5122 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5123 // Close the handles to the subprocess, so that it goes away |
3361 | 5124 CloseHandle(pi.hThread); |
5125 CloseHandle(pi.hProcess); | |
5126 } | |
5127 else | |
5128 { | |
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
|
5129 cmdlen = |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5130 #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
|
5131 ((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
|
5132 (!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
|
5133 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
|
5134 : 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
|
5135 #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
|
5136 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
1569 | 5137 |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
5138 newcmd = alloc(cmdlen); |
3361 | 5139 if (newcmd != NULL) |
7 | 5140 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5141 #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
|
5142 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
|
5143 # 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
|
5144 (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
|
5145 # 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
|
5146 need_vimrun_warning) |
7 | 5147 { |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5148 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
|
5149 "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
|
5150 "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
|
5151 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
|
5152 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
|
5153 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
|
5154 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5155 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
|
5156 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
|
5157 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
|
5158 vim_free(wtitle); |
7 | 5159 need_vimrun_warning = FALSE; |
5160 } | |
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
|
5161 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
|
5162 # 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
|
5163 (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
|
5164 # 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
|
5165 !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
|
5166 // 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
|
5167 // 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
|
5168 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 5169 vimrun_path, |
5170 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
5171 ? "-s " : "", | |
5172 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
|
5173 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
|
5174 # 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
|
5175 (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
|
5176 # 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
|
5177 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
|
5178 // 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
|
5179 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
|
5180 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
|
5181 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
|
5182 #endif |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5183 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 5184 p_sh, p_shcf, cmd); |
7 | 5185 x = mch_system((char *)newcmd, options); |
3361 | 5186 vim_free(newcmd); |
7 | 5187 } |
5188 } | |
5189 } | |
5190 | |
5191 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
|
5192 { |
3bb4dea4a164
patch 8.2.0773: switching to raw mode every time ":" is used
Bram Moolenaar <Bram@vim.org>
parents:
20227
diff
changeset
|
5193 // 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
|
5194 cur_tmode = TMODE_UNKNOWN; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5195 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
|
5196 } |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5197 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5198 // Print the return value, unless "vimrun" was used. |
7 | 5199 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
|
5200 #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
|
5201 && ((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
|
5202 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1) |
7 | 5203 #endif |
5204 ) | |
5205 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5206 smsg(_("shell returned %d"), x); |
7 | 5207 msg_putchar('\n'); |
5208 } | |
5209 resettitle(); | |
5210 | |
5211 signal(SIGINT, SIG_DFL); | |
5212 #if defined(__GNUC__) && !defined(__MINGW32__) | |
5213 signal(SIGKILL, SIG_DFL); | |
5214 #else | |
5215 signal(SIGBREAK, SIG_DFL); | |
5216 #endif | |
5217 signal(SIGILL, SIG_DFL); | |
5218 signal(SIGFPE, SIG_DFL); | |
5219 signal(SIGSEGV, SIG_DFL); | |
5220 signal(SIGTERM, SIG_DFL); | |
5221 signal(SIGABRT, SIG_DFL); | |
5222 | |
5223 return x; | |
5224 } | |
5225 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5226 #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
|
5227 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5228 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
|
5229 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
|
5230 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
|
5231 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
|
5232 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
|
5233 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
|
5234 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5235 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5236 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
|
5237 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
|
5238 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5239 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
|
5240 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
|
5241 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
|
5242 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5243 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
|
5244 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
|
5245 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
|
5246 vim_free(wn); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5247 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5248 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5249 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5250 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5251 * 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
|
5252 * 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
|
5253 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
5254 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
|
5255 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
|
5256 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5257 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
|
5258 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
|
5259 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
|
5260 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5261 // 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
|
5262 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
|
5263 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5264 |
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
|
5265 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
|
5266 { |
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
|
5267 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
|
5268 { |
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
|
5269 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
|
5270 { |
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
|
5271 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
|
5272 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
|
5273 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
|
5274 --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
|
5275 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
|
5276 { |
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
|
5277 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
|
5278 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
|
5279 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
|
5280 |
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
|
5281 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
|
5282 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
|
5283 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
|
5284 *((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
|
5285 *((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
|
5286 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
|
5287 *((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
|
5288 *((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
|
5289 } |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5290 vim_free(wkey); |
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5291 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
|
5292 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5293 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5294 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5295 |
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
|
5296 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
|
5297 { |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5298 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
|
5299 |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5300 // 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
|
5301 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
|
5302 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
|
5303 |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5304 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
|
5305 { |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5306 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
|
5307 *((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
|
5308 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
|
5309 } |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5310 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
|
5311 *((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
|
5312 } |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5313 |
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
|
5314 # 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
|
5315 { |
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
|
5316 # 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
|
5317 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
|
5318 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
|
5319 # 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
|
5320 # 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
|
5321 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
|
5322 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
|
5323 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5324 // 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
|
5325 // 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
|
5326 // 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
|
5327 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
|
5328 # 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
|
5329 + 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
|
5330 # 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
|
5331 # 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
|
5332 + 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
|
5333 # 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
|
5334 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5335 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5336 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
|
5337 { |
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
|
5338 # 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
|
5339 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
|
5340 *((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
|
5341 (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
|
5342 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
|
5343 *((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
|
5344 (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
|
5345 *((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
|
5346 # 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
|
5347 # 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
|
5348 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
|
5349 { |
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
|
5350 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
|
5351 *((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
|
5352 (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
|
5353 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
|
5354 *((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
|
5355 (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
|
5356 *((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
|
5357 } |
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
|
5358 # 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
|
5359 } |
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
|
5360 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5361 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5362 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5363 |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5364 /* |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5365 * 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
|
5366 * 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
|
5367 */ |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5368 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
|
5369 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
|
5370 { |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5371 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
|
5372 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
|
5373 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
|
5374 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5375 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
|
5376 GetCurrentProcessId(), |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5377 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
|
5378 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5379 // 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
|
5380 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
|
5381 name, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5382 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
|
5383 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
|
5384 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
|
5385 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5386 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
|
5387 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
|
5388 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5389 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
|
5390 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
|
5391 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
|
5392 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5393 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
|
5394 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
|
5395 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
|
5396 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
|
5397 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5398 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
|
5399 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5400 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
|
5401 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
|
5402 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5403 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5404 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
|
5405 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5406 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5407 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5408 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
|
5409 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5410 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5411 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5412 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5413 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5414 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5415 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5416 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5417 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
|
5418 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5419 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5420 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
|
5421 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
|
5422 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
|
5423 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
|
5424 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
|
5425 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
|
5426 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
|
5427 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5428 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
|
5429 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5430 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5431 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5432 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5433 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5434 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5435 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5436 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
|
5437 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
|
5438 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5439 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5440 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5441 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5442 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5443 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5444 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5445 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5446 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
|
5447 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
|
5448 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5449 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5450 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5451 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5452 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5453 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5454 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5455 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5456 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5457 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5458 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5459 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5460 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5461 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
|
5462 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5463 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
|
5464 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5465 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5466 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
|
5467 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5468 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
|
5469 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5470 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5471 } |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5472 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
|
5473 && (!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
|
5474 || !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
|
5475 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5476 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5477 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5478 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5479 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
|
5480 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5481 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
|
5482 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5483 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5484 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
|
5485 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5486 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
|
5487 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5488 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5489 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5490 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5491 (!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
|
5492 || !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
|
5493 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5494 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5495 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5496 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5497 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
|
5498 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5499 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
|
5500 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5501 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5502 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
|
5503 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5504 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
|
5505 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5506 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5507 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5508 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
|
5509 (!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
|
5510 || !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
|
5511 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5512 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5513 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5514 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5515 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5516 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
|
5517 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5518 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
|
5519 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5520 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5521 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5522 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5523 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5524 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5525 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5526 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5527 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5528 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5529 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5530 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5531 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5532 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
|
5533 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5534 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5535 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
|
5536 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5537 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
|
5538 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5539 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
|
5540 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5541 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5542 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5543 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5544 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5545 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5546 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5547 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
|
5548 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5549 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5550 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5551 // 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
|
5552 // process with TerminateProcess. |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5553 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5554 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5555 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5556 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5557 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5558 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5559 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5560 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5561 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5562 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5563 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5564 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
|
5565 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5566 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5567 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5568 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5569 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5570 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5571 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
|
5572 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5573 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
|
5574 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5575 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
|
5576 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5577 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5578 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5579 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5580 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5581 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5582 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5583 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5584 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5585 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5586 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5587 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5588 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
|
5589 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5590 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5591 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5592 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5593 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5594 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5595 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5596 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5597 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
|
5598 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5599 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5600 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5601 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
|
5602 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5603 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
|
5604 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5605 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5606 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5607 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5608 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5609 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5610 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5611 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5612 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
|
5613 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5614 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5615 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5616 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5617 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5618 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5619 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5620 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5621 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5622 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5623 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
|
5624 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5625 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5626 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5627 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5628 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
|
5629 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5630 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5631 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5632 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5633 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5634 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5635 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5636 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
|
5637 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5638 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
|
5639 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5640 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
|
5641 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5642 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5643 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5644 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5645 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5646 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5647 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5648 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5649 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5650 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5651 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5652 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5653 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5654 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5655 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5656 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5657 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5658 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5659 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5660 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5661 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5662 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5663 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5664 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5665 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5666 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5667 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5668 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5669 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5670 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5671 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5672 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5673 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5674 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5675 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5676 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5677 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5678 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5679 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5680 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5681 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5682 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5683 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5684 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5685 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5686 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5687 * 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
|
5688 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5689 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5690 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
|
5691 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5692 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5693 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5694 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
|
5695 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5696 // deadly signal |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5697 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
|
5698 { |
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
|
5699 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
|
5700 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
|
5701 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
|
5702 } |
19360
16d538568dc8
patch 8.2.0238: MS-Windows: job_stop() results in exit value zero
Bram Moolenaar <Bram@vim.org>
parents:
19239
diff
changeset
|
5703 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
|
5704 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5705 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5706 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
|
5707 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5708 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5709 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
|
5710 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5711 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5712 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5713 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5714 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5715 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5716 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5717 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5718 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5719 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5720 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5721 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5722 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5723 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5724 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5725 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5726 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5727 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5728 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5729 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5730 |
7 | 5731 |
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
|
5732 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 5733 |
5734 /* | |
5735 * Start termcap mode | |
5736 */ | |
5737 static void | |
5738 termcap_mode_start(void) | |
5739 { | |
5740 DWORD cmodein; | |
5741 | |
5742 if (g_fTermcapMode) | |
5743 return; | |
5744 | |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5745 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
|
5746 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
|
5747 |
7 | 5748 SaveConsoleBuffer(&g_cbNonTermcap); |
5749 | |
5750 if (g_cbTermcap.IsValid) | |
5751 { | |
5752 /* | |
5753 * We've been in termcap mode before. Restore certain screen | |
5754 * characteristics, including the buffer size and the window | |
5755 * size. Since we will be redrawing the screen, we don't need | |
5756 * to restore the actual contents of the buffer. | |
5757 */ | |
5758 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
|
5759 reset_console_color_rgb(); |
7 | 5760 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5761 Rows = g_cbTermcap.Info.dwSize.Y; | |
5762 Columns = g_cbTermcap.Info.dwSize.X; | |
5763 } | |
5764 else | |
5765 { | |
5766 /* | |
5767 * This is our first time entering termcap mode. Clear the console | |
5768 * screen buffer, and resize the buffer to match the current window | |
5769 * size. We will use this as the size of our editing environment. | |
5770 */ | |
5771 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
|
5772 set_console_color_rgb(); |
7 | 5773 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5774 } | |
5775 | |
5776 resettitle(); | |
5777 | |
5778 GetConsoleMode(g_hConIn, &cmodein); | |
5779 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
|
5780 { |
7 | 5781 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
|
5782 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
|
5783 } |
7 | 5784 else |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5785 { |
7 | 5786 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
|
5787 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
|
5788 } |
7 | 5789 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
|
5790 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 5791 |
5792 redraw_later_clear(); | |
5793 g_fTermcapMode = TRUE; | |
5794 } | |
5795 | |
5796 | |
5797 /* | |
5798 * End termcap mode | |
5799 */ | |
5800 static void | |
5801 termcap_mode_end(void) | |
5802 { | |
5803 DWORD cmodein; | |
5804 ConsoleBuffer *cb; | |
5805 COORD coord; | |
5806 DWORD dwDummy; | |
5807 | |
5808 if (!g_fTermcapMode) | |
5809 return; | |
5810 | |
5811 SaveConsoleBuffer(&g_cbTermcap); | |
5812 | |
5813 GetConsoleMode(g_hConIn, &cmodein); | |
5814 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
|
5815 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
|
5816 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 5817 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5818 # ifdef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5819 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
|
5820 # else |
7 | 5821 cb = &g_cbNonTermcap; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5822 # 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
|
5823 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
|
5824 restore_console_color_rgb(); |
7 | 5825 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5826 | |
5827 if (p_rs || exiting) | |
5828 { | |
5829 /* | |
5830 * Clear anything that happens to be on the current line. | |
5831 */ | |
5832 coord.X = 0; | |
5833 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5834 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5835 cb->Info.dwSize.X, coord, &dwDummy); | |
5836 /* | |
5837 * The following is just for aesthetics. If we are exiting without | |
5838 * restoring the screen, then we want to have a prompt string | |
5839 * appear at the bottom line. However, the command interpreter | |
5840 * seems to always advance the cursor one line before displaying | |
5841 * the prompt string, which causes the screen to scroll. To | |
5842 * counter this, move the cursor up one line before exiting. | |
5843 */ | |
5844 if (exiting && !p_rs) | |
5845 coord.Y--; | |
5846 /* | |
5847 * Position the cursor at the leftmost column of the desired row. | |
5848 */ | |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5849 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
|
5850 } |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5851 |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5852 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
|
5853 vtp_printf("\033[?1049l"); |
a2fa2fc0f403
patch 8.2.0490: Win32: VTP doesn't respect 'restorescreen'
Bram Moolenaar <Bram@vim.org>
parents:
19789
diff
changeset
|
5854 |
7 | 5855 g_fTermcapMode = FALSE; |
5856 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5857 #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
|
5858 |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5859 |
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
|
5860 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 5861 void |
5862 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
|
5863 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
|
5864 int len UNUSED) |
7 | 5865 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5866 // never used |
7 | 5867 } |
5868 | |
5869 #else | |
5870 | |
5871 /* | |
5872 * clear `n' chars, starting from `coord' | |
5873 */ | |
5874 static void | |
5875 clear_chars( | |
5876 COORD coord, | |
5877 DWORD n) | |
5878 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5879 if (!USE_VTP) |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5880 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5881 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
|
5882 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5883 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
|
5884 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
|
5885 &dwDummy); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5886 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5887 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
|
5888 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5889 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
|
5890 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
|
5891 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
|
5892 } |
7 | 5893 } |
5894 | |
5895 | |
5896 /* | |
5897 * Clear the screen | |
5898 */ | |
5899 static void | |
5900 clear_screen(void) | |
5901 { | |
5902 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
|
5903 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5904 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
|
5905 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
|
5906 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5907 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5908 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
|
5909 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
|
5910 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
|
5911 } |
7 | 5912 } |
5913 | |
5914 | |
5915 /* | |
5916 * Clear to end of display | |
5917 */ | |
5918 static void | |
5919 clear_to_end_of_display(void) | |
5920 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5921 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
|
5922 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5923 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
|
5924 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5925 * 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
|
5926 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5927 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5928 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
|
5929 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
|
5930 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
|
5931 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5932 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
|
5933 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
|
5934 } |
7 | 5935 } |
5936 | |
5937 | |
5938 /* | |
5939 * Clear to end of line | |
5940 */ | |
5941 static void | |
5942 clear_to_end_of_line(void) | |
5943 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5944 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
|
5945 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5946 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
|
5947 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
|
5948 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5949 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5950 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
|
5951 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
|
5952 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
|
5953 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5954 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
|
5955 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
|
5956 } |
7 | 5957 } |
5958 | |
5959 | |
5960 /* | |
5961 * Scroll the scroll region up by `cLines' lines | |
5962 */ | |
5963 static void | |
26 | 5964 scroll(unsigned cLines) |
7 | 5965 { |
5966 COORD oldcoord = g_coord; | |
5967 | |
5968 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5969 delete_lines(cLines); | |
5970 | |
5971 g_coord = oldcoord; | |
5972 } | |
5973 | |
5974 | |
5975 /* | |
5976 * Set the scroll region | |
5977 */ | |
5978 static void | |
5979 set_scroll_region( | |
5980 unsigned left, | |
5981 unsigned top, | |
5982 unsigned right, | |
5983 unsigned bottom) | |
5984 { | |
5985 if (left >= right | |
5986 || top >= bottom | |
5987 || right > (unsigned) Columns - 1 | |
5988 || bottom > (unsigned) Rows - 1) | |
5989 return; | |
5990 | |
5991 g_srScrollRegion.Left = left; | |
5992 g_srScrollRegion.Top = top; | |
5993 g_srScrollRegion.Right = right; | |
5994 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
|
5995 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5996 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5997 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
|
5998 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
|
5999 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
|
6000 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
|
6001 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6002 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
|
6003 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6004 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6005 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
|
6006 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
|
6007 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6008 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6009 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
|
6010 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
|
6011 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
|
6012 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
|
6013 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6014 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
|
6015 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6016 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6017 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
|
6018 g_srScrollRegion.Right = right; |
7 | 6019 } |
6020 | |
6021 | |
6022 /* | |
6023 * Insert `cLines' lines at the current cursor position | |
6024 */ | |
6025 static void | |
26 | 6026 insert_lines(unsigned cLines) |
7 | 6027 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6028 SMALL_RECT source, clip; |
7 | 6029 COORD dest; |
6030 CHAR_INFO fill; | |
6031 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6032 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
|
6033 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6034 dest.X = g_srScrollRegion.Left; |
7 | 6035 dest.Y = g_coord.Y + cLines; |
6036 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6037 source.Left = g_srScrollRegion.Left; |
7 | 6038 source.Top = g_coord.Y; |
6039 source.Right = g_srScrollRegion.Right; | |
6040 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
6041 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6042 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
|
6043 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
|
6044 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
|
6045 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
|
6046 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6047 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
|
6048 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
|
6049 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
|
6050 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6051 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
|
6052 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6053 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
|
6054 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6055 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
|
6056 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6057 // 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
|
6058 // 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
|
6059 // 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
|
6060 // 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
|
6061 // 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
|
6062 // direction). |
7 | 6063 |
6064 if (source.Bottom < dest.Y) | |
6065 { | |
6066 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
|
6067 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
|
6068 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6069 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
|
6070 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
|
6071 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6072 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
|
6073 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
|
6074 } |
7 | 6075 } |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6076 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6077 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
|
6078 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6079 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
|
6080 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
|
6081 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6082 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
|
6083 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
|
6084 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6085 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
|
6086 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
|
6087 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6088 } |
7 | 6089 } |
6090 | |
6091 | |
6092 /* | |
6093 * Delete `cLines' lines at the current cursor position | |
6094 */ | |
6095 static void | |
26 | 6096 delete_lines(unsigned cLines) |
7 | 6097 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6098 SMALL_RECT source, clip; |
7 | 6099 COORD dest; |
6100 CHAR_INFO fill; | |
6101 int nb; | |
6102 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6103 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
|
6104 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6105 dest.X = g_srScrollRegion.Left; |
7 | 6106 dest.Y = g_coord.Y; |
6107 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6108 source.Left = g_srScrollRegion.Left; |
7 | 6109 source.Top = g_coord.Y + cLines; |
6110 source.Right = g_srScrollRegion.Right; | |
6111 source.Bottom = g_srScrollRegion.Bottom; | |
6112 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6113 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
|
6114 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
|
6115 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
|
6116 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
|
6117 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6118 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
|
6119 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
|
6120 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
|
6121 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6122 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
|
6123 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6124 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
|
6125 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
6126 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
|
6127 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6128 // 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
|
6129 // above. |
7 | 6130 |
6131 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
6132 | |
6133 if (nb < source.Top) | |
6134 { | |
6135 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
|
6136 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
|
6137 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6138 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
|
6139 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
|
6140 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6141 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
|
6142 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
|
6143 } |
7 | 6144 } |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6145 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6146 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
|
6147 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6148 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
|
6149 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
|
6150 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6151 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
|
6152 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
|
6153 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6154 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
|
6155 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
|
6156 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
6157 } |
7 | 6158 } |
6159 | |
6160 | |
6161 /* | |
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
|
6162 * Set the cursor position to (x,y) (1-based). |
7 | 6163 */ |
6164 static void | |
6165 gotoxy( | |
6166 unsigned x, | |
6167 unsigned y) | |
6168 { | |
6169 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
6170 return; | |
6171 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6172 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
|
6173 { |
19789
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6174 // 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
|
6175 // 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
|
6176 // for VTP. |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6177 g_coord.X = 0; |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6178 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
|
6179 |
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
|
6180 // 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
|
6181 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
|
6182 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
|
6183 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
|
6184 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6185 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
|
6186 { |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
6187 // 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
|
6188 // 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
|
6189 // 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
|
6190 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
|
6191 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6192 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
|
6193 |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
6194 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
|
6195 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
|
6196 } |
7 | 6197 } |
6198 | |
6199 | |
6200 /* | |
6201 * 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
|
6202 * See ../runtime/doc/os_win32.txt for the numbers. |
7 | 6203 */ |
6204 static void | |
26 | 6205 textattr(WORD wAttr) |
7 | 6206 { |
6710 | 6207 g_attrCurrent = wAttr & 0xff; |
7 | 6208 |
6209 SetConsoleTextAttribute(g_hConOut, wAttr); | |
6210 } | |
6211 | |
6212 | |
6213 static void | |
26 | 6214 textcolor(WORD wAttr) |
7 | 6215 { |
6710 | 6216 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 6217 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6218 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
|
6219 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
|
6220 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6221 vtp_sgr_bulk(wAttr); |
7 | 6222 } |
6223 | |
6224 | |
6225 static void | |
26 | 6226 textbackground(WORD wAttr) |
7 | 6227 { |
6710 | 6228 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 6229 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6230 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
|
6231 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
|
6232 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6233 vtp_sgr_bulk(wAttr); |
7 | 6234 } |
6235 | |
6236 | |
6237 /* | |
6238 * restore the default text attribute (whatever we started with) | |
6239 */ | |
6240 static void | |
26 | 6241 normvideo(void) |
7 | 6242 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6243 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
|
6244 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
|
6245 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6246 vtp_sgr_bulk(0); |
7 | 6247 } |
6248 | |
6249 | |
6250 static WORD g_attrPreStandout = 0; | |
6251 | |
6252 /* | |
6253 * Make the text standout, by brightening it | |
6254 */ | |
6255 static void | |
6256 standout(void) | |
6257 { | |
6258 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
|
6259 |
7 | 6260 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
6261 } | |
6262 | |
6263 | |
6264 /* | |
6265 * Turn off standout mode | |
6266 */ | |
6267 static void | |
26 | 6268 standend(void) |
7 | 6269 { |
6270 if (g_attrPreStandout) | |
6271 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
|
6272 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6273 g_attrPreStandout = 0; |
7 | 6274 } |
6275 | |
6276 | |
6277 /* | |
1199 | 6278 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 6279 */ |
6280 void | |
26 | 6281 mch_set_normal_colors(void) |
7 | 6282 { |
6283 char_u *p; | |
6284 int n; | |
6285 | |
6286 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
6287 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
|
6288 if ( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6289 # 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
|
6290 !p_tgc && |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6291 # 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
|
6292 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 6293 { |
6294 p = T_ME + 2; | |
6295 n = getdigits(&p); | |
6296 if (*p == 'm' && n > 0) | |
6297 { | |
6298 cterm_normal_fg_color = (n & 0xf) + 1; | |
6299 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
6300 } | |
6301 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6302 # 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
|
6303 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
|
6304 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
|
6305 # endif |
7 | 6306 } |
6307 | |
6308 | |
6309 /* | |
6310 * visual bell: flash the screen | |
6311 */ | |
6312 static void | |
26 | 6313 visual_bell(void) |
7 | 6314 { |
6315 COORD coordOrigin = {0, 0}; | |
6316 WORD attrFlash = ~g_attrCurrent & 0xff; | |
6317 | |
6318 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
|
6319 LPWORD oldattrs = ALLOC_MULT(WORD, Rows * Columns); |
7 | 6320 |
6321 if (oldattrs == NULL) | |
6322 return; | |
6323 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
6324 coordOrigin, &dwDummy); | |
6325 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
6326 coordOrigin, &dwDummy); | |
6327 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6328 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
|
6329 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
|
6330 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 6331 coordOrigin, &dwDummy); |
6332 vim_free(oldattrs); | |
6333 } | |
6334 | |
6335 | |
6336 /* | |
6337 * Make the cursor visible or invisible | |
6338 */ | |
6339 static void | |
26 | 6340 cursor_visible(BOOL fVisible) |
7 | 6341 { |
6342 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
|
6343 |
a2124c6d5e6e
patch 8.2.0592: MS-Windows with VTP: cursor is not made invisible
Bram Moolenaar <Bram@vim.org>
parents:
20051
diff
changeset
|
6344 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
|
6345 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
|
6346 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6347 # ifdef MCH_CURSOR_SHAPE |
7 | 6348 mch_update_cursor(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6349 # endif |
7 | 6350 } |
6351 | |
6352 | |
6353 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6354 * 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
|
6355 * Returns the number of bytes actually written (at least one). |
7 | 6356 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6357 static DWORD |
7 | 6358 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6359 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6360 DWORD cbToWrite) |
7 | 6361 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6362 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
|
6363 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
|
6364 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
|
6365 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
|
6366 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
|
6367 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
|
6368 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
|
6369 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
|
6370 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
|
6371 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
|
6372 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
|
6373 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
|
6374 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6375 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
|
6376 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6377 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
|
6378 do |
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 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
|
6381 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
|
6382 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
|
6383 break; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6384 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
|
6385 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
|
6386 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
|
6387 } 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
|
6388 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
|
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 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
|
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 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
|
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 (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
|
6395 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6396 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
|
6397 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
|
6398 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
|
6399 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
|
6400 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6401 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
|
6402 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
|
6403 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
|
6404 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
|
6405 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6406 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6407 else |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6408 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6409 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
|
6410 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
|
6411 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
|
6412 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6413 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6414 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6415 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6416 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
|
6417 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6418 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
|
6419 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
|
6420 // 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
|
6421 // 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
|
6422 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
|
6423 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
|
6424 || 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
|
6425 cchwritten = 1; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6426 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6427 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6428 { |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6429 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
|
6430 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
|
6431 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
|
6432 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6433 |
27455
6045bf58926d
patch 8.2.4256: MS-Windows: compiler warnings when compiled with /W4
Bram Moolenaar <Bram@vim.org>
parents:
27370
diff
changeset
|
6434 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
|
6435 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6436 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
|
6437 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
|
6438 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6439 else |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6440 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6441 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
|
6442 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
|
6443 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
|
6444 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
|
6445 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
|
6446 } |
7 | 6447 |
6448 while (g_coord.X > g_srScrollRegion.Right) | |
6449 { | |
6450 g_coord.X -= (SHORT) Columns; | |
6451 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6452 g_coord.Y++; | |
6453 } | |
6454 | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6455 // 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
|
6456 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
|
6457 gotoxy(g_coord.X + 1, g_coord.Y + 1); |
7 | 6458 |
6459 return written; | |
6460 } | |
6461 | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6462 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
|
6463 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
|
6464 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
|
6465 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
|
6466 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
|
6467 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6468 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
|
6469 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
|
6470 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6471 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
|
6472 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
|
6473 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6474 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
|
6475 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
|
6476 ++p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6477 do |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6478 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6479 ++p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6480 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
|
6481 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
|
6482 } 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
|
6483 *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
|
6484 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6485 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
|
6486 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6487 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6488 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
|
6489 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
|
6490 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
|
6491 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
|
6492 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
|
6493 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6494 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
|
6495 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6496 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
|
6497 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6498 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6499 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6500 * 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
|
6501 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6502 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
|
6503 sgrn2( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6504 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
|
6505 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
|
6506 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6507 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
|
6508 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
|
6509 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
|
6510 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6511 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
|
6512 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6513 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6514 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6515 * 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
|
6516 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6517 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
|
6518 sgrnc( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6519 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
|
6520 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
|
6521 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6522 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
|
6523 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
|
6524 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
|
6525 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6526 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
|
6527 ? 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
|
6528 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6529 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6530 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
|
6531 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
|
6532 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6533 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
|
6534 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6535 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
|
6536 ++p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6537 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
|
6538 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6539 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6540 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6541 * 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
|
6542 * NULL. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6543 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6544 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
|
6545 sgrn2c( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6546 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
|
6547 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
|
6548 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6549 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
|
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 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
|
6552 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6553 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6554 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6555 * 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
|
6556 * 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
|
6557 * 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
|
6558 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6559 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
|
6560 sgrn2cn( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6561 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
|
6562 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
|
6563 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6564 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
|
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 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
|
6567 } |
7 | 6568 |
6569 /* | |
6570 * mch_write(): write the output buffer to the screen, translating ESC | |
6571 * sequences into calls to console output routines. | |
6572 */ | |
6573 void | |
6574 mch_write( | |
6575 char_u *s, | |
6576 int len) | |
6577 { | |
24506
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6578 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
|
6579 |
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
|
6580 # 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
|
6581 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
|
6582 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
|
6583 # 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
|
6584 |
7 | 6585 if (!term_console) |
6586 { | |
6587 write(1, s, (unsigned)len); | |
6588 return; | |
6589 } | |
6590 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6591 // translate ESC | sequences into faked bios calls |
7 | 6592 while (len--) |
6593 { | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6594 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
|
6595 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
|
6596 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6597 // 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
|
6598 // 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
|
6599 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
|
6600 { |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29245
diff
changeset
|
6601 redraw_all_later(UPD_CLEAR); |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6602 return; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6603 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6604 |
24506
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6605 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
|
6606 { |
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6607 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
|
6608 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
|
6609 && 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
|
6610 break; |
24506
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6611 } |
7 | 6612 |
6613 if (p_wd) | |
6614 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6615 WaitForChar(p_wd, FALSE); |
7 | 6616 if (prefix != 0) |
6617 prefix = 1; | |
6618 } | |
6619 | |
6620 if (prefix != 0) | |
6621 { | |
6622 DWORD nWritten; | |
6623 | |
6624 nWritten = write_chars(s, prefix); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6625 # ifdef MCH_WRITE_DUMP |
7 | 6626 if (fdDump) |
6627 { | |
6628 fputc('>', fdDump); | |
6629 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6630 fputs("<\n", fdDump); | |
6631 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6632 # endif |
7 | 6633 len -= (nWritten - 1); |
6634 s += nWritten; | |
6635 } | |
6636 else if (s[0] == '\n') | |
6637 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6638 // \n, newline: go to the beginning of the next line or scroll |
7 | 6639 if (g_coord.Y == g_srScrollRegion.Bottom) |
6640 { | |
6641 scroll(1); | |
6642 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6643 } | |
6644 else | |
6645 { | |
6646 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6647 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6648 # ifdef MCH_WRITE_DUMP |
7 | 6649 if (fdDump) |
6650 fputs("\\n\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6651 # endif |
7 | 6652 s++; |
6653 } | |
6654 else if (s[0] == '\r') | |
6655 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6656 // \r, carriage return: go to beginning of line |
7 | 6657 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
|
6658 # ifdef MCH_WRITE_DUMP |
7 | 6659 if (fdDump) |
6660 fputs("\\r\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6661 # endif |
7 | 6662 s++; |
6663 } | |
6664 else if (s[0] == '\b') | |
6665 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6666 // \b, backspace: move cursor one position left |
7 | 6667 if (g_coord.X > g_srScrollRegion.Left) |
6668 g_coord.X--; | |
6669 else if (g_coord.Y > g_srScrollRegion.Top) | |
6670 { | |
6671 g_coord.X = g_srScrollRegion.Right; | |
6672 g_coord.Y--; | |
6673 } | |
6674 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
|
6675 # ifdef MCH_WRITE_DUMP |
7 | 6676 if (fdDump) |
6677 fputs("\\b\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6678 # endif |
7 | 6679 s++; |
6680 } | |
6681 else if (s[0] == '\a') | |
6682 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6683 // \a, bell |
7 | 6684 MessageBeep(0xFFFFFFFF); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6685 # ifdef MCH_WRITE_DUMP |
7 | 6686 if (fdDump) |
6687 fputs("\\a\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6688 # endif |
7 | 6689 s++; |
6690 } | |
6691 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6692 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6693 # ifdef MCH_WRITE_DUMP |
24 | 6694 char_u *old_s = s; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6695 # endif |
24 | 6696 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
|
6697 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
|
6698 char_u *sp; |
7 | 6699 |
6700 switch (s[2]) | |
6701 { | |
6702 case '0': case '1': case '2': case '3': case '4': | |
6703 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
|
6704 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
|
6705 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
|
6706 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6707 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
|
6708 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6709 // 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
|
6710 // 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
|
6711 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6712 // 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
|
6713 // 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
|
6714 if (sgrn2(sgrn2(sgrn2cn(sgrn2(sgrnc(p, 39), 38), 48), 48), 38)) |
7 | 6715 { |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6716 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
|
6717 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
|
6718 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
|
6719 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
|
6720 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6721 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6722 // 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
|
6723 // omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6724 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
|
6725 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
|
6726 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6727 // 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
|
6728 // omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6729 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
|
6730 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
|
6731 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6732 // 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
|
6733 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
|
6734 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
|
6735 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6736 // If restoreFG and FG are connected, the restoreFG can be |
28844
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
6737 // omitted. |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6738 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
|
6739 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
|
6740 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6741 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
|
6742 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6743 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
|
6744 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
|
6745 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
|
6746 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
|
6747 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6748 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
|
6749 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6750 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
|
6751 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6752 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
|
6753 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
|
6754 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6755 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
|
6756 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6757 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
|
6758 vtp_sgr_bulks(argc, args); |
7 | 6759 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6760 else if (argc == 2 && *p == 'H') |
7 | 6761 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6762 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
|
6763 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6764 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
|
6765 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6766 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
|
6767 } |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6768 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
|
6769 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6770 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
|
6771 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6772 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
|
6773 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6774 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
|
6775 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6776 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
|
6777 { |
7 | 6778 gotoxy(g_coord.X + 1, |
6779 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6780 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6781 else if (argc == 1 && *p == 'b') |
7 | 6782 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6783 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
|
6784 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6785 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
|
6786 { |
7 | 6787 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6788 g_coord.Y + 1); | |
6789 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6790 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
|
6791 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6792 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
|
6793 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6794 else if (argc == 1 && *p == 'H') |
7 | 6795 { |
6796 gotoxy(1, arg1); | |
6797 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6798 else if (argc == 1 && *p == 'L') |
7 | 6799 { |
6800 insert_lines(arg1); | |
6801 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6802 else if (argc == 1 && *p == 'M') |
7 | 6803 { |
6804 delete_lines(arg1); | |
6805 } | |
6806 | |
835 | 6807 len -= (int)(p - s); |
7 | 6808 s = p + 1; |
6809 break; | |
6810 | |
6811 case 'A': | |
6812 gotoxy(g_coord.X + 1, | |
6813 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6814 goto got3; | |
6815 | |
6816 case 'B': | |
6817 visual_bell(); | |
6818 goto got3; | |
6819 | |
6820 case 'C': | |
6821 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6822 g_coord.Y + 1); | |
6823 goto got3; | |
6824 | |
6825 case 'E': | |
6826 termcap_mode_end(); | |
6827 goto got3; | |
6828 | |
6829 case 'F': | |
6830 standout(); | |
6831 goto got3; | |
6832 | |
6833 case 'f': | |
6834 standend(); | |
6835 goto got3; | |
6836 | |
6837 case 'H': | |
6838 gotoxy(1, 1); | |
6839 goto got3; | |
6840 | |
6841 case 'j': | |
6842 clear_to_end_of_display(); | |
6843 goto got3; | |
6844 | |
6845 case 'J': | |
6846 clear_screen(); | |
6847 goto got3; | |
6848 | |
6849 case 'K': | |
6850 clear_to_end_of_line(); | |
6851 goto got3; | |
6852 | |
6853 case 'L': | |
6854 insert_lines(1); | |
6855 goto got3; | |
6856 | |
6857 case 'M': | |
6858 delete_lines(1); | |
6859 goto got3; | |
6860 | |
6861 case 'S': | |
6862 termcap_mode_start(); | |
6863 goto got3; | |
6864 | |
6865 case 'V': | |
6866 cursor_visible(TRUE); | |
6867 goto got3; | |
6868 | |
6869 case 'v': | |
6870 cursor_visible(FALSE); | |
6871 goto got3; | |
6872 | |
6873 got3: | |
6874 s += 3; | |
6875 len -= 2; | |
6876 } | |
6877 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6878 # ifdef MCH_WRITE_DUMP |
7 | 6879 if (fdDump) |
6880 { | |
6881 fputs("ESC | ", fdDump); | |
6882 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6883 fputc('\n', fdDump); | |
6884 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6885 # endif |
7 | 6886 } |
30019
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6887 else if (s[0] == ESC && len >= 3-1 && s[1] == '[') |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6888 { |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6889 int l = 2; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6890 |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6891 if (isdigit(s[l])) |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6892 l++; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6893 if (s[l] == ' ' && s[l + 1] == 'q') |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6894 { |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6895 // DECSCUSR (cursor style) sequences |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6896 if (USE_VTP || USE_WT) |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6897 vtp_printf("%.*s", l + 2, s); // Pass through |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6898 s += l + 2; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6899 len -= l + 1; |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6900 } |
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
6901 } |
7 | 6902 else |
6903 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6904 // Write a single character |
7 | 6905 DWORD nWritten; |
6906 | |
6907 nWritten = write_chars(s, 1); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6908 # ifdef MCH_WRITE_DUMP |
7 | 6909 if (fdDump) |
6910 { | |
6911 fputc('>', fdDump); | |
6912 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6913 fputs("<\n", fdDump); | |
6914 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6915 # endif |
7 | 6916 |
6917 len -= (nWritten - 1); | |
6918 s += nWritten; | |
6919 } | |
6920 } | |
6921 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6922 # ifdef MCH_WRITE_DUMP |
7 | 6923 if (fdDump) |
6924 fflush(fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6925 # endif |
7 | 6926 } |
6927 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6928 #endif // FEAT_GUI_MSWIN |
7 | 6929 |
6930 | |
6931 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6932 * Delay for "msec" milliseconds. |
7 | 6933 */ |
6934 void | |
6935 mch_delay( | |
6936 long msec, | |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
6937 int flags UNUSED) |
7 | 6938 { |
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
|
6939 #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
|
6940 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
|
6941 #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
|
6942 # 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
|
6943 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
|
6944 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6945 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
|
6946 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
|
6947 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6948 # endif |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
6949 if (flags & MCH_DELAY_IGNOREINPUT) |
14 | 6950 # ifdef FEAT_MZSCHEME |
6951 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6952 { | |
6953 int towait = p_mzq; | |
6954 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6955 // if msec is large enough, wait by portions in p_mzq |
14 | 6956 while (msec > 0) |
6957 { | |
6958 mzvim_check_threads(); | |
6959 if (msec < towait) | |
6960 towait = msec; | |
6961 Sleep(towait); | |
6962 msec -= towait; | |
6963 } | |
6964 } | |
6965 else | |
6966 # endif | |
6967 Sleep((int)msec); | |
7 | 6968 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6969 WaitForChar(msec, FALSE); |
7 | 6970 #endif |
6971 } | |
6972 | |
6973 | |
6974 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6975 * 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
|
6976 * This can also remove a symbolic link like Unix. |
7 | 6977 * Return 0 for success, -1 for failure. |
6978 */ | |
6979 int | |
6980 mch_remove(char_u *name) | |
6981 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6982 WCHAR *wn; |
7 | 6983 int n; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6984 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6985 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6986 * 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
|
6987 * 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
|
6988 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6989 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
|
6990 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6991 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6992 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6993 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6994 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
|
6995 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
|
6996 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
|
6997 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6998 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
|
6999 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
|
7000 return n; |
7 | 7001 } |
7002 | |
7003 | |
7004 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
7005 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 7006 */ |
7007 void | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
7008 mch_breakcheck(int force UNUSED) |
7 | 7009 { |
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
|
7010 #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
|
7011 # 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
|
7012 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
|
7013 # 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
|
7014 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
|
7015 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7016 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
|
7017 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
|
7018 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
|
7019 } |
7 | 7020 #endif |
7021 } | |
7022 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7023 // 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
|
7024 #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
|
7025 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
7026 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
7027 * 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
|
7028 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
7029 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
|
7030 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
|
7031 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7032 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7033 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7034 // 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
|
7035 // what fits in 32 bits. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7036 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7037 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7038 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
7039 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7040 // 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
|
7041 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
|
7042 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7043 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
|
7044 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7045 // 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
|
7046 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
|
7047 } |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7048 // 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
|
7049 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
|
7050 } |
7 | 7051 |
7052 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7053 * mch_wrename() works around a bug in rename (aka MoveFile) in |
7 | 7054 * Windows 95: rename("foo.bar", "foo.bar~") will generate a |
7055 * file whose short file name is "FOO.BAR" (its long file name will | |
7056 * be correct: "foo.bar~"). Because a file can be accessed by | |
7057 * either its SFN or its LFN, "foo.bar" has effectively been | |
7058 * renamed to "foo.bar", which is not at all what was wanted. This | |
7059 * seems to happen only when renaming files with three-character | |
7060 * extensions by appending a suffix that does not include ".". | |
7061 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
7062 * | |
7063 * There is another problem, which isn't really a bug but isn't right either: | |
7064 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
7065 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
7066 * service pack 6. Doesn't seem to happen on Windows 98. | |
7067 * | |
7068 * Like rename(), returns 0 upon success, non-zero upon failure. | |
7069 * Should probably set errno appropriately when errors occur. | |
7070 */ | |
7071 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
|
7072 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
|
7073 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7074 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
|
7075 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
|
7076 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
|
7077 WCHAR szNewPath[_MAX_PATH + 1]; |
7 | 7078 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
|
7079 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7080 // 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
|
7081 // 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
|
7082 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
|
7083 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
|
7084 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
|
7085 && 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
|
7086 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
|
7087 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
|
7088 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
|
7089 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7090 // 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
|
7091 // 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
|
7092 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) |
7 | 7093 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
|
7094 *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
|
7095 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7096 // 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
|
7097 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) |
7 | 7098 return -2; |
7099 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7100 // 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
|
7101 if (!DeleteFileW(szTempFile)) |
7 | 7102 return -3; |
7103 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7104 // 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
|
7105 if (!MoveFileW(wold, szTempFile)) |
7 | 7106 return -4; |
7107 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7108 // 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
|
7109 // 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
|
7110 // 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
|
7111 // 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
|
7112 // 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
|
7113 // 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
|
7114 // 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
|
7115 // 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
|
7116 // 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
|
7117 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, |
7 | 7118 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) |
7119 return -5; | |
7120 if (!CloseHandle(hf)) | |
7121 return -6; | |
7122 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7123 // 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
|
7124 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
|
7125 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7126 // 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
|
7127 // 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
|
7128 (void)MoveFileW(szTempFile, wold); |
7 | 7129 return -7; |
7130 } | |
7131 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7132 // 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
|
7133 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
|
7134 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7135 // 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
|
7136 if (!DeleteFileW(wold)) |
7 | 7137 return -8; |
7138 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7139 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
|
7140 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7141 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7142 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7143 /* |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7144 * 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
|
7145 * 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
|
7146 */ |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7147 int |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7148 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
|
7149 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
|
7150 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
|
7151 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7152 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
|
7153 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
|
7154 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
|
7155 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7156 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
|
7157 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
|
7158 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
|
7159 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
|
7160 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
|
7161 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
|
7162 return retval; |
7 | 7163 } |
7164 | |
7165 /* | |
7166 * Get the default shell for the current hardware platform | |
7167 */ | |
7168 char * | |
26 | 7169 default_shell(void) |
7 | 7170 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7171 return "cmd.exe"; |
7 | 7172 } |
7173 | |
7174 /* | |
7175 * mch_access() extends access() to do more detailed check on network drives. | |
7176 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
7177 */ | |
7178 int | |
7179 mch_access(char *n, int p) | |
7180 { | |
7181 HANDLE hFile; | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7182 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
|
7183 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
|
7184 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7185 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
|
7186 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
|
7187 return -1; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7188 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7189 if (mch_isdir((char_u *)n)) |
7 | 7190 { |
7191 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
7192 | |
7193 if (p & R_OK) | |
7194 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7195 // 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
|
7196 // 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
|
7197 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
|
7198 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
|
7199 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7200 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
|
7201 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
|
7202 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
|
7203 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
|
7204 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
|
7205 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
|
7206 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7207 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
|
7208 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
|
7209 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7210 else |
7 | 7211 (void)FindClose(hFile); |
7212 } | |
7213 | |
7214 if (p & W_OK) | |
7215 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7216 // 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
|
7217 // 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
|
7218 // 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
|
7219 // 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
|
7220 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
|
7221 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7222 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
|
7223 DeleteFileW(TempNameW); |
7 | 7224 } |
7225 } | |
7226 else | |
7227 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7228 // 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
|
7229 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
|
7230 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7231 // 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
|
7232 // 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
|
7233 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
|
7234 | ((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
|
7235 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7236 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
|
7237 NULL, OPEN_EXISTING, 0, NULL); |
7 | 7238 if (hFile == INVALID_HANDLE_VALUE) |
7239 goto getout; | |
7240 CloseHandle(hFile); | |
7241 } | |
7242 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7243 retval = 0; // success |
7 | 7244 getout: |
7245 vim_free(wn); | |
7246 return retval; | |
7247 } | |
7248 | |
7249 /* | |
1752 | 7250 * Version of open() that may use UTF-16 file name. |
7 | 7251 */ |
7252 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7253 mch_open(const char *name, int flags, int mode) |
7 | 7254 { |
7255 WCHAR *wn; | |
7256 int f; | |
7257 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7258 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
|
7259 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
|
7260 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
|
7261 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7262 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
|
7263 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
|
7264 return f; |
7 | 7265 } |
7266 | |
7267 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7268 * Version of fopen() that uses UTF-16 file name. |
7 | 7269 */ |
7270 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7271 mch_fopen(const char *name, const char *mode) |
7 | 7272 { |
7273 WCHAR *wn, *wm; | |
7274 FILE *f = NULL; | |
7275 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7276 #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
|
7277 // 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
|
7278 // 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
|
7279 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
|
7280 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
|
7281 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7282 _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
|
7283 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
|
7284 _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
|
7285 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
|
7286 _set_fmode(_O_BINARY); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7287 #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
|
7288 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
|
7289 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
|
7290 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
|
7291 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
|
7292 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
|
7293 vim_free(wm); |
1569 | 7294 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7295 #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
|
7296 _set_fmode(oldMode); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7297 #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
|
7298 return f; |
7 | 7299 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7300 |
7 | 7301 /* |
7302 * SUB STREAM (aka info stream) handling: | |
7303 * | |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7304 * 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
|
7305 * 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
|
7306 * 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
|
7307 * 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
|
7308 * 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
|
7309 * when copying only the main stream. Therefore we have to copy sub streams. |
7 | 7310 * |
7311 * Incomplete explanation: | |
7312 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
7313 * More useful info and an example: | |
7314 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
7315 */ | |
7316 | |
7317 /* | |
7318 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
7319 * and write to stream "substream" of file "to". | |
7320 * Errors are ignored. | |
7321 */ | |
7322 static void | |
7323 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
7324 { | |
7325 HANDLE hTo; | |
7326 WCHAR *to_name; | |
7327 | |
7328 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
7329 wcscpy(to_name, to); | |
7330 wcscat(to_name, substream); | |
7331 | |
7332 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
7333 FILE_ATTRIBUTE_NORMAL, NULL); | |
7334 if (hTo != INVALID_HANDLE_VALUE) | |
7335 { | |
7336 long done; | |
7337 DWORD todo; | |
7338 DWORD readcnt, written; | |
7339 char buf[4096]; | |
7340 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7341 // Copy block of bytes at a time. Abort when something goes wrong. |
7 | 7342 for (done = 0; done < len; done += written) |
7343 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7344 // (size_t) cast for Borland C 5.5 |
835 | 7345 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
7346 : (size_t)(len - done)); | |
7 | 7347 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
7348 FALSE, FALSE, context) | |
7349 || readcnt != todo | |
7350 || !WriteFile(hTo, buf, todo, &written, NULL) | |
7351 || written != todo) | |
7352 break; | |
7353 } | |
7354 CloseHandle(hTo); | |
7355 } | |
7356 | |
7357 free(to_name); | |
7358 } | |
7359 | |
7360 /* | |
7361 * Copy info streams from file "from" to file "to". | |
7362 */ | |
7363 static void | |
7364 copy_infostreams(char_u *from, char_u *to) | |
7365 { | |
7366 WCHAR *fromw; | |
7367 WCHAR *tow; | |
7368 HANDLE sh; | |
7369 WIN32_STREAM_ID sid; | |
7370 int headersize; | |
7371 WCHAR streamname[_MAX_PATH]; | |
7372 DWORD readcount; | |
7373 void *context = NULL; | |
7374 DWORD lo, hi; | |
7375 int len; | |
7376 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7377 // Convert the file names to wide characters. |
1752 | 7378 fromw = enc_to_utf16(from, NULL); |
7379 tow = enc_to_utf16(to, NULL); | |
7 | 7380 if (fromw != NULL && tow != NULL) |
7381 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7382 // Open the file for reading. |
7 | 7383 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, |
7384 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
7385 if (sh != INVALID_HANDLE_VALUE) | |
7386 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7387 // 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
|
7388 // have done them all. |
7 | 7389 for (;;) |
7390 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7391 // 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
|
7392 // the "readcount" is zero we have done all info streams. |
7 | 7393 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); |
835 | 7394 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 7395 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
7396 &readcount, FALSE, FALSE, &context) | |
7397 || readcount == 0) | |
7398 break; | |
7399 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7400 // 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
|
7401 // 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
|
7402 // suggest it is called "::$DATA". |
7 | 7403 if (sid.dwStreamNameSize > 0) |
7404 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7405 // Read the stream name. |
7 | 7406 if (!BackupRead(sh, (LPBYTE)streamname, |
7407 sid.dwStreamNameSize, | |
7408 &readcount, FALSE, FALSE, &context)) | |
7409 break; | |
7410 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7411 // 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
|
7412 // 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
|
7413 // 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
|
7414 // 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
|
7415 // wide characters. |
7 | 7416 len = readcount / sizeof(WCHAR); |
7417 streamname[len] = 0; | |
7418 if (len > 7 && wcsicmp(streamname + len - 6, | |
7419 L":$DATA") == 0) | |
7420 { | |
7421 streamname[len - 6] = 0; | |
7422 copy_substream(sh, &context, tow, streamname, | |
10 | 7423 (long)sid.Size.u.LowPart); |
7 | 7424 } |
7425 } | |
7426 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7427 // 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
|
7428 // 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
|
7429 // that's OK. |
323 | 7430 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 7431 &lo, &hi, &context); |
7432 } | |
7433 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7434 // Clear the context. |
7 | 7435 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); |
7436 | |
7437 CloseHandle(sh); | |
7438 } | |
7439 } | |
7440 vim_free(fromw); | |
7441 vim_free(tow); | |
7442 } | |
7443 | |
7444 /* | |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7445 * ntdll.dll definitions |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7446 */ |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7447 #define FileEaInformation 7 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7448 #ifndef STATUS_SUCCESS |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7449 # 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
|
7450 #endif |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7451 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7452 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
|
7453 ULONG NextEntryOffset; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7454 UCHAR Flags; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7455 UCHAR EaNameLength; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7456 USHORT EaValueLength; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7457 CHAR EaName[1]; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7458 } 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
|
7459 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7460 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
|
7461 ULONG EaSize; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7462 } 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
|
7463 |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
7464 #ifndef PROTO |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7465 typedef NTSTATUS (NTAPI *PfnNtOpenFile)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7466 PHANDLE FileHandle, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7467 ACCESS_MASK DesiredAccess, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7468 POBJECT_ATTRIBUTES ObjectAttributes, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7469 PIO_STATUS_BLOCK IoStatusBlock, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7470 ULONG ShareAccess, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7471 ULONG OpenOptions); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7472 typedef NTSTATUS (NTAPI *PfnNtClose)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7473 HANDLE Handle); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7474 typedef NTSTATUS (NTAPI *PfnNtSetEaFile)( |
28844
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7475 HANDLE FileHandle, |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7476 PIO_STATUS_BLOCK IoStatusBlock, |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7477 PVOID Buffer, |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7478 ULONG Length); |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7479 typedef NTSTATUS (NTAPI *PfnNtQueryEaFile)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7480 HANDLE FileHandle, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7481 PIO_STATUS_BLOCK IoStatusBlock, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7482 PVOID Buffer, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7483 ULONG Length, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7484 BOOLEAN ReturnSingleEntry, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7485 PVOID EaList, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7486 ULONG EaListLength, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7487 PULONG EaIndex, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7488 BOOLEAN RestartScan); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7489 typedef NTSTATUS (NTAPI *PfnNtQueryInformationFile)( |
28844
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7490 HANDLE FileHandle, |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7491 PIO_STATUS_BLOCK IoStatusBlock, |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7492 PVOID FileInformation, |
c0403cd5ca06
patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
7493 ULONG Length, |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7494 FILE_INFORMATION_CLASS FileInformationClass); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7495 typedef VOID (NTAPI *PfnRtlInitUnicodeString)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7496 PUNICODE_STRING DestinationString, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7497 PCWSTR SourceString); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7498 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7499 PfnNtOpenFile pNtOpenFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7500 PfnNtClose pNtClose = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7501 PfnNtSetEaFile pNtSetEaFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7502 PfnNtQueryEaFile pNtQueryEaFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7503 PfnNtQueryInformationFile pNtQueryInformationFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7504 PfnRtlInitUnicodeString pRtlInitUnicodeString = NULL; |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
7505 #endif |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7506 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7507 /* |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7508 * Load ntdll.dll functions. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7509 */ |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7510 static BOOL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7511 load_ntdll(void) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7512 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7513 static int loaded = -1; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7514 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7515 if (loaded == -1) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7516 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7517 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
|
7518 if (hNtdll != NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7519 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7520 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
|
7521 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
|
7522 pNtSetEaFile = (PfnNtSetEaFile) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7523 GetProcAddress(hNtdll, "NtSetEaFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7524 pNtQueryEaFile = (PfnNtQueryEaFile) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7525 GetProcAddress(hNtdll, "NtQueryEaFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7526 pNtQueryInformationFile = (PfnNtQueryInformationFile) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7527 GetProcAddress(hNtdll, "NtQueryInformationFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7528 pRtlInitUnicodeString = (PfnRtlInitUnicodeString) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7529 GetProcAddress(hNtdll, "RtlInitUnicodeString"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7530 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7531 if (pNtOpenFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7532 || pNtClose == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7533 || pNtSetEaFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7534 || pNtQueryEaFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7535 || pNtQueryInformationFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7536 || pRtlInitUnicodeString == NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7537 loaded = FALSE; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7538 else |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7539 loaded = TRUE; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7540 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7541 return (BOOL) loaded; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7542 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7543 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7544 /* |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7545 * 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
|
7546 */ |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7547 static void |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7548 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
|
7549 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7550 char_u *fromf = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7551 char_u *tof = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7552 WCHAR *fromw = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7553 WCHAR *tow = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7554 UNICODE_STRING u; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7555 HANDLE h; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7556 OBJECT_ATTRIBUTES oa; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7557 IO_STATUS_BLOCK iosb; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7558 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
|
7559 void *ea = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7560 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7561 if (!load_ntdll()) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7562 return; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7563 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7564 // 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
|
7565 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
|
7566 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
|
7567 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
|
7568 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7569 STRCPY(fromf, "\\??\\"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7570 STRCAT(fromf, from); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7571 STRCPY(tof, "\\??\\"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7572 STRCAT(tof, to); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7573 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7574 // 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
|
7575 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
|
7576 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
|
7577 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
|
7578 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7579 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7580 // Get the EA. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7581 pRtlInitUnicodeString(&u, fromw); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7582 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
|
7583 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
|
7584 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
|
7585 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7586 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
|
7587 FileEaInformation); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7588 if (eainfo.EaSize != 0) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7589 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7590 ea = alloc(eainfo.EaSize); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7591 if (ea != NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7592 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7593 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
|
7594 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
|
7595 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7596 vim_free(ea); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7597 ea = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7598 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7599 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7600 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7601 pNtClose(h); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7602 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7603 // Set the EA. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7604 if (ea != NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7605 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7606 pRtlInitUnicodeString(&u, tow); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7607 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
|
7608 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
|
7609 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
|
7610 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7611 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7612 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
|
7613 pNtClose(h); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7614 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7615 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7616 theend: |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7617 vim_free(fromf); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7618 vim_free(tof); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7619 vim_free(fromw); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7620 vim_free(tow); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7621 vim_free(ea); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7622 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7623 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7624 /* |
7 | 7625 * Copy file attributes from file "from" to file "to". |
7626 * For Windows NT and later we copy info streams. | |
7627 * Always returns zero, errors are ignored. | |
7628 */ | |
7629 int | |
7630 mch_copy_file_attribute(char_u *from, char_u *to) | |
7631 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7632 // 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
|
7633 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
|
7634 copy_extattr(from, to); |
7 | 7635 return 0; |
7636 } | |
7637 | |
26 | 7638 |
7639 /* | |
24848
c91b3e5b7896
patch 8.2.2962: MS-Windows command line arguments have wrong encoding
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
7640 * The command line arguments in UTF-16 |
26 | 7641 */ |
344 | 7642 static int nArgsW = 0; |
26 | 7643 static LPWSTR *ArglistW = NULL; |
7644 static int global_argc = 0; | |
7645 static char **global_argv; | |
7646 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7647 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
|
7648 // for the argument list. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7649 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
|
7650 // command line arguments added to |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7651 // the argument list |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7652 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
|
7653 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
|
7654 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
|
7655 static int used_file_diff_mode = FALSE; // file name was with diff mode |
26 | 7656 static int used_alist_count = 0; |
7657 | |
7658 | |
7659 /* | |
7660 * Get the command line arguments. Unicode version. | |
7661 * Returns argc. Zero when something fails. | |
7662 */ | |
7663 int | |
7664 get_cmd_argsW(char ***argvp) | |
7665 { | |
7666 char **argv = NULL; | |
7667 int argc = 0; | |
7668 int i; | |
7669 | |
6193 | 7670 free_cmd_argsW(); |
26 | 7671 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7672 if (ArglistW != NULL) | |
7673 { | |
7674 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7675 if (argv != NULL) | |
7676 { | |
7677 argc = nArgsW; | |
7678 argv[argc] = NULL; | |
7679 for (i = 0; i < argc; ++i) | |
7680 { | |
7681 int len; | |
7682 | |
24848
c91b3e5b7896
patch 8.2.2962: MS-Windows command line arguments have wrong encoding
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
7683 // 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
|
7684 WideCharToMultiByte_alloc(CP_UTF8, 0, |
835 | 7685 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7686 (LPSTR *)&argv[i], &len, 0, 0); |
7687 if (argv[i] == NULL) | |
7688 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7689 // Out of memory, clear everything. |
26 | 7690 while (i > 0) |
7691 free(argv[--i]); | |
7692 free(argv); | |
5529 | 7693 argv = NULL; |
26 | 7694 argc = 0; |
7695 } | |
7696 } | |
7697 } | |
7698 } | |
7699 | |
7700 global_argc = argc; | |
7701 global_argv = argv; | |
7702 if (argc > 0) | |
6193 | 7703 { |
7704 if (used_file_indexes != NULL) | |
7705 free(used_file_indexes); | |
26 | 7706 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7707 } |
26 | 7708 |
7709 if (argvp != NULL) | |
7710 *argvp = argv; | |
7711 return argc; | |
7712 } | |
7713 | |
7714 void | |
7715 free_cmd_argsW(void) | |
7716 { | |
7717 if (ArglistW != NULL) | |
7718 { | |
7719 GlobalFree(ArglistW); | |
7720 ArglistW = NULL; | |
7721 } | |
7722 } | |
7723 | |
7724 /* | |
7725 * Remember "name" is an argument that was added to the argument list. | |
7726 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7727 * is called. | |
7728 */ | |
7729 void | |
819 | 7730 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7731 { |
7732 int i; | |
7733 | |
7734 if (used_file_indexes == NULL) | |
7735 return; | |
7736 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7737 if (STRCMP(global_argv[i], name) == 0) | |
7738 { | |
7739 used_file_argc = i; | |
7740 used_file_indexes[used_file_count++] = i; | |
7741 break; | |
7742 } | |
7743 used_file_literal = literal; | |
7744 used_file_full_path = full_path; | |
819 | 7745 used_file_diff_mode = diff_mode; |
26 | 7746 } |
7747 | |
7748 /* | |
7749 * Remember the length of the argument list as it was. If it changes then we | |
7750 * leave it alone when 'encoding' is set. | |
7751 */ | |
7752 void | |
7753 set_alist_count(void) | |
7754 { | |
7755 used_alist_count = GARGCOUNT; | |
7756 } | |
7757 | |
7758 /* | |
7759 * 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
|
7760 * has been changed while starting up. Use the UTF-16 command line arguments |
26 | 7761 * and convert them to 'encoding'. |
7762 */ | |
7763 void | |
7764 fix_arg_enc(void) | |
7765 { | |
7766 int i; | |
7767 int idx; | |
7768 char_u *str; | |
41 | 7769 int *fnum_list; |
26 | 7770 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7771 // Safety checks: |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7772 // - 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
|
7773 // list, something must be wrong. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7774 // - 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
|
7775 // - the length of the argument list wasn't changed by the user. |
344 | 7776 if (global_argc != nArgsW |
26 | 7777 || ArglistW == NULL |
7778 || used_file_indexes == NULL | |
7779 || used_file_count == 0 | |
7780 || used_alist_count != GARGCOUNT) | |
7781 return; | |
7782 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7783 // 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
|
7784 fnum_list = ALLOC_MULT(int, GARGCOUNT); |
41 | 7785 if (fnum_list == NULL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7786 return; // out of memory |
41 | 7787 for (i = 0; i < GARGCOUNT; ++i) |
7788 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7789 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7790 // Clear the argument list. Make room for the new arguments. |
26 | 7791 alist_clear(&global_alist); |
7792 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
|
7793 return; // out of memory |
26 | 7794 |
7795 for (i = 0; i < used_file_count; ++i) | |
7796 { | |
7797 idx = used_file_indexes[i]; | |
1752 | 7798 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7799 if (str != NULL) |
41 | 7800 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7801 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
|
7802 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
7803 #ifdef FEAT_DIFF |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7804 // 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
|
7805 // directory name. Just like it's done in main(). |
819 | 7806 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 |
7807 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7808 { | |
7809 char_u *r; | |
7810 | |
7811 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7812 if (r != NULL) | |
7813 { | |
7814 vim_free(str); | |
7815 str = r; | |
7816 } | |
7817 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
7818 #endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7819 // 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
|
7820 // names it's done by alist_expand() below. |
41 | 7821 if (used_file_literal) |
7822 buf_set_name(fnum_list[i], str); | |
7823 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7824 // 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
|
7825 // 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
|
7826 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
|
7827 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7828 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
|
7829 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7830 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
|
7831 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7832 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7833 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7834 } |
26 | 7835 } |
7836 | |
7837 if (!used_file_literal) | |
7838 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7839 // 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
|
7840 // 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
|
7841 // 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
|
7842 // "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
|
7843 // 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
|
7844 // 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
|
7845 // 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
|
7846 // 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
|
7847 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
|
7848 do_cmdline_cmd((char_u *)":legacy let g:SaVe_WIG = &wig|set wig="); |
41 | 7849 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
|
7850 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
|
7851 (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
|
7852 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
|
7853 (char_u *)":legacy let &wig = g:SaVe_WIG|unlet g:SaVe_WIG"); |
26 | 7854 } |
7855 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7856 // 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
|
7857 // arglist and there is no file name: Edit the first argument now. |
26 | 7858 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) |
7859 { | |
7860 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
|
7861 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
|
7862 && 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
|
7863 last_chdir_reason = "drop"; |
26 | 7864 } |
41 | 7865 |
7866 set_alist_count(); | |
26 | 7867 } |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7868 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7869 int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
7870 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
|
7871 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7872 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
|
7873 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
|
7874 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16750
diff
changeset
|
7875 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
|
7876 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
|
7877 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
|
7878 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7879 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
|
7880 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7881 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
|
7882 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7883 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
|
7884 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
|
7885 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
|
7886 _wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7887 #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
|
7888 libintl_wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7889 #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
|
7890 // 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
|
7891 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
|
7892 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7893 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
|
7894 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7895 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7896 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7897 * 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
|
7898 * 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
|
7899 */ |
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
|
7900 #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
|
7901 |
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
|
7902 /* |
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
|
7903 * 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
|
7904 * 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
|
7905 */ |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7906 #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
|
7907 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7908 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7909 * 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
|
7910 * 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
|
7911 */ |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7912 #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
|
7913 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7914 /* |
18611
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7915 * 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
|
7916 */ |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7917 #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
|
7918 |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7919 /* |
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
|
7920 * 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
|
7921 * 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
|
7922 */ |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7923 #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
|
7924 |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7925 /* |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7926 * 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
|
7927 * insider preview. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7928 */ |
18235
88716bc1c20b
patch 8.1.2112: build number for ConPTY is outdated
Bram Moolenaar <Bram@vim.org>
parents:
18180
diff
changeset
|
7929 #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
|
7930 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7931 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7932 * Not stable now. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7933 */ |
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
|
7934 #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
|
7935 |
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
|
7936 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
|
7937 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
|
7938 { |
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
|
7939 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
|
7940 #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
|
7941 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
|
7942 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
|
7943 |
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
|
7944 # 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
|
7945 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
|
7946 # 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
|
7947 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7948 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
|
7949 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7950 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
|
7951 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
|
7952 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
|
7953 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
|
7954 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
|
7955 } |
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
|
7956 #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
|
7957 |
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
|
7958 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
|
7959 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
|
7960 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
|
7961 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
|
7962 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7963 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
|
7964 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
|
7965 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
|
7966 conpty_type = 2; |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7967 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
|
7968 conpty_type = 2; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7969 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
|
7970 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
|
7971 |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7972 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
|
7973 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
|
7974 } |
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
|
7975 |
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
|
7976 #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
|
7977 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7978 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
|
7979 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
|
7980 { |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
7981 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
|
7982 # ifdef FEAT_TERMGUICOLORS |
28763
b01bca69b1d5
patch 8.2.4906: MS-Windows: cannot use transparent background
Bram Moolenaar <Bram@vim.org>
parents:
28702
diff
changeset
|
7983 COLORREF 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
|
7984 # 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
|
7985 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7986 csbi.cbSize = sizeof(csbi); |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
7987 GetConsoleScreenBufferInfoEx(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
|
7988 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
|
7989 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
|
7990 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
|
7991 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
|
7992 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7993 # ifdef FEAT_TERMGUICOLORS |
30013
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
7994 if (!USE_WT) |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
7995 { |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
7996 COLORREF bg; |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
7997 bg = (COLORREF)csbi.ColorTable[g_color_index_bg]; |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
7998 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
7999 default_console_color_bg = bg; |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8000 } |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
8001 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
|
8002 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
|
8003 default_console_color_fg = fg; |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
8004 # 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
|
8005 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8006 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
|
8007 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8008 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8009 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
|
8010 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
|
8011 { |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8012 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
|
8013 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8014 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8015 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
|
8016 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
|
8017 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
|
8018 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8019 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8020 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
|
8021 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
|
8022 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
|
8023 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
|
8024 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8025 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
|
8026 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
|
8027 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
|
8028 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
|
8029 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
|
8030 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8031 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8032 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
|
8033 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
|
8034 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
|
8035 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8036 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
|
8037 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8038 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
|
8039 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
|
8040 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8041 |
27521
3ad379c0ab28
patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27455
diff
changeset
|
8042 # define FAST256(x) \ |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8043 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
|
8044 && 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
|
8045 && 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
|
8046 |
27521
3ad379c0ab28
patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27455
diff
changeset
|
8047 # define FAST256CASE(x) \ |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8048 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
|
8049 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
|
8050 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8051 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
|
8052 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
|
8053 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
|
8054 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
|
8055 { |
27521
3ad379c0ab28
patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27455
diff
changeset
|
8056 # define MAXSGR 16 |
3ad379c0ab28
patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27455
diff
changeset
|
8057 # define SGRBUFSIZE 2 + 4 * MAXSGR + 1 // '\033[' + SGR + 'm' |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8058 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
|
8059 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
|
8060 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
|
8061 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
|
8062 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
|
8063 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
|
8064 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8065 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
|
8066 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8067 sgrfgr = sgrbgr = -1; |
30019
347cf03fee2b
patch 9.0.0347: MS-Windows: cannot set cursor shape in Windows Terminal
Bram Moolenaar <Bram@vim.org>
parents:
30013
diff
changeset
|
8068 vtp_printf("\033[m"); |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8069 return; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8070 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8071 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8072 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
|
8073 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
|
8074 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8075 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
|
8076 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
|
8077 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8078 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
|
8079 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8080 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
|
8081 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8082 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
|
8083 && 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
|
8084 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8085 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
|
8086 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
|
8087 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8088 else |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8089 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8090 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
|
8091 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
|
8092 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
|
8093 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
|
8094 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8095 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8096 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
|
8097 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8098 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
|
8099 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
|
8100 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8101 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8102 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
|
8103 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8104 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
|
8105 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8106 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
|
8107 && 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
|
8108 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8109 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
|
8110 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
|
8111 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8112 else |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8113 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8114 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
|
8115 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
|
8116 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
|
8117 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
|
8118 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8119 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8120 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
|
8121 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8122 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
|
8123 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
|
8124 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8125 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8126 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
|
8127 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
|
8128 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
|
8129 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
|
8130 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
|
8131 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
|
8132 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
|
8133 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
|
8134 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
|
8135 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
|
8136 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8137 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
|
8138 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
|
8139 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8140 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8141 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
|
8142 *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
|
8143 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8144 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
|
8145 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8146 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
|
8147 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
|
8148 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8149 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
|
8150 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8151 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
|
8152 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8153 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
|
8154 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8155 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
|
8156 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8157 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
|
8158 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8159 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
|
8160 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8161 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
|
8162 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8163 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
|
8164 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8165 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
|
8166 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8167 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
|
8168 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8169 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
|
8170 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8171 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
|
8172 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8173 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
|
8174 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8175 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
|
8176 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8177 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
|
8178 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8179 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
|
8180 *p-- = '['; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8181 *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
|
8182 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
|
8183 default: |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8184 break; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8185 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8186 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8187 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8188 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
|
8189 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
|
8190 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8191 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
|
8192 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8193 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8194 int |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8195 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
|
8196 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8197 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
|
8198 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8199 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
8200 # 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
|
8201 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
|
8202 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8203 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
|
8204 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
8205 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
|
8206 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8207 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
|
8208 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
|
8209 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
8210 # 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
|
8211 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8212 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
|
8213 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
|
8214 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8215 # ifdef FEAT_TERMGUICOLORS |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8216 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
|
8217 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
|
8218 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
|
8219 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8220 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
|
8221 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8222 |
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
|
8223 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
|
8224 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8225 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
|
8226 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8227 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
|
8228 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
|
8229 return; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8230 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8231 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8232 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
|
8233 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
|
8234 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8235 csbi.cbSize = sizeof(csbi); |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8236 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8237 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8238 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
|
8239 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
|
8240 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
|
8241 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
|
8242 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
|
8243 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
|
8244 csbi.ColorTable[g_color_index_fg] = (COLORREF)fg; |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8245 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8246 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8247 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8248 |
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
|
8249 # 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
|
8250 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
|
8251 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
|
8252 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
|
8253 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
|
8254 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
|
8255 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
|
8256 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8257 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
|
8258 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
|
8259 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
|
8260 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
|
8261 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
|
8262 |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8263 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
|
8264 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
|
8265 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
|
8266 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
|
8267 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8268 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
|
8269 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
|
8270 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
|
8271 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
|
8272 : 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
|
8273 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
|
8274 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
|
8275 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8276 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
|
8277 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8278 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
|
8279 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
|
8280 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
30112
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8281 if (USE_WT) |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8282 { |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8283 cterm_normal_bg_gui_color = guibg = |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8284 ctermbg != -1 ? ctermtoxterm(ctermbg) : INVALCOLOR; |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8285 if (ctermbg < 0) |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8286 ctermbg = 0; |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8287 } |
7ad136fb7fcd
patch 9.0.0392: inverted condition is a bit confusing
Bram Moolenaar <Bram@vim.org>
parents:
30019
diff
changeset
|
8288 else |
30013
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8289 { |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8290 guibg = ctermbg != -1 ? ctermtoxterm(ctermbg) |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8291 : default_console_color_bg; |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8292 cterm_normal_bg_gui_color = guibg; |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8293 ctermbg = ctermbg < 0 ? 0 : ctermbg; |
11cfe4c6d677
patch 9.0.0344: MS-Windows: background color wrong in Console
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
8294 } |
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
|
8295 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8296 |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8297 *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
|
8298 *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
|
8299 *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
|
8300 *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
|
8301 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8302 # 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
|
8303 |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8304 /* |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8305 * 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
|
8306 */ |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8307 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
|
8308 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
|
8309 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8310 # ifdef FEAT_TERMGUICOLORS |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8311 CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8312 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8313 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
|
8314 return; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8315 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8316 csbi.cbSize = sizeof(csbi); |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8317 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8318 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8319 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
|
8320 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
|
8321 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
|
8322 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
|
8323 csbi.ColorTable[g_color_index_fg] = (COLORREF)store_console_fg_rgb; |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8324 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8325 # endif |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8326 } |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8327 |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8328 /* |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8329 * 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
|
8330 */ |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8331 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
|
8332 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
|
8333 { |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8334 # ifdef FEAT_TERMGUICOLORS |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8335 CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8336 |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8337 csbi.cbSize = sizeof(csbi); |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8338 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8339 |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8340 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
|
8341 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
|
8342 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
|
8343 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
|
8344 csbi.ColorTable[g_color_index_fg] = (COLORREF)save_console_fg_rgb; |
30320
0763cb330a65
patch 9.0.0496: no good reason to keep supporting Windows-XP
Bram Moolenaar <Bram@vim.org>
parents:
30200
diff
changeset
|
8345 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8346 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8347 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8348 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8349 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8350 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
|
8351 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8352 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
|
8353 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
|
8354 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8355 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
|
8356 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8357 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8358 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8359 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
|
8360 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8361 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
|
8362 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8363 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8364 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8365 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
|
8366 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8367 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
|
8368 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8369 |
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
|
8370 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
|
8371 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
|
8372 { |
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
|
8373 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
|
8374 } |
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
|
8375 |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
8376 #endif |
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
8377 |
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
|
8378 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
|
8379 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
|
8380 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8381 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
|
8382 } |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8383 |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8384 int |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8385 get_conpty_type(void) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8386 { |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8387 return conpty_type; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8388 } |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8389 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8390 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
|
8391 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
|
8392 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8393 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
|
8394 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8395 |
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
|
8396 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
|
8397 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
|
8398 { |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8399 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
|
8400 } |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8401 |
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
|
8402 #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
|
8403 void |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8404 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
|
8405 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8406 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
|
8407 COORD coord; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8408 SMALL_RECT newsize; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8409 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8410 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
|
8411 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8412 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
|
8413 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
|
8414 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
|
8415 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8416 newsize.Left = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8417 newsize.Top = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8418 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
|
8419 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
|
8420 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
|
8421 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8422 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
|
8423 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8424 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8425 #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
|
8426 |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8427 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
|
8428 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
|
8429 { |
27657
a077948be0f4
patch 8.2.4354: dynamic loading of libsodium not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
27581
diff
changeset
|
8430 static char *oldmsg = NULL; |
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
|
8431 char *msg = NULL; |
27657
a077948be0f4
patch 8.2.4354: dynamic loading of libsodium not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
27581
diff
changeset
|
8432 |
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
|
8433 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
|
8434 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); |
27657
a077948be0f4
patch 8.2.4354: dynamic loading of libsodium not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
27581
diff
changeset
|
8435 if (oldmsg != NULL) |
a077948be0f4
patch 8.2.4354: dynamic loading of libsodium not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
27581
diff
changeset
|
8436 LocalFree(oldmsg); |
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
|
8437 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
|
8438 { |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8439 // 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
|
8440 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
|
8441 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
|
8442 *pcrlf = '\0'; |
27657
a077948be0f4
patch 8.2.4354: dynamic loading of libsodium not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
27581
diff
changeset
|
8443 oldmsg = msg; |
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
|
8444 } |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8445 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
|
8446 } |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8447 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8448 #if defined(FEAT_RELTIME) || defined(PROTO) |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8449 static HANDLE timer_handle; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8450 static int timer_active = FALSE; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8451 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8452 /* |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8453 * Calls to start_timeout alternate the return value pointer between the two |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8454 * entries in timeout_flags. If the previously active timeout is very close to |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8455 * expiring when start_timeout() is called then a race condition means that the |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8456 * set_flag() function may still be invoked after the previous timer is |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8457 * deleted. Ping-ponging between the two flags prevents this causing 'fake' |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8458 * timeouts. |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8459 */ |
29245
b12fd2b3be63
patch 8.2.5141: using "volatile int" in a signal handler might be wrong
Bram Moolenaar <Bram@vim.org>
parents:
29220
diff
changeset
|
8460 static sig_atomic_t timeout_flags[2]; |
b12fd2b3be63
patch 8.2.5141: using "volatile int" in a signal handler might be wrong
Bram Moolenaar <Bram@vim.org>
parents:
29220
diff
changeset
|
8461 static int timeout_flag_idx = 0; |
b12fd2b3be63
patch 8.2.5141: using "volatile int" in a signal handler might be wrong
Bram Moolenaar <Bram@vim.org>
parents:
29220
diff
changeset
|
8462 static sig_atomic_t *timeout_flag = &timeout_flags[0]; |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8463 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8464 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8465 static void CALLBACK |
29105
faf7fcd1c8d5
patch 8.2.5073: clang on MS-Windows produces warnings
Bram Moolenaar <Bram@vim.org>
parents:
29096
diff
changeset
|
8466 set_flag(void *param, BOOLEAN unused2 UNUSED) |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8467 { |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8468 int *timeout_flag = (int *)param; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8469 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8470 *timeout_flag = TRUE; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8471 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8472 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8473 /* |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8474 * Stop any active timeout. |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8475 */ |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8476 void |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8477 stop_timeout(void) |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8478 { |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8479 if (timer_active) |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8480 { |
30882
7449da0e006b
patch 9.0.0775: MS-Windows: mouse scrolling not supported in the console
Bram Moolenaar <Bram@vim.org>
parents:
30641
diff
changeset
|
8481 BOOL ret = DeleteTimerQueueTimer(NULL, timer_handle, NULL); |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8482 timer_active = FALSE; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8483 if (!ret && GetLastError() != ERROR_IO_PENDING) |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8484 { |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8485 semsg(_(e_could_not_clear_timeout_str), GetWin32Error()); |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8486 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8487 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8488 *timeout_flag = FALSE; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8489 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8490 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8491 /* |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8492 * Start the timeout timer. |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8493 * |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8494 * The period is defined in milliseconds. |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8495 * |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8496 * The return value is a pointer to a flag that is initialised to 0. If the |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8497 * timeout expires, the flag is set to 1. This will only return pointers to |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8498 * static memory; i.e. any pointer returned by this function may always be |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8499 * safely dereferenced. |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8500 * |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8501 * This function is not expected to fail, but if it does it still returns a |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8502 * valid flag pointer; the flag will remain stuck at zero. |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8503 */ |
29245
b12fd2b3be63
patch 8.2.5141: using "volatile int" in a signal handler might be wrong
Bram Moolenaar <Bram@vim.org>
parents:
29220
diff
changeset
|
8504 volatile sig_atomic_t * |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8505 start_timeout(long msec) |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8506 { |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8507 BOOL ret; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8508 |
29220
d6f8b784d0f6
patch 8.2.5129: timeout handling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
8509 timeout_flag = &timeout_flags[timeout_flag_idx]; |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8510 |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8511 stop_timeout(); |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8512 ret = CreateTimerQueueTimer( |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8513 &timer_handle, NULL, set_flag, timeout_flag, |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8514 (DWORD)msec, 0, WT_EXECUTEDEFAULT); |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8515 if (!ret) |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8516 { |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8517 semsg(_(e_could_not_set_timeout_str), GetWin32Error()); |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8518 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8519 else |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8520 { |
29220
d6f8b784d0f6
patch 8.2.5129: timeout handling is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
8521 timeout_flag_idx = (timeout_flag_idx + 1) % 2; |
29071
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8522 timer_active = TRUE; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8523 *timeout_flag = FALSE; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8524 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8525 return timeout_flag; |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8526 } |
b90bca860b5a
patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28844
diff
changeset
|
8527 #endif |