Mercurial > vim
annotate src/os_win32.c @ 14904:8dd4014f9b98
Added tag v8.1.0463 for changeset c1ee9f32bec3f9d462e6e2fb54a5f3b9ef0e3a5a
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 07 Oct 2018 21:00:06 +0200 |
parents | 66176f8735aa |
children | 6e4e0d43b20b |
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 | |
13 * the console version only, so there is a lot of "#ifndef FEAT_GUI_W32". | |
14 * | |
15 * Win32 (Windows NT and Windows 95) system-dependent routines. | |
16 * Portions lifted from the Win32 SDK samples, the MSDOS-dependent code, | |
17 * NetHack 3.1.3, GNU Emacs 19.30, and Vile 5.5. | |
18 * | |
19 * George V. Reilly <george@reilly.org> wrote most of this. | |
20 * Roger Knobbe <rogerk@wonderware.com> did the initial port of Vim 3.0. | |
21 */ | |
22 | |
23 #include "vim.h" | |
24 | |
14 | 25 #ifdef FEAT_MZSCHEME |
26 # include "if_mzsch.h" | |
27 #endif | |
28 | |
7 | 29 #include <sys/types.h> |
30 #include <signal.h> | |
31 #include <limits.h> | |
3927 | 32 |
33 /* cproto fails on missing include files */ | |
34 #ifndef PROTO | |
35 # include <process.h> | |
36 #endif | |
7 | 37 |
38 #undef chdir | |
39 #ifdef __GNUC__ | |
40 # ifndef __MINGW32__ | |
41 # include <dirent.h> | |
42 # endif | |
43 #else | |
44 # include <direct.h> | |
45 #endif | |
46 | |
3927 | 47 #ifndef PROTO |
48 # if defined(FEAT_TITLE) && !defined(FEAT_GUI_W32) | |
49 # include <shellapi.h> | |
50 # endif | |
7 | 51 #endif |
52 | |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
53 #ifdef FEAT_JOB_CHANNEL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
54 # include <tlhelp32.h> |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
55 #endif |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
56 |
7 | 57 #ifdef __MINGW32__ |
58 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED | |
59 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 | |
60 # endif | |
61 # ifndef RIGHTMOST_BUTTON_PRESSED | |
62 # define RIGHTMOST_BUTTON_PRESSED 0x0002 | |
63 # endif | |
64 # ifndef FROM_LEFT_2ND_BUTTON_PRESSED | |
65 # define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 | |
66 # endif | |
67 # ifndef FROM_LEFT_3RD_BUTTON_PRESSED | |
68 # define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 | |
69 # endif | |
70 # ifndef FROM_LEFT_4TH_BUTTON_PRESSED | |
71 # define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 | |
72 # endif | |
73 | |
74 /* | |
75 * EventFlags | |
76 */ | |
77 # ifndef MOUSE_MOVED | |
78 # define MOUSE_MOVED 0x0001 | |
79 # endif | |
80 # ifndef DOUBLE_CLICK | |
81 # define DOUBLE_CLICK 0x0002 | |
82 # endif | |
83 #endif | |
84 | |
85 /* Record all output and all keyboard & mouse input */ | |
86 /* #define MCH_WRITE_DUMP */ | |
87 | |
88 #ifdef MCH_WRITE_DUMP | |
89 FILE* fdDump = NULL; | |
90 #endif | |
91 | |
92 /* | |
93 * When generating prototypes for Win32 on Unix, these lines make the syntax | |
94 * errors disappear. They do not need to be correct. | |
95 */ | |
96 #ifdef PROTO | |
97 #define WINAPI | |
98 typedef char * LPCSTR; | |
26 | 99 typedef char * LPWSTR; |
7 | 100 typedef int ACCESS_MASK; |
101 typedef int BOOL; | |
102 typedef int COLORREF; | |
103 typedef int CONSOLE_CURSOR_INFO; | |
104 typedef int COORD; | |
105 typedef int DWORD; | |
106 typedef int HANDLE; | |
7668
21b0a39d13ed
commit https://github.com/vim/vim/commit/ef26954a35207c3f17d6ed35d9a40c918d974892
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
107 typedef int LPHANDLE; |
7 | 108 typedef int HDC; |
109 typedef int HFONT; | |
110 typedef int HICON; | |
111 typedef int HINSTANCE; | |
112 typedef int HWND; | |
113 typedef int INPUT_RECORD; | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
114 typedef int INT; |
7 | 115 typedef int KEY_EVENT_RECORD; |
116 typedef int LOGFONT; | |
117 typedef int LPBOOL; | |
118 typedef int LPCTSTR; | |
119 typedef int LPDWORD; | |
120 typedef int LPSTR; | |
121 typedef int LPTSTR; | |
122 typedef int LPVOID; | |
123 typedef int MOUSE_EVENT_RECORD; | |
124 typedef int PACL; | |
125 typedef int PDWORD; | |
126 typedef int PHANDLE; | |
127 typedef int PRINTDLG; | |
128 typedef int PSECURITY_DESCRIPTOR; | |
129 typedef int PSID; | |
130 typedef int SECURITY_INFORMATION; | |
131 typedef int SHORT; | |
132 typedef int SMALL_RECT; | |
133 typedef int TEXTMETRIC; | |
134 typedef int TOKEN_INFORMATION_CLASS; | |
135 typedef int TRUSTEE; | |
136 typedef int WORD; | |
137 typedef int WCHAR; | |
138 typedef void VOID; | |
3927 | 139 typedef int BY_HANDLE_FILE_INFORMATION; |
5112
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
140 typedef int SE_OBJECT_TYPE; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
141 typedef int PSNSECINFO; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
142 typedef int PSNSECINFOW; |
6359 | 143 typedef int STARTUPINFO; |
144 typedef int PROCESS_INFORMATION; | |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
145 typedef int LPSECURITY_ATTRIBUTES; |
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
146 # define __stdcall /* empty */ |
7 | 147 #endif |
148 | |
149 #if defined(__BORLANDC__) | |
150 /* Strangely Borland uses a non-standard name. */ | |
151 # define wcsicmp(a, b) wcscmpi((a), (b)) | |
152 #endif | |
153 | |
154 #ifndef FEAT_GUI_W32 | |
155 /* Win32 Console handles for input and output */ | |
156 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; | |
157 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; | |
158 | |
159 /* Win32 Screen buffer,coordinate,console I/O information */ | |
160 static SMALL_RECT g_srScrollRegion; | |
161 static COORD g_coord; /* 0-based, but external coords are 1-based */ | |
162 | |
163 /* The attribute of the screen when the editor was started */ | |
164 static WORD g_attrDefault = 7; /* lightgray text on black background */ | |
165 static WORD g_attrCurrent; | |
166 | |
167 static int g_fCBrkPressed = FALSE; /* set by ctrl-break interrupt */ | |
168 static int g_fCtrlCPressed = FALSE; /* set when ctrl-C or ctrl-break detected */ | |
169 static int g_fForceExit = FALSE; /* set when forcefully exiting */ | |
170 | |
171 static void scroll(unsigned cLines); | |
172 static void set_scroll_region(unsigned left, unsigned top, | |
173 unsigned right, unsigned bottom); | |
174 static void delete_lines(unsigned cLines); | |
175 static void gotoxy(unsigned x, unsigned y); | |
176 static void standout(void); | |
177 static int s_cursor_visible = TRUE; | |
178 static int did_create_conin = FALSE; | |
179 #else | |
180 static int s_dont_use_vimrun = TRUE; | |
181 static int need_vimrun_warning = FALSE; | |
182 static char *vimrun_path = "vimrun "; | |
183 #endif | |
184 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
185 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
186 static int win32_setattrs(char_u *name, int attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
187 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
188 |
7 | 189 #ifndef FEAT_GUI_W32 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
190 static int vtp_working = 0; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
191 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
|
192 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
|
193 static int vtp_printf(char *format, ...); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
194 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
|
195 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
|
196 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
197 static 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
|
198 static guicolor_T save_console_fg_rgb; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
199 |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
200 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
|
201 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
|
202 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
203 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
204 static int default_console_color_bg = 0x000000; // black |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
205 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
|
206 # endif |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
207 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
208 # 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
|
209 # define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256))) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
210 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
211 # define USE_VTP 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
212 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
213 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
214 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
|
215 static void reset_console_color_rgb(void); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
216 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
217 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
218 /* This flag is newly created from Windows 10 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
219 #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
|
220 # 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
|
221 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
222 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
223 #ifndef FEAT_GUI_W32 |
7 | 224 static int suppress_winsize = 1; /* don't fiddle with console */ |
225 #endif | |
226 | |
2612 | 227 static char_u *exe_path = NULL; |
228 | |
5633 | 229 static BOOL win8_or_later = FALSE; |
230 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
231 #ifndef FEAT_GUI_W32 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
232 /* Dynamic loading for portability */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
233 typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
234 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
235 ULONG cbSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
236 COORD dwSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
237 COORD dwCursorPosition; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
238 WORD wAttributes; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
239 SMALL_RECT srWindow; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
240 COORD dwMaximumWindowSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
241 WORD wPopupAttributes; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
242 BOOL bFullscreenSupported; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
243 COLORREF ColorTable[16]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
244 } DYN_CONSOLE_SCREEN_BUFFER_INFOEX, *PDYN_CONSOLE_SCREEN_BUFFER_INFOEX; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
245 typedef BOOL (WINAPI *PfnGetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
246 static PfnGetConsoleScreenBufferInfoEx pGetConsoleScreenBufferInfoEx; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
247 typedef BOOL (WINAPI *PfnSetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
248 static PfnSetConsoleScreenBufferInfoEx pSetConsoleScreenBufferInfoEx; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
249 static BOOL has_csbiex = FALSE; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
250 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
251 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
252 * 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
|
253 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
254 typedef BOOL (WINAPI *PfnRtlGetVersion)(LPOSVERSIONINFOW); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
255 # define MAKE_VER(major, minor, build) \ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
256 (((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
|
257 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
258 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
|
259 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
|
260 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
261 OSVERSIONINFOW osver = {sizeof(OSVERSIONINFOW)}; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
266 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
|
267 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
|
268 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
269 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
270 (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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
276 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
|
277 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
278 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
279 |
5580 | 280 /* |
281 * Version of ReadConsoleInput() that works with IME. | |
5590 | 282 * Works around problems on Windows 8. |
5580 | 283 */ |
284 static BOOL | |
285 read_console_input( | |
5590 | 286 HANDLE hInput, |
287 INPUT_RECORD *lpBuffer, | |
288 DWORD nLength, | |
289 LPDWORD lpEvents) | |
5580 | 290 { |
291 enum | |
292 { | |
5590 | 293 IRSIZE = 10 |
5580 | 294 }; |
5590 | 295 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 296 static DWORD s_dwIndex = 0; |
297 static DWORD s_dwMax = 0; | |
5590 | 298 DWORD dwEvents; |
5635 | 299 int head; |
300 int tail; | |
301 int i; | |
5580 | 302 |
6981 | 303 if (nLength == -2) |
304 return (s_dwMax > 0) ? TRUE : FALSE; | |
305 | |
5633 | 306 if (!win8_or_later) |
307 { | |
308 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
309 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
310 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 311 } |
312 | |
5580 | 313 if (s_dwMax == 0) |
314 { | |
5590 | 315 if (nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
316 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
317 if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents)) |
5590 | 318 return FALSE; |
5580 | 319 s_dwIndex = 0; |
5590 | 320 s_dwMax = dwEvents; |
321 if (dwEvents == 0) | |
5580 | 322 { |
5590 | 323 *lpEvents = 0; |
324 return TRUE; | |
5580 | 325 } |
5635 | 326 |
327 if (s_dwMax > 1) | |
328 { | |
329 head = 0; | |
330 tail = s_dwMax - 1; | |
331 while (head != tail) | |
332 { | |
333 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
334 && s_irCache[head + 1].EventType | |
335 == WINDOW_BUFFER_SIZE_EVENT) | |
336 { | |
337 /* Remove duplicate event to avoid flicker. */ | |
338 for (i = head; i < tail; ++i) | |
339 s_irCache[i] = s_irCache[i + 1]; | |
340 --tail; | |
341 continue; | |
342 } | |
343 head++; | |
344 } | |
345 s_dwMax = tail + 1; | |
346 } | |
5580 | 347 } |
5635 | 348 |
5590 | 349 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 350 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 351 s_dwMax = 0; |
5590 | 352 *lpEvents = 1; |
5580 | 353 return TRUE; |
354 } | |
355 | |
356 /* | |
357 * Version of PeekConsoleInput() that works with IME. | |
358 */ | |
359 static BOOL | |
360 peek_console_input( | |
5590 | 361 HANDLE hInput, |
362 INPUT_RECORD *lpBuffer, | |
363 DWORD nLength, | |
364 LPDWORD lpEvents) | |
5580 | 365 { |
5590 | 366 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 367 } |
368 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
369 # ifdef FEAT_CLIENTSERVER |
6981 | 370 static DWORD |
371 msg_wait_for_multiple_objects( | |
372 DWORD nCount, | |
373 LPHANDLE pHandles, | |
374 BOOL fWaitAll, | |
375 DWORD dwMilliseconds, | |
376 DWORD dwWakeMask) | |
377 { | |
378 if (read_console_input(NULL, NULL, -2, NULL)) | |
379 return WAIT_OBJECT_0; | |
380 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
381 dwMilliseconds, dwWakeMask); | |
382 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
383 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
384 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
385 # ifndef FEAT_CLIENTSERVER |
6981 | 386 static DWORD |
387 wait_for_single_object( | |
388 HANDLE hHandle, | |
389 DWORD dwMilliseconds) | |
390 { | |
391 if (read_console_input(NULL, NULL, -2, NULL)) | |
392 return WAIT_OBJECT_0; | |
393 return WaitForSingleObject(hHandle, dwMilliseconds); | |
394 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
395 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
396 #endif |
6981 | 397 |
7 | 398 static void |
399 get_exe_name(void) | |
400 { | |
2630 | 401 /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned |
402 * as the maximum length that works (plus a NUL byte). */ | |
403 #define MAX_ENV_PATH_LEN 8192 | |
404 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 405 char_u *p; |
7 | 406 |
407 if (exe_name == NULL) | |
408 { | |
409 /* store the name of the executable, may be used for $VIM */ | |
2630 | 410 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 411 if (*temp != NUL) |
412 exe_name = FullName_save((char_u *)temp, FALSE); | |
413 } | |
819 | 414 |
2612 | 415 if (exe_path == NULL && exe_name != NULL) |
819 | 416 { |
2615 | 417 exe_path = vim_strnsave(exe_name, |
418 (int)(gettail_sep(exe_name) - exe_name)); | |
2612 | 419 if (exe_path != NULL) |
819 | 420 { |
2612 | 421 /* Append our starting directory to $PATH, so that when doing |
422 * "!xxd" it's found in our starting directory. Needed because | |
423 * SearchPath() also looks there. */ | |
424 p = mch_getenv("PATH"); | |
2630 | 425 if (p == NULL |
426 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 427 { |
2630 | 428 if (p == NULL || *p == NUL) |
429 temp[0] = NUL; | |
430 else | |
431 { | |
432 STRCPY(temp, p); | |
433 STRCAT(temp, ";"); | |
434 } | |
2612 | 435 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
436 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 437 } |
819 | 438 } |
439 } | |
7 | 440 } |
441 | |
2612 | 442 /* |
3361 | 443 * Unescape characters in "p" that appear in "escaped". |
444 */ | |
445 static void | |
446 unescape_shellxquote(char_u *p, char_u *escaped) | |
447 { | |
3386 | 448 int l = (int)STRLEN(p); |
3361 | 449 int n; |
450 | |
451 while (*p != NUL) | |
452 { | |
453 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
454 mch_memmove(p, p + 1, l--); | |
455 #ifdef FEAT_MBYTE | |
456 n = (*mb_ptr2len)(p); | |
457 #else | |
458 n = 1; | |
459 #endif | |
460 p += n; | |
461 l -= n; | |
462 } | |
463 } | |
464 | |
465 /* | |
2612 | 466 * Load library "name". |
467 */ | |
468 HINSTANCE | |
469 vimLoadLib(char *name) | |
470 { | |
3902 | 471 HINSTANCE dll = NULL; |
3889 | 472 |
473 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call | |
474 * vimLoadLib() recursively, which causes a stack overflow. */ | |
2612 | 475 if (exe_path == NULL) |
476 get_exe_name(); | |
3902 | 477 if (exe_path != NULL) |
2612 | 478 { |
3902 | 479 WCHAR old_dirw[MAXPATHL]; |
480 | |
481 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
482 { | |
483 /* Change directory to where the executable is, both to make | |
484 * sure we find a .dll there and to avoid looking for a .dll | |
485 * in the current directory. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
486 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 487 dll = LoadLibrary(name); |
488 SetCurrentDirectoryW(old_dirw); | |
489 return dll; | |
490 } | |
2612 | 491 } |
492 return dll; | |
493 } | |
494 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
495 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) || defined(PROTO) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
496 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
497 * 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
|
498 * 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
|
499 * If 'info' is 1, return the module name which the function is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
500 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
501 static void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
502 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
503 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
508 PIMAGE_THUNK_DATA pIAT; /* Import Address Table */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
509 PIMAGE_THUNK_DATA pINT; /* Import Name Table */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
510 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
|
511 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 + 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
|
519 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
520 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
|
521 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
522 if (!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
|
523 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
524 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
|
525 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
|
526 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
|
527 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
528 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
|
529 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
530 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
|
531 + (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
|
532 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
|
533 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
534 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
|
535 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 return (void *)(pImage + pImpDesc->Name); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
540 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
541 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
|
542 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
543 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
544 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
545 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
546 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
|
547 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
548 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
549 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
550 * 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
|
551 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
552 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
553 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
|
554 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
555 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
|
556 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
557 modulename = (char *)get_imported_func_info(hInst, funcname, 1); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
558 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
|
559 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
|
560 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
|
561 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
562 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
563 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
564 * 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
|
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 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
567 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
|
568 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
569 return get_imported_func_info(hInst, funcname, 0); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
570 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
571 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
572 |
7 | 573 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
574 # ifndef GETTEXT_DLL | |
575 # 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
|
576 # 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
|
577 # define GETTEXT_DLL_ALT2 "intl.dll" |
7 | 578 # endif |
3622 | 579 /* Dummy functions */ |
36 | 580 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
|
581 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 582 static char *null_libintl_textdomain(const char *); |
583 static char *null_libintl_bindtextdomain(const char *, const char *); | |
584 static char *null_libintl_bind_textdomain_codeset(const char *, const char *); | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
585 static int null_libintl_putenv(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
|
586 static int null_libintl_wputenv(const wchar_t *); |
7 | 587 |
2612 | 588 static HINSTANCE hLibintlDLL = NULL; |
36 | 589 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
|
590 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
|
591 = null_libintl_ngettext; |
36 | 592 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
593 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 594 = null_libintl_bindtextdomain; |
36 | 595 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
596 = null_libintl_bind_textdomain_codeset; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
597 int (*dyn_libintl_putenv)(const char *) = null_libintl_putenv; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
598 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 599 |
600 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
601 dyn_libintl_init(void) |
7 | 602 { |
603 int i; | |
604 static struct | |
605 { | |
606 char *name; | |
607 FARPROC *ptr; | |
608 } libintl_entry[] = | |
609 { | |
610 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
611 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 612 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
613 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
614 {NULL, NULL} | |
615 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
616 HINSTANCE hmsvcrt; |
7 | 617 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
618 // 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
|
619 if (hLibintlDLL != NULL) |
7 | 620 return 1; |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
621 // 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
|
622 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
623 #ifdef GETTEXT_DLL_ALT1 |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
624 if (!hLibintlDLL) |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
625 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT1); |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
626 #endif |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
627 #ifdef GETTEXT_DLL_ALT2 |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
628 if (!hLibintlDLL) |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
629 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
630 #endif |
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
631 if (!hLibintlDLL) |
7 | 632 { |
2612 | 633 if (p_verbose > 0) |
7 | 634 { |
2612 | 635 verbose_enter(); |
636 EMSG2(_(e_loadlib), GETTEXT_DLL); | |
637 verbose_leave(); | |
7 | 638 } |
2612 | 639 return 0; |
7 | 640 } |
641 for (i = 0; libintl_entry[i].name != NULL | |
642 && libintl_entry[i].ptr != NULL; ++i) | |
643 { | |
644 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
645 libintl_entry[i].name)) == NULL) | |
646 { | |
647 dyn_libintl_end(); | |
648 if (p_verbose > 0) | |
292 | 649 { |
650 verbose_enter(); | |
7 | 651 EMSG2(_(e_loadfunc), libintl_entry[i].name); |
292 | 652 verbose_leave(); |
653 } | |
7 | 654 return 0; |
655 } | |
656 } | |
36 | 657 |
658 /* The bind_textdomain_codeset() function is optional. */ | |
323 | 659 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 660 "bind_textdomain_codeset"); |
661 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
662 dyn_libintl_bind_textdomain_codeset = | |
663 null_libintl_bind_textdomain_codeset; | |
664 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
665 /* _putenv() function for the libintl.dll is optional. */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
666 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
|
667 if (hmsvcrt != NULL) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
668 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
669 dyn_libintl_putenv = (void *)GetProcAddress(hmsvcrt, "_putenv"); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
670 dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
671 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
672 if (dyn_libintl_putenv == NULL || dyn_libintl_putenv == _putenv) |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
673 dyn_libintl_putenv = null_libintl_putenv; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
674 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
|
675 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
|
676 |
7 | 677 return 1; |
678 } | |
679 | |
680 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
681 dyn_libintl_end(void) |
7 | 682 { |
683 if (hLibintlDLL) | |
684 FreeLibrary(hLibintlDLL); | |
685 hLibintlDLL = NULL; | |
686 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
|
687 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 688 dyn_libintl_textdomain = null_libintl_textdomain; |
689 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 690 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
691 dyn_libintl_putenv = null_libintl_putenv; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
692 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 693 } |
694 | |
695 static char * | |
26 | 696 null_libintl_gettext(const char *msgid) |
7 | 697 { |
698 return (char*)msgid; | |
699 } | |
700 | |
701 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
702 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
703 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
704 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
705 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
706 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
707 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
|
708 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
709 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 const char *dirname UNUSED) |
7 | 714 { |
715 return NULL; | |
716 } | |
717 | |
718 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
|
719 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
|
720 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
|
721 const char *codeset UNUSED) |
36 | 722 { |
723 return NULL; | |
724 } | |
725 | |
726 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
|
727 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 728 { |
729 return NULL; | |
730 } | |
731 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
732 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
|
733 null_libintl_putenv(const char *envstring UNUSED) |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
734 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
735 return 0; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
736 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
737 |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
738 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
|
739 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
|
740 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
741 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
|
742 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
743 |
7 | 744 #endif /* DYNAMIC_GETTEXT */ |
745 | |
746 /* This symbol is not defined in older versions of the SDK or Visual C++ */ | |
747 | |
748 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
749 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
750 #endif | |
751 | |
752 DWORD g_PlatformId; | |
753 | |
754 #ifdef HAVE_ACL | |
3927 | 755 # ifndef PROTO |
756 # include <aclapi.h> | |
757 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
758 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
759 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
760 # endif |
7 | 761 #endif |
762 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
763 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
764 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
765 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
766 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
767 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
768 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
769 { |
5590 | 770 BOOL bResult; |
771 LUID luid; | |
772 HANDLE hToken; | |
773 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
774 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
775 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
776 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
777 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
778 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
779 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
780 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
781 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
782 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
783 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
784 |
6047 | 785 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
786 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
787 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
788 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
789 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
790 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
791 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
792 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
793 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
794 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
795 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
796 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
797 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
798 |
7 | 799 /* |
800 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
801 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
802 */ | |
803 void | |
804 PlatformId(void) | |
805 { | |
806 static int done = FALSE; | |
807 | |
808 if (!done) | |
809 { | |
810 OSVERSIONINFO ovi; | |
811 | |
812 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
813 GetVersionEx(&ovi); | |
814 | |
815 g_PlatformId = ovi.dwPlatformId; | |
816 | |
5633 | 817 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
818 || ovi.dwMajorVersion > 6) | |
819 win8_or_later = TRUE; | |
820 | |
7 | 821 #ifdef HAVE_ACL |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
822 /* Enable privilege for getting or setting SACLs. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
823 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 824 #endif |
825 done = TRUE; | |
826 } | |
827 } | |
828 | |
829 #ifndef FEAT_GUI_W32 | |
830 | |
831 #define SHIFT (SHIFT_PRESSED) | |
832 #define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) | |
833 #define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) | |
834 #define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) | |
835 | |
836 | |
837 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. | |
838 * We map function keys to their ANSI terminal equivalents, as produced | |
839 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any | |
840 * ANSI key with a value >= '\300' is nonstandard, but provided anyway | |
841 * so that the user can have access to all SHIFT-, CTRL-, and ALT- | |
842 * combinations of function/arrow/etc keys. | |
843 */ | |
844 | |
297 | 845 static const struct |
7 | 846 { |
847 WORD wVirtKey; | |
848 BOOL fAnsiKey; | |
849 int chAlone; | |
850 int chShift; | |
851 int chCtrl; | |
852 int chAlt; | |
853 } VirtKeyMap[] = | |
854 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
855 // Key ANSI alone shift ctrl alt |
7 | 856 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, |
857 | |
858 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
859 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
860 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
861 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
862 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
863 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
864 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
865 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
866 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
867 { 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
|
868 { 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
|
869 { 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
|
870 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
871 { 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
|
872 { 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
|
873 { 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
|
874 { 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
|
875 { 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
|
876 { 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
|
877 { 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
|
878 { 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
|
879 { 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
|
880 { VK_DELETE,TRUE, 'S', '\327', '\330', '\331', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
881 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
882 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, // PrtScrn |
7 | 883 |
884 #if 0 | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
885 // 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
|
886 { 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
|
887 { 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
|
888 { 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
|
889 { 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
|
890 { 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
|
891 { 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
|
892 { 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
|
893 { VK_F20, TRUE, '\366', '\367', '\370', '\371', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
894 #endif |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
895 { 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
|
896 { 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
|
897 // { 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
|
898 { 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
|
899 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
900 { 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
|
901 { 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
|
902 { 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
|
903 { 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
|
904 { 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
|
905 { 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
|
906 { 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
|
907 { 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
|
908 { 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
|
909 // Sorry, out of number space! <negri> |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
910 { VK_NUMPAD9,TRUE, '\376', '\377', '\377', '\367', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
911 |
7 | 912 }; |
913 | |
914 | |
915 #ifdef _MSC_VER | |
916 // The ToAscii bug destroys several registers. Need to turn off optimization | |
917 // or the GetConsoleKeyboardLayoutName hack will fail in non-debug versions | |
797 | 918 # pragma warning(push) |
919 # pragma warning(disable: 4748) | |
7 | 920 # pragma optimize("", off) |
921 #endif | |
922 | |
923 #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
924 # define UChar UnicodeChar |
7 | 925 #else |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
926 # define UChar uChar.UnicodeChar |
7 | 927 #endif |
928 | |
929 /* The return code indicates key code size. */ | |
930 static int | |
931 #ifdef __BORLANDC__ | |
932 __stdcall | |
933 #endif | |
934 win32_kbd_patch_key( | |
26 | 935 KEY_EVENT_RECORD *pker) |
7 | 936 { |
937 UINT uMods = pker->dwControlKeyState; | |
938 static int s_iIsDead = 0; | |
939 static WORD awAnsiCode[2]; | |
940 static BYTE abKeystate[256]; | |
941 | |
942 | |
943 if (s_iIsDead == 2) | |
944 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
945 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 946 s_iIsDead = 0; |
947 return 1; | |
948 } | |
949 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
950 if (pker->UChar != 0) |
7 | 951 return 1; |
952 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
953 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 954 |
955 /* Clear any pending dead keys */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
956 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 957 |
958 if (uMods & SHIFT_PRESSED) | |
959 abKeystate[VK_SHIFT] = 0x80; | |
960 if (uMods & CAPSLOCK_ON) | |
961 abKeystate[VK_CAPITAL] = 1; | |
962 | |
963 if ((uMods & ALT_GR) == ALT_GR) | |
964 { | |
965 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
966 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
967 } | |
968 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
969 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
|
970 abKeystate, awAnsiCode, 2, 0); |
7 | 971 |
972 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
973 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 974 |
975 return s_iIsDead; | |
976 } | |
977 | |
978 #ifdef _MSC_VER | |
979 /* MUST switch optimization on again here, otherwise a call to | |
980 * decode_key_event() may crash (e.g. when hitting caps-lock) */ | |
981 # pragma optimize("", on) | |
797 | 982 # pragma warning(pop) |
7 | 983 |
984 # if (_MSC_VER < 1100) | |
985 /* MUST turn off global optimisation for this next function, or | |
986 * pressing ctrl-minus in insert mode crashes Vim when built with | |
987 * VC4.1. -- negri. */ | |
988 # pragma optimize("g", off) | |
989 # endif | |
990 #endif | |
991 | |
992 static BOOL g_fJustGotFocus = FALSE; | |
993 | |
994 /* | |
995 * Decode a KEY_EVENT into one or two keystrokes | |
996 */ | |
997 static BOOL | |
998 decode_key_event( | |
999 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1000 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1001 WCHAR *pch2, |
7 | 1002 int *pmodifiers, |
1003 BOOL fDoPost) | |
1004 { | |
1005 int i; | |
1006 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
1007 | |
1008 *pch = *pch2 = NUL; | |
1009 g_fJustGotFocus = FALSE; | |
1010 | |
1011 /* ignore key up events */ | |
1012 if (!pker->bKeyDown) | |
1013 return FALSE; | |
1014 | |
1015 /* ignore some keystrokes */ | |
1016 switch (pker->wVirtualKeyCode) | |
1017 { | |
1018 /* modifiers */ | |
1019 case VK_SHIFT: | |
1020 case VK_CONTROL: | |
1021 case VK_MENU: /* Alt key */ | |
1022 return FALSE; | |
1023 | |
1024 default: | |
1025 break; | |
1026 } | |
1027 | |
1028 /* special cases */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1029 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 1030 { |
1031 /* Ctrl-6 is Ctrl-^ */ | |
1032 if (pker->wVirtualKeyCode == '6') | |
1033 { | |
1034 *pch = Ctrl_HAT; | |
1035 return TRUE; | |
1036 } | |
1037 /* Ctrl-2 is Ctrl-@ */ | |
1038 else if (pker->wVirtualKeyCode == '2') | |
1039 { | |
1040 *pch = NUL; | |
1041 return TRUE; | |
1042 } | |
1043 /* Ctrl-- is Ctrl-_ */ | |
1044 else if (pker->wVirtualKeyCode == 0xBD) | |
1045 { | |
1046 *pch = Ctrl__; | |
1047 return TRUE; | |
1048 } | |
1049 } | |
1050 | |
1051 /* Shift-TAB */ | |
1052 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) | |
1053 { | |
1054 *pch = K_NUL; | |
1055 *pch2 = '\017'; | |
1056 return TRUE; | |
1057 } | |
1058 | |
1059 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
1060 { | |
1061 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1062 { | |
1063 if (nModifs == 0) | |
1064 *pch = VirtKeyMap[i].chAlone; | |
1065 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1066 *pch = VirtKeyMap[i].chShift; | |
1067 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1068 *pch = VirtKeyMap[i].chCtrl; | |
1069 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1070 *pch = VirtKeyMap[i].chAlt; | |
1071 | |
1072 if (*pch != 0) | |
1073 { | |
1074 if (VirtKeyMap[i].fAnsiKey) | |
1075 { | |
1076 *pch2 = *pch; | |
1077 *pch = K_NUL; | |
1078 } | |
1079 | |
1080 return TRUE; | |
1081 } | |
1082 } | |
1083 } | |
1084 | |
1085 i = win32_kbd_patch_key(pker); | |
1086 | |
1087 if (i < 0) | |
1088 *pch = NUL; | |
1089 else | |
1090 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1091 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1092 |
1093 if (pmodifiers != NULL) | |
1094 { | |
1095 /* Pass on the ALT key as a modifier, but only when not combined | |
1096 * with CTRL (which is ALTGR). */ | |
1097 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) | |
1098 *pmodifiers |= MOD_MASK_ALT; | |
1099 | |
1100 /* Pass on SHIFT only for special keys, because we don't know when | |
1101 * it's already included with the character. */ | |
1102 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) | |
1103 *pmodifiers |= MOD_MASK_SHIFT; | |
1104 | |
1105 /* Pass on CTRL only for non-special keys, because we don't know | |
1106 * when it's already included with the character. And not when | |
1107 * combined with ALT (which is ALTGR). */ | |
1108 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 | |
1109 && *pch >= 0x20 && *pch < 0x80) | |
1110 *pmodifiers |= MOD_MASK_CTRL; | |
1111 } | |
1112 } | |
1113 | |
1114 return (*pch != NUL); | |
1115 } | |
1116 | |
1117 #ifdef _MSC_VER | |
1118 # pragma optimize("", on) | |
1119 #endif | |
1120 | |
1121 #endif /* FEAT_GUI_W32 */ | |
1122 | |
1123 | |
1124 #ifdef FEAT_MOUSE | |
1125 | |
1126 /* | |
1127 * For the GUI the mouse handling is in gui_w32.c. | |
1128 */ | |
1129 # ifdef FEAT_GUI_W32 | |
1130 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
|
1131 mch_setmouse(int on UNUSED) |
7 | 1132 { |
1133 } | |
1134 # else | |
1135 static int g_fMouseAvail = FALSE; /* mouse present */ | |
1136 static int g_fMouseActive = FALSE; /* mouse enabled */ | |
1137 static int g_nMouseClick = -1; /* mouse status */ | |
1138 static int g_xMouse; /* mouse x coordinate */ | |
1139 static int g_yMouse; /* mouse y coordinate */ | |
1140 | |
1141 /* | |
1142 * Enable or disable mouse input | |
1143 */ | |
1144 void | |
26 | 1145 mch_setmouse(int on) |
7 | 1146 { |
1147 DWORD cmodein; | |
1148 | |
1149 if (!g_fMouseAvail) | |
1150 return; | |
1151 | |
1152 g_fMouseActive = on; | |
1153 GetConsoleMode(g_hConIn, &cmodein); | |
1154 | |
1155 if (g_fMouseActive) | |
1156 cmodein |= ENABLE_MOUSE_INPUT; | |
1157 else | |
1158 cmodein &= ~ENABLE_MOUSE_INPUT; | |
1159 | |
1160 SetConsoleMode(g_hConIn, cmodein); | |
1161 } | |
1162 | |
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
|
1163 |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1164 #if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1165 /* |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1166 * 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
|
1167 */ |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1168 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
|
1169 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
|
1170 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1171 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
|
1172 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1173 #endif |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1174 |
7 | 1175 /* |
1176 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1177 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1178 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1179 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1180 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1181 * and we return the mouse position in g_xMouse and g_yMouse. | |
1182 * | |
1183 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1184 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1185 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1186 * | |
1187 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1188 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1189 * | |
1190 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1191 * moves, even if it stays within the same character cell. We ignore | |
1192 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1193 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1194 * we're only interested in MOUSE_DRAG). | |
1195 * | |
1196 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1197 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1198 * In practice, it's almost impossible to click both at the same time, | |
1199 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1200 * in such cases, if the user is clicking quickly. | |
1201 */ | |
1202 static BOOL | |
1203 decode_mouse_event( | |
26 | 1204 MOUSE_EVENT_RECORD *pmer) |
7 | 1205 { |
1206 static int s_nOldButton = -1; | |
1207 static int s_nOldMouseClick = -1; | |
1208 static int s_xOldMouse = -1; | |
1209 static int s_yOldMouse = -1; | |
1210 static linenr_T s_old_topline = 0; | |
1211 #ifdef FEAT_DIFF | |
1212 static int s_old_topfill = 0; | |
1213 #endif | |
1214 static int s_cClicks = 1; | |
1215 static BOOL s_fReleased = TRUE; | |
1216 static DWORD s_dwLastClickTime = 0; | |
1217 static BOOL s_fNextIsMiddle = FALSE; | |
1218 | |
1219 static DWORD cButtons = 0; /* number of buttons supported */ | |
1220 | |
1221 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1222 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1223 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1224 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1225 | |
1226 int nButton; | |
1227 | |
1228 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1229 cButtons = 2; | |
1230 | |
1231 if (!g_fMouseAvail || !g_fMouseActive) | |
1232 { | |
1233 g_nMouseClick = -1; | |
1234 return FALSE; | |
1235 } | |
1236 | |
1237 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ | |
1238 if (g_fJustGotFocus) | |
1239 { | |
1240 g_fJustGotFocus = FALSE; | |
1241 return FALSE; | |
1242 } | |
1243 | |
1244 /* unprocessed mouse click? */ | |
1245 if (g_nMouseClick != -1) | |
1246 return TRUE; | |
1247 | |
1248 nButton = -1; | |
1249 g_xMouse = pmer->dwMousePosition.X; | |
1250 g_yMouse = pmer->dwMousePosition.Y; | |
1251 | |
1252 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1253 { | |
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
|
1254 /* Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these |
7 | 1255 * events even when the mouse moves only within a char cell.) */ |
1256 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) | |
1257 return FALSE; | |
1258 } | |
1259 | |
1260 /* If no buttons are pressed... */ | |
1261 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) | |
1262 { | |
13416
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1263 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
|
1264 |
7 | 1265 /* If the last thing returned was MOUSE_RELEASE, ignore this */ |
1266 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
|
1267 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1268 #ifdef FEAT_BEVAL_TERM |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1269 /* do return mouse move events when we want them */ |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1270 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
|
1271 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
|
1272 else |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1273 #endif |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1274 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
|
1275 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1276 |
7 | 1277 s_fReleased = TRUE; |
1278 } | |
1279 else /* one or more buttons pressed */ | |
1280 { | |
1281 /* on a 2-button mouse, hold down left and right buttons | |
1282 * simultaneously to get MIDDLE. */ | |
1283 | |
1284 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1285 { | |
1286 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1287 | |
1288 /* if either left or right button only is pressed, see if the | |
4352 | 1289 * next mouse event has both of them pressed */ |
7 | 1290 if (dwLR == LEFT || dwLR == RIGHT) |
1291 { | |
1292 for (;;) | |
1293 { | |
1294 /* wait a short time for next input event */ | |
1295 if (WaitForSingleObject(g_hConIn, p_mouset / 3) | |
1296 != WAIT_OBJECT_0) | |
1297 break; | |
1298 else | |
1299 { | |
1300 DWORD cRecords = 0; | |
1301 INPUT_RECORD ir; | |
1302 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1303 | |
5580 | 1304 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1305 |
1306 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1307 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1308 break; | |
1309 else | |
1310 { | |
1311 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1312 { | |
5580 | 1313 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1314 |
1315 return decode_mouse_event(pmer2); | |
1316 } | |
1317 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1318 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1319 { | |
1320 /* throw away spurious mouse move */ | |
5580 | 1321 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1322 |
1323 /* are there any more mouse events in queue? */ | |
5580 | 1324 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1325 |
1326 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1327 break; | |
1328 } | |
1329 else | |
1330 break; | |
1331 } | |
1332 } | |
1333 } | |
1334 } | |
1335 } | |
1336 | |
1337 if (s_fNextIsMiddle) | |
1338 { | |
1339 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1340 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1341 s_fNextIsMiddle = FALSE; | |
1342 } | |
1343 else if (cButtons == 2 && | |
1344 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1345 { | |
1346 nButton = MOUSE_MIDDLE; | |
1347 | |
1348 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1349 { | |
1350 s_fNextIsMiddle = TRUE; | |
1351 nButton = MOUSE_RELEASE; | |
1352 } | |
1353 } | |
1354 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1355 nButton = MOUSE_LEFT; | |
1356 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1357 nButton = MOUSE_MIDDLE; | |
1358 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1359 nButton = MOUSE_RIGHT; | |
1360 | |
1361 if (! s_fReleased && ! s_fNextIsMiddle | |
1362 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1363 return FALSE; | |
1364 | |
1365 s_fReleased = s_fNextIsMiddle; | |
1366 } | |
1367 | |
1368 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1369 { | |
1370 /* button pressed or released, without mouse moving */ | |
1371 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1372 { | |
1373 DWORD dwCurrentTime = GetTickCount(); | |
1374 | |
1375 if (s_xOldMouse != g_xMouse | |
1376 || s_yOldMouse != g_yMouse | |
1377 || s_nOldButton != nButton | |
1378 || s_old_topline != curwin->w_topline | |
1379 #ifdef FEAT_DIFF | |
1380 || s_old_topfill != curwin->w_topfill | |
1381 #endif | |
1382 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) | |
1383 { | |
1384 s_cClicks = 1; | |
1385 } | |
1386 else if (++s_cClicks > 4) | |
1387 { | |
1388 s_cClicks = 1; | |
1389 } | |
1390 | |
1391 s_dwLastClickTime = dwCurrentTime; | |
1392 } | |
1393 } | |
1394 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1395 { | |
1396 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1397 nButton = MOUSE_DRAG; | |
1398 | |
1399 s_cClicks = 1; | |
1400 } | |
1401 | |
1402 if (nButton == -1) | |
1403 return FALSE; | |
1404 | |
1405 if (nButton != MOUSE_RELEASE) | |
1406 s_nOldButton = nButton; | |
1407 | |
1408 g_nMouseClick = nButton; | |
1409 | |
1410 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1411 g_nMouseClick |= MOUSE_SHIFT; | |
1412 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1413 g_nMouseClick |= MOUSE_CTRL; | |
1414 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1415 g_nMouseClick |= MOUSE_ALT; | |
1416 | |
1417 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1418 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1419 | |
1420 /* only pass on interesting (i.e., different) mouse events */ | |
1421 if (s_xOldMouse == g_xMouse | |
1422 && s_yOldMouse == g_yMouse | |
1423 && s_nOldMouseClick == g_nMouseClick) | |
1424 { | |
1425 g_nMouseClick = -1; | |
1426 return FALSE; | |
1427 } | |
1428 | |
1429 s_xOldMouse = g_xMouse; | |
1430 s_yOldMouse = g_yMouse; | |
1431 s_old_topline = curwin->w_topline; | |
1432 #ifdef FEAT_DIFF | |
1433 s_old_topfill = curwin->w_topfill; | |
1434 #endif | |
1435 s_nOldMouseClick = g_nMouseClick; | |
1436 | |
1437 return TRUE; | |
1438 } | |
1439 | |
1440 # endif /* FEAT_GUI_W32 */ | |
1441 #endif /* FEAT_MOUSE */ | |
1442 | |
1443 | |
1444 #ifdef MCH_CURSOR_SHAPE | |
1445 /* | |
1446 * Set the shape of the cursor. | |
1447 * 'thickness' can be from 1 (thin) to 99 (block) | |
1448 */ | |
1449 static void | |
1450 mch_set_cursor_shape(int thickness) | |
1451 { | |
1452 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1453 ConsoleCursorInfo.dwSize = thickness; | |
1454 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1455 | |
1456 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1457 if (s_cursor_visible) | |
1458 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1459 } | |
1460 | |
1461 void | |
1462 mch_update_cursor(void) | |
1463 { | |
1464 int idx; | |
1465 int thickness; | |
1466 | |
1467 /* | |
1468 * How the cursor is drawn depends on the current mode. | |
1469 */ | |
1470 idx = get_shape_idx(FALSE); | |
1471 | |
1472 if (shape_table[idx].shape == SHAPE_BLOCK) | |
1473 thickness = 99; /* 100 doesn't work on W95 */ | |
1474 else | |
1475 thickness = shape_table[idx].percentage; | |
1476 mch_set_cursor_shape(thickness); | |
1477 } | |
1478 #endif | |
1479 | |
1480 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1481 /* | |
1482 * Handle FOCUS_EVENT. | |
1483 */ | |
1484 static void | |
1485 handle_focus_event(INPUT_RECORD ir) | |
1486 { | |
1487 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1488 ui_focus_change((int)g_fJustGotFocus); | |
1489 } | |
1490 | |
1491 /* | |
1492 * Wait until console input from keyboard or mouse is available, | |
1493 * 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
|
1494 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1495 * Return TRUE if something is available FALSE if not. |
1496 */ | |
1497 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1498 WaitForChar(long msec, int ignore_input) |
7 | 1499 { |
1500 DWORD dwNow = 0, dwEndTime = 0; | |
1501 INPUT_RECORD ir; | |
1502 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1503 WCHAR ch, ch2; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1504 #ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1505 int tb_change_cnt = typebuf.tb_change_cnt; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1506 #endif |
7 | 1507 |
1508 if (msec > 0) | |
1509 /* Wait until the specified time has elapsed. */ | |
1510 dwEndTime = GetTickCount() + msec; | |
1511 else if (msec < 0) | |
1512 /* Wait forever. */ | |
1513 dwEndTime = INFINITE; | |
1514 | |
1515 /* We need to loop until the end of the time period, because | |
1516 * we might get multiple unusable mouse events in that time. | |
1517 */ | |
1518 for (;;) | |
1519 { | |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1520 // 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
|
1521 if (msec != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1522 { |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1523 #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
|
1524 parse_queued_messages(); |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1525 #endif |
14 | 1526 #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
|
1527 mzvim_check_threads(); |
14 | 1528 #endif |
7 | 1529 #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
|
1530 serverProcessPendingMessages(); |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1531 #endif |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1532 } |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1533 |
7 | 1534 if (0 |
1535 #ifdef FEAT_MOUSE | |
1536 || g_nMouseClick != -1 | |
1537 #endif | |
1538 #ifdef FEAT_CLIENTSERVER | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1539 || (!ignore_input && input_available()) |
7 | 1540 #endif |
1541 ) | |
1542 return TRUE; | |
1543 | |
1544 if (msec > 0) | |
1545 { | |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1546 /* If the specified wait time has passed, return. Beware that |
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1547 * GetTickCount() may wrap around (overflow). */ |
7 | 1548 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1549 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1550 break; |
1551 } | |
1552 if (msec != 0) | |
1553 { | |
14 | 1554 DWORD dwWaitTime = dwEndTime - dwNow; |
1555 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
1556 #ifdef FEAT_JOB_CHANNEL |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1557 /* Check channel while waiting for input. */ |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1558 if (dwWaitTime > 100) |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1559 { |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1560 dwWaitTime = 100; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1561 /* If there is readahead then parse_queued_messages() timed out |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1562 * and we should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1563 if (channel_any_readahead()) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1564 dwWaitTime = 10; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1565 } |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1566 #endif |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12724
diff
changeset
|
1567 #ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1568 if (p_beval && dwWaitTime > 100) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1569 /* The 'balloonexpr' may indirectly invoke a callback while |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1570 * waiting for a character, need to check often. */ |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1571 dwWaitTime = 100; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1572 #endif |
14 | 1573 #ifdef FEAT_MZSCHEME |
1574 if (mzthreads_allowed() && p_mzq > 0 | |
1575 && (msec < 0 || (long)dwWaitTime > p_mzq)) | |
1576 dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ | |
1577 #endif | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1578 #ifdef FEAT_TIMERS |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1579 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1580 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1581 |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1582 /* When waiting very briefly don't trigger timers. */ |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1583 if (dwWaitTime > 10) |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1584 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1585 /* Trigger timers and then get the time in msec until the |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1586 * next one is due. Wait up to that time. */ |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1587 due_time = check_due_timer(); |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1588 if (typebuf.tb_change_cnt != tb_change_cnt) |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1589 { |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1590 /* timer may have used feedkeys() */ |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1591 return FALSE; |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1592 } |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1593 if (due_time > 0 && dwWaitTime > (DWORD)due_time) |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1594 dwWaitTime = due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1595 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1596 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1597 #endif |
7 | 1598 #ifdef FEAT_CLIENTSERVER |
1599 /* Wait for either an event on the console input or a message in | |
1600 * the client-server window. */ | |
6981 | 1601 if (msg_wait_for_multiple_objects(1, &g_hConIn, FALSE, |
14 | 1602 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0) |
7 | 1603 #else |
6981 | 1604 if (wait_for_single_object(g_hConIn, dwWaitTime) != WAIT_OBJECT_0) |
7 | 1605 #endif |
1606 continue; | |
1607 } | |
1608 | |
1609 cRecords = 0; | |
5580 | 1610 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1611 |
1612 #ifdef FEAT_MBYTE_IME | |
1613 if (State & CMDLINE && msg_row == Rows - 1) | |
1614 { | |
1615 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1616 | |
1617 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1618 { | |
1619 if (csbi.dwCursorPosition.Y != msg_row) | |
1620 { | |
1621 /* The screen is now messed up, must redraw the | |
1622 * command line and later all the windows. */ | |
1623 redraw_all_later(CLEAR); | |
1624 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); | |
1625 redrawcmd(); | |
1626 } | |
1627 } | |
1628 } | |
1629 #endif | |
1630 | |
1631 if (cRecords > 0) | |
1632 { | |
1633 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1634 { | |
1635 #ifdef FEAT_MBYTE_IME | |
1636 /* Windows IME sends two '\n's with only one 'ENTER'. First: | |
1637 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1638 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1639 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1640 { | |
5580 | 1641 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1642 continue; |
1643 } | |
1644 #endif | |
1645 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, | |
1646 NULL, FALSE)) | |
1647 return TRUE; | |
1648 } | |
1649 | |
5580 | 1650 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1651 |
1652 if (ir.EventType == FOCUS_EVENT) | |
1653 handle_focus_event(ir); | |
1654 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
|
1655 { |
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1656 /* Only call shell_resized() when the size actually change to |
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1657 * avoid the screen is cleard. */ |
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1658 if (ir.Event.WindowBufferSizeEvent.dwSize.X != Columns |
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1659 || ir.Event.WindowBufferSizeEvent.dwSize.Y != Rows) |
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1660 shell_resized(); |
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1661 } |
7 | 1662 #ifdef FEAT_MOUSE |
1663 else if (ir.EventType == MOUSE_EVENT | |
1664 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1665 return TRUE; | |
1666 #endif | |
1667 } | |
1668 else if (msec == 0) | |
1669 break; | |
1670 } | |
1671 | |
1672 #ifdef FEAT_CLIENTSERVER | |
1673 /* Something might have been received while we were waiting. */ | |
1674 if (input_available()) | |
1675 return TRUE; | |
1676 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1677 |
7 | 1678 return FALSE; |
1679 } | |
1680 | |
1681 #ifndef FEAT_GUI_MSWIN | |
1682 /* | |
1683 * return non-zero if a character is available | |
1684 */ | |
1685 int | |
26 | 1686 mch_char_avail(void) |
7 | 1687 { |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1688 return WaitForChar(0L, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1689 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1690 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1691 # 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
|
1692 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1693 * 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
|
1694 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1695 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1696 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1697 { |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1698 return WaitForChar(0L, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1699 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1700 # endif |
7 | 1701 #endif |
1702 | |
1703 /* | |
1704 * Create the console input. Used when reading stdin doesn't work. | |
1705 */ | |
1706 static void | |
1707 create_conin(void) | |
1708 { | |
1709 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1710 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1711 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1712 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1713 did_create_conin = TRUE; |
1714 } | |
1715 | |
1716 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1717 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1718 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1719 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1720 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1721 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1722 WCHAR ch; |
7 | 1723 |
1724 for (;;) | |
1725 { | |
1726 INPUT_RECORD ir; | |
1727 DWORD cRecords = 0; | |
1728 | |
1729 #ifdef FEAT_CLIENTSERVER | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1730 (void)WaitForChar(-1L, FALSE); |
7 | 1731 if (input_available()) |
1732 return 0; | |
1733 # ifdef FEAT_MOUSE | |
1734 if (g_nMouseClick != -1) | |
1735 return 0; | |
1736 # endif | |
1737 #endif | |
5580 | 1738 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1739 { |
1740 if (did_create_conin) | |
1741 read_error_exit(); | |
1742 create_conin(); | |
1743 continue; | |
1744 } | |
1745 | |
1746 if (ir.EventType == KEY_EVENT) | |
1747 { | |
1748 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1749 pmodifiers, TRUE)) | |
1750 return ch; | |
1751 } | |
1752 else if (ir.EventType == FOCUS_EVENT) | |
1753 handle_focus_event(ir); | |
1754 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1755 shell_resized(); | |
1756 #ifdef FEAT_MOUSE | |
1757 else if (ir.EventType == MOUSE_EVENT) | |
1758 { | |
1759 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1760 return 0; | |
1761 } | |
1762 #endif | |
1763 } | |
1764 } | |
1765 #endif /* !FEAT_GUI_W32 */ | |
1766 | |
1767 | |
1768 /* | |
3622 | 1769 * mch_inchar(): low-level input function. |
7 | 1770 * Get one or more characters from the keyboard or the mouse. |
1771 * If time == 0, do not wait for characters. | |
1772 * If time == n, wait a short time for characters. | |
1773 * If time == -1, wait forever for characters. | |
1774 * Returns the number of characters read into buf. | |
1775 */ | |
1776 int | |
1777 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
|
1778 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
|
1779 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
|
1780 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
|
1781 int tb_change_cnt UNUSED) |
7 | 1782 { |
1783 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1784 | |
1785 int len; | |
1786 int c; | |
1787 #define TYPEAHEADLEN 20 | |
1788 static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ | |
1789 static int typeaheadlen = 0; | |
1790 | |
1791 /* First use any typeahead that was kept because "buf" was too small. */ | |
1792 if (typeaheadlen > 0) | |
1793 goto theend; | |
1794 | |
1795 if (time >= 0) | |
1796 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1797 if (!WaitForChar(time, FALSE)) /* no character available */ |
7 | 1798 return 0; |
1799 } | |
1800 else /* time == -1, wait forever */ | |
1801 { | |
1802 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
1803 | |
203 | 1804 /* |
1805 * If there is no character available within 2 seconds (default) | |
1806 * write the autoscript file to disk. Or cause the CursorHold event | |
1807 * to be triggered. | |
1808 */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1809 if (!WaitForChar(p_ut, FALSE)) |
7 | 1810 { |
609 | 1811 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1812 { |
203 | 1813 buf[0] = K_SPECIAL; |
1814 buf[1] = KS_EXTRA; | |
1815 buf[2] = (int)KE_CURSORHOLD; | |
1816 return 3; | |
7 | 1817 } |
368 | 1818 before_blocking(); |
7 | 1819 } |
1820 } | |
1821 | |
1822 /* | |
1823 * Try to read as many characters as there are, until the buffer is full. | |
1824 */ | |
1825 | |
1826 /* we will get at least one key. Get more if they are available. */ | |
1827 g_fCBrkPressed = FALSE; | |
1828 | |
1829 #ifdef MCH_WRITE_DUMP | |
1830 if (fdDump) | |
1831 fputc('[', fdDump); | |
1832 #endif | |
1833 | |
1834 /* Keep looping until there is something in the typeahead buffer and more | |
1835 * to get and still room in the buffer (up to two bytes for a char and | |
1836 * 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
|
1837 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) |
7 | 1838 && typeaheadlen + 5 <= TYPEAHEADLEN) |
1839 { | |
1840 if (typebuf_changed(tb_change_cnt)) | |
1841 { | |
1842 /* "buf" may be invalid now if a client put something in the | |
1843 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1844 typeaheadlen = 0; | |
1845 break; | |
1846 } | |
1847 #ifdef FEAT_MOUSE | |
1848 if (g_nMouseClick != -1) | |
1849 { | |
1850 # ifdef MCH_WRITE_DUMP | |
1851 if (fdDump) | |
1852 fprintf(fdDump, "{%02x @ %d, %d}", | |
1853 g_nMouseClick, g_xMouse, g_yMouse); | |
1854 # endif | |
1855 typeahead[typeaheadlen++] = ESC + 128; | |
1856 typeahead[typeaheadlen++] = 'M'; | |
1857 typeahead[typeaheadlen++] = g_nMouseClick; | |
1858 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1859 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1860 g_nMouseClick = -1; | |
1861 } | |
1862 else | |
1863 #endif | |
1864 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1865 WCHAR ch2 = NUL; |
7 | 1866 int modifiers = 0; |
1867 | |
1868 c = tgetch(&modifiers, &ch2); | |
1869 | |
1870 if (typebuf_changed(tb_change_cnt)) | |
1871 { | |
1872 /* "buf" may be invalid now if a client put something in the | |
1873 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1874 typeaheadlen = 0; | |
1875 break; | |
1876 } | |
1877 | |
1878 if (c == Ctrl_C && ctrl_c_interrupts) | |
1879 { | |
1880 #if defined(FEAT_CLIENTSERVER) | |
1881 trash_input_buf(); | |
1882 #endif | |
1883 got_int = TRUE; | |
1884 } | |
1885 | |
1886 #ifdef FEAT_MOUSE | |
1887 if (g_nMouseClick == -1) | |
1888 #endif | |
1889 { | |
1890 int n = 1; | |
6047 | 1891 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1892 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1893 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1894 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1895 int i; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1896 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1897 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1898 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1899 ch[0] = c; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1900 if (c >= 0xD800 && c <= 0xDBFF) /* High surrogate */ |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1901 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1902 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1903 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1904 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1905 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1906 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1907 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1908 for (i = 0; i < n; i++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1909 typeahead[typeaheadlen + i] = p[i]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1910 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1911 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1912 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1913 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1914 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1915 typeahead[typeaheadlen] = c; |
7 | 1916 if (ch2 != NUL) |
1917 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1918 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
|
1919 { |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1920 switch (ch2) |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1921 { |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1922 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
|
1923 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
|
1924 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
|
1925 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
|
1926 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
|
1927 n++; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1928 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1929 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1930 default: |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1931 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
|
1932 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
|
1933 n += 2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1934 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1935 } |
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
|
1936 } |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1937 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
|
1938 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1939 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
|
1940 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
|
1941 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
|
1942 } |
6047 | 1943 } |
1944 | |
7 | 1945 /* Use the ALT key to set the 8th bit of the character |
1946 * when it's one byte, the 8th bit isn't set yet and not | |
1947 * using a double-byte encoding (would become a lead | |
1948 * byte). */ | |
1949 if ((modifiers & MOD_MASK_ALT) | |
1950 && n == 1 | |
1951 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1952 #ifdef FEAT_MBYTE | |
1953 && !enc_dbcs | |
1954 #endif | |
1955 ) | |
1956 { | |
1443 | 1957 #ifdef FEAT_MBYTE |
1958 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, | |
1959 typeahead + typeaheadlen); | |
1960 #else | |
7 | 1961 typeahead[typeaheadlen] |= 0x80; |
1443 | 1962 #endif |
7 | 1963 modifiers &= ~MOD_MASK_ALT; |
1964 } | |
1965 | |
1966 if (modifiers != 0) | |
1967 { | |
1968 /* Prepend modifiers to the character. */ | |
1969 mch_memmove(typeahead + typeaheadlen + 3, | |
1970 typeahead + typeaheadlen, n); | |
1971 typeahead[typeaheadlen++] = K_SPECIAL; | |
1972 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
1973 typeahead[typeaheadlen++] = modifiers; | |
1974 } | |
1975 | |
1976 typeaheadlen += n; | |
1977 | |
1978 #ifdef MCH_WRITE_DUMP | |
1979 if (fdDump) | |
1980 fputc(c, fdDump); | |
1981 #endif | |
1982 } | |
1983 } | |
1984 } | |
1985 | |
1986 #ifdef MCH_WRITE_DUMP | |
1987 if (fdDump) | |
1988 { | |
1989 fputs("]\n", fdDump); | |
1990 fflush(fdDump); | |
1991 } | |
1992 #endif | |
1993 | |
1994 theend: | |
1995 /* Move typeahead to "buf", as much as fits. */ | |
1996 len = 0; | |
1997 while (len < maxlen && typeaheadlen > 0) | |
1998 { | |
1999 buf[len++] = typeahead[0]; | |
2000 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
2001 } | |
2002 return len; | |
2003 | |
2004 #else /* FEAT_GUI_W32 */ | |
2005 return 0; | |
2006 #endif /* FEAT_GUI_W32 */ | |
2007 } | |
2008 | |
3927 | 2009 #ifndef PROTO |
2010 # ifndef __MINGW32__ | |
2011 # include <shellapi.h> /* required for FindExecutable() */ | |
2012 # endif | |
7 | 2013 #endif |
2014 | |
9 | 2015 /* |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2016 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH. |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2017 * If "use_path" is FALSE: Return TRUE if "name" exists. |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2018 * 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
|
2019 * the allocated memory. |
10 | 2020 * TODO: Should somehow check if it's really executable. |
9 | 2021 */ |
7 | 2022 static int |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2023 executable_exists(char *name, char_u **path, int use_path) |
7 | 2024 { |
9 | 2025 char *dum; |
2026 char fname[_MAX_PATH]; | |
6185 | 2027 char *curpath, *newpath; |
2028 long n; | |
9 | 2029 |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2030 if (!use_path) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2031 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2032 if (mch_getperm((char_u *)name) != -1 && !mch_isdir((char_u *)name)) |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2033 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2034 if (path != NULL) |
11060
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2035 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2036 if (mch_isFullName((char_u *)name)) |
11060
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2037 *path = vim_strsave((char_u *)name); |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2038 else |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2039 *path = FullName_save((char_u *)name, FALSE); |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2040 } |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2041 return TRUE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2042 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2043 return FALSE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2044 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2045 |
9 | 2046 #ifdef FEAT_MBYTE |
2047 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
7 | 2048 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2049 WCHAR *p = enc_to_utf16((char_u *)name, NULL); |
9 | 2050 WCHAR fnamew[_MAX_PATH]; |
2051 WCHAR *dumw; | |
6185 | 2052 WCHAR *wcurpath, *wnewpath; |
9 | 2053 |
2054 if (p != NULL) | |
2055 { | |
6185 | 2056 wcurpath = _wgetenv(L"PATH"); |
2057 wnewpath = (WCHAR*)alloc((unsigned)(wcslen(wcurpath) + 3) | |
2058 * sizeof(WCHAR)); | |
2059 if (wnewpath == NULL) | |
2060 return FALSE; | |
2061 wcscpy(wnewpath, L".;"); | |
2062 wcscat(wnewpath, wcurpath); | |
2063 n = (long)SearchPathW(wnewpath, p, NULL, _MAX_PATH, fnamew, &dumw); | |
2064 vim_free(wnewpath); | |
9 | 2065 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2066 if (n == 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2067 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2068 if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2069 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2070 if (path != NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2071 *path = utf16_to_enc(fnamew, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2072 return TRUE; |
9 | 2073 } |
7 | 2074 } |
9 | 2075 #endif |
6185 | 2076 |
2077 curpath = getenv("PATH"); | |
2078 newpath = (char*)alloc((unsigned)(STRLEN(curpath) + 3)); | |
2079 if (newpath == NULL) | |
2080 return FALSE; | |
2081 STRCPY(newpath, ".;"); | |
2082 STRCAT(newpath, curpath); | |
2083 n = (long)SearchPath(newpath, name, NULL, _MAX_PATH, fname, &dum); | |
2084 vim_free(newpath); | |
2085 if (n == 0) | |
9 | 2086 return FALSE; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2087 if (mch_isdir((char_u *)fname)) |
9 | 2088 return FALSE; |
5782 | 2089 if (path != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2090 *path = vim_strsave((char_u *)fname); |
9 | 2091 return TRUE; |
7 | 2092 } |
2093 | |
2584 | 2094 #if ((defined(__MINGW32__) || defined (__CYGWIN32__)) && \ |
2935 | 2095 __MSVCRT_VERSION__ >= 0x800) || (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 2096 /* |
2097 * Bad parameter handler. | |
2098 * | |
2099 * Certain MS CRT functions will intentionally crash when passed invalid | |
2100 * parameters to highlight possible security holes. Setting this function as | |
2101 * the bad parameter handler will prevent the crash. | |
2102 * | |
2103 * In debug builds the parameters contain CRT information that might help track | |
2104 * down the source of a problem, but in non-debug builds the arguments are all | |
2105 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
2106 * worth allowing these to make debugging of issues easier. | |
2107 */ | |
2108 static void | |
2109 bad_param_handler(const wchar_t *expression, | |
2110 const wchar_t *function, | |
2111 const wchar_t *file, | |
2112 unsigned int line, | |
2113 uintptr_t pReserved) | |
2114 { | |
2115 } | |
2116 | |
2117 # define SET_INVALID_PARAM_HANDLER \ | |
2118 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2119 #else | |
2120 # define SET_INVALID_PARAM_HANDLER | |
2121 #endif | |
2122 | |
7 | 2123 #ifdef FEAT_GUI_W32 |
2124 | |
2125 /* | |
2126 * GUI version of mch_init(). | |
2127 */ | |
2128 void | |
26 | 2129 mch_init(void) |
7 | 2130 { |
2131 #ifndef __MINGW32__ | |
2132 extern int _fmode; | |
2133 #endif | |
2134 | |
2584 | 2135 /* Silently handle invalid parameters to CRT functions */ |
2136 SET_INVALID_PARAM_HANDLER; | |
2137 | |
7 | 2138 /* Let critical errors result in a failure, not in a dialog box. Required |
2139 * for the timestamp test to work on removed floppies. */ | |
2140 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2141 | |
2142 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2143 | |
2144 /* Specify window size. Is there a place to get the default from? */ | |
2145 Rows = 25; | |
2146 Columns = 80; | |
2147 | |
2148 /* Look for 'vimrun' */ | |
2149 { | |
2150 char_u vimrun_location[_MAX_PATH + 4]; | |
2151 | |
2152 /* First try in same directory as gvim.exe */ | |
2153 STRCPY(vimrun_location, exe_name); | |
2154 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2155 if (mch_getperm(vimrun_location) >= 0) | |
2156 { | |
2157 if (*skiptowhite(vimrun_location) != NUL) | |
2158 { | |
2159 /* Enclose path with white space in double quotes. */ | |
2160 mch_memmove(vimrun_location + 1, vimrun_location, | |
2161 STRLEN(vimrun_location) + 1); | |
2162 *vimrun_location = '"'; | |
2163 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2164 } | |
2165 else | |
2166 STRCPY(gettail(vimrun_location), "vimrun "); | |
2167 | |
2168 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2169 s_dont_use_vimrun = FALSE; | |
2170 } | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2171 else if (executable_exists("vimrun.exe", NULL, TRUE)) |
7 | 2172 s_dont_use_vimrun = FALSE; |
2173 | |
2174 /* Don't give the warning for a missing vimrun.exe right now, but only | |
2175 * when vimrun was supposed to be used. Don't bother people that do | |
2176 * not need vimrun.exe. */ | |
2177 if (s_dont_use_vimrun) | |
2178 need_vimrun_warning = TRUE; | |
2179 } | |
2180 | |
2181 /* | |
2182 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2183 * Otherwise the default "findstr /n" is used. | |
2184 */ | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2185 if (!executable_exists("findstr.exe", NULL, TRUE)) |
7 | 2186 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
2187 | |
2188 #ifdef FEAT_CLIPBOARD | |
4168 | 2189 win_clip_init(); |
7 | 2190 #endif |
2191 } | |
2192 | |
2193 | |
2194 #else /* FEAT_GUI_W32 */ | |
2195 | |
2196 #define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) | |
2197 #define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) | |
2198 | |
2199 /* | |
2200 * ClearConsoleBuffer() | |
2201 * Description: | |
2202 * Clears the entire contents of the console screen buffer, using the | |
2203 * specified attribute. | |
2204 * Returns: | |
2205 * TRUE on success | |
2206 */ | |
2207 static BOOL | |
2208 ClearConsoleBuffer(WORD wAttribute) | |
2209 { | |
2210 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2211 COORD coord; | |
2212 DWORD NumCells, dummy; | |
2213 | |
2214 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2215 return FALSE; | |
2216 | |
2217 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2218 coord.X = 0; | |
2219 coord.Y = 0; | |
2220 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2221 coord, &dummy)) | |
2222 { | |
2223 return FALSE; | |
2224 } | |
2225 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2226 coord, &dummy)) | |
2227 { | |
2228 return FALSE; | |
2229 } | |
2230 | |
2231 return TRUE; | |
2232 } | |
2233 | |
2234 /* | |
2235 * FitConsoleWindow() | |
2236 * Description: | |
2237 * Checks if the console window will fit within given buffer dimensions. | |
2238 * Also, if requested, will shrink the window to fit. | |
2239 * Returns: | |
2240 * TRUE on success | |
2241 */ | |
2242 static BOOL | |
2243 FitConsoleWindow( | |
2244 COORD dwBufferSize, | |
2245 BOOL WantAdjust) | |
2246 { | |
2247 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2248 COORD dwWindowSize; | |
2249 BOOL NeedAdjust = FALSE; | |
2250 | |
2251 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2252 { | |
2253 /* | |
2254 * A buffer resize will fail if the current console window does | |
2255 * not lie completely within that buffer. To avoid this, we might | |
2256 * have to move and possibly shrink the window. | |
2257 */ | |
2258 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2259 { | |
2260 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2261 if (dwWindowSize.X > dwBufferSize.X) | |
2262 dwWindowSize.X = dwBufferSize.X; | |
2263 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2264 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2265 NeedAdjust = TRUE; | |
2266 } | |
2267 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2268 { | |
2269 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2270 if (dwWindowSize.Y > dwBufferSize.Y) | |
2271 dwWindowSize.Y = dwBufferSize.Y; | |
2272 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2273 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2274 NeedAdjust = TRUE; | |
2275 } | |
2276 if (NeedAdjust && WantAdjust) | |
2277 { | |
2278 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2279 return FALSE; | |
2280 } | |
2281 return TRUE; | |
2282 } | |
2283 | |
2284 return FALSE; | |
2285 } | |
2286 | |
2287 typedef struct ConsoleBufferStruct | |
2288 { | |
26 | 2289 BOOL IsValid; |
2290 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2291 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2292 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
|
2293 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
|
2294 int NumRegions; |
7 | 2295 } ConsoleBuffer; |
2296 | |
2297 /* | |
2298 * SaveConsoleBuffer() | |
2299 * Description: | |
2300 * Saves important information about the console buffer, including the | |
2301 * actual buffer contents. The saved information is suitable for later | |
2302 * restoration by RestoreConsoleBuffer(). | |
2303 * Returns: | |
2304 * TRUE if all information was saved; FALSE otherwise | |
2305 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2306 */ | |
2307 static BOOL | |
2308 SaveConsoleBuffer( | |
2309 ConsoleBuffer *cb) | |
2310 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2311 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2312 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2313 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2314 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
|
2315 int i, numregions; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2316 |
7 | 2317 if (cb == NULL) |
2318 return FALSE; | |
2319 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2320 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2321 { |
2322 cb->IsValid = FALSE; | |
2323 return FALSE; | |
2324 } | |
2325 cb->IsValid = TRUE; | |
2326 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2327 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2328 * 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
|
2329 * 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
|
2330 * 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
|
2331 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2332 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2333 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
|
2334 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
|
2335 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2336 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
|
2337 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
|
2338 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
|
2339 vim_free(cb->Buffer); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2340 cb->Buffer = (PCHAR_INFO)alloc(NumCells * sizeof(CHAR_INFO)); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2341 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2342 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2343 } |
7 | 2344 |
2345 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2346 * 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
|
2347 * 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
|
2348 * 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
|
2349 * 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
|
2350 * 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
|
2351 * 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
|
2352 * height of each chunk will be (12000 / width). |
7 | 2353 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2354 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2355 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2356 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
|
2357 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
|
2358 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2359 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
|
2360 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
|
2361 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2362 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
|
2363 vim_free(cb->Regions); |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2364 cb->Regions = (PSMALL_RECT)alloc(cb->NumRegions * sizeof(SMALL_RECT)); |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2365 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
|
2366 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2367 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
|
2368 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
|
2369 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2370 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2371 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2372 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr) |
7 | 2373 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2374 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2375 * 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
|
2376 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2377 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2378 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2379 * 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
|
2380 * 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
|
2381 * 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
|
2382 * 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
|
2383 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2384 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2385 ReadRegion.Bottom = Y + Y_incr - 1; |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2386 if (!ReadConsoleOutputW(g_hConOut, /* output handle */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2387 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2388 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2389 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2390 &ReadRegion)) /* region to save */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2391 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2392 VIM_CLEAR(cb->Buffer); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2393 VIM_CLEAR(cb->Regions); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2394 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2395 } |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2396 cb->Regions[i] = ReadRegion; |
7 | 2397 } |
2398 | |
2399 return TRUE; | |
2400 } | |
2401 | |
2402 /* | |
2403 * RestoreConsoleBuffer() | |
2404 * Description: | |
2405 * Restores important information about the console buffer, including the | |
2406 * actual buffer contents, if desired. The information to restore is in | |
2407 * the same format used by SaveConsoleBuffer(). | |
2408 * Returns: | |
2409 * TRUE on success | |
2410 */ | |
2411 static BOOL | |
2412 RestoreConsoleBuffer( | |
26 | 2413 ConsoleBuffer *cb, |
2414 BOOL RestoreScreen) | |
7 | 2415 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2416 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2417 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
|
2418 int i; |
7 | 2419 |
2420 if (cb == NULL || !cb->IsValid) | |
2421 return FALSE; | |
2422 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2423 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2424 * 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
|
2425 * 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
|
2426 * 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
|
2427 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2428 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2429 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2430 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2431 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2432 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
|
2433 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2434 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
|
2435 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2436 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2437 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2438 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2439 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2440 * 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
|
2441 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2442 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2443 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2444 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2445 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
|
2446 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2447 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
|
2448 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2449 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2450 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2451 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2452 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2453 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2454 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2455 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
|
2456 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2457 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
|
2458 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
|
2459 WriteRegion = cb->Regions[i]; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2460 if (!WriteConsoleOutputW(g_hConOut, /* output handle */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2461 cb->Buffer, /* our buffer */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2462 cb->BufferSize, /* dimensions of our buffer */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2463 BufferCoord, /* offset in our buffer */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2464 &WriteRegion)) /* region to restore */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2465 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2466 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
|
2467 } |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2468 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2469 } |
7 | 2470 |
2471 return TRUE; | |
2472 } | |
2473 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2474 #define FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2475 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2476 static ConsoleBuffer g_cbOrig = { 0 }; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2477 #endif |
7 | 2478 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2479 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2480 | |
2481 #ifdef FEAT_TITLE | |
2482 #ifdef __BORLANDC__ | |
2483 typedef HWND (__stdcall *GETCONSOLEWINDOWPROC)(VOID); | |
2484 #else | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2485 typedef HWND (WINAPI *GETCONSOLEWINDOWPROC)(VOID); |
7 | 2486 #endif |
2487 char g_szOrigTitle[256] = { 0 }; | |
2488 HWND g_hWnd = NULL; /* also used in os_mswin.c */ | |
2489 static HICON g_hOrigIconSmall = NULL; | |
2490 static HICON g_hOrigIcon = NULL; | |
2491 static HICON g_hVimIcon = NULL; | |
2492 static BOOL g_fCanChangeIcon = FALSE; | |
2493 | |
2494 /* ICON* are not defined in VC++ 4.0 */ | |
2495 #ifndef ICON_SMALL | |
2496 #define ICON_SMALL 0 | |
2497 #endif | |
2498 #ifndef ICON_BIG | |
2499 #define ICON_BIG 1 | |
2500 #endif | |
2501 /* | |
2502 * GetConsoleIcon() | |
2503 * Description: | |
2504 * Attempts to retrieve the small icon and/or the big icon currently in | |
2505 * use by a given window. | |
2506 * Returns: | |
2507 * TRUE on success | |
2508 */ | |
2509 static BOOL | |
2510 GetConsoleIcon( | |
26 | 2511 HWND hWnd, |
2512 HICON *phIconSmall, | |
2513 HICON *phIcon) | |
7 | 2514 { |
2515 if (hWnd == NULL) | |
2516 return FALSE; | |
2517 | |
2518 if (phIconSmall != NULL) | |
26 | 2519 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2520 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2521 if (phIcon != NULL) |
26 | 2522 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2523 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2524 return TRUE; |
2525 } | |
2526 | |
2527 /* | |
2528 * SetConsoleIcon() | |
2529 * Description: | |
2530 * Attempts to change the small icon and/or the big icon currently in | |
2531 * use by a given window. | |
2532 * Returns: | |
2533 * TRUE on success | |
2534 */ | |
2535 static BOOL | |
2536 SetConsoleIcon( | |
26 | 2537 HWND hWnd, |
2538 HICON hIconSmall, | |
2539 HICON hIcon) | |
7 | 2540 { |
2541 if (hWnd == NULL) | |
2542 return FALSE; | |
2543 | |
2544 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2545 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2546 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2547 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2548 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2549 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2550 return TRUE; |
2551 } | |
2552 | |
2553 /* | |
2554 * SaveConsoleTitleAndIcon() | |
2555 * Description: | |
2556 * Saves the current console window title in g_szOrigTitle, for later | |
2557 * restoration. Also, attempts to obtain a handle to the console window, | |
2558 * and use it to save the small and big icons currently in use by the | |
2559 * console window. This is not always possible on some versions of Windows; | |
2560 * nor is it possible when running Vim remotely using Telnet (since the | |
2561 * console window the user sees is owned by a remote process). | |
2562 */ | |
2563 static void | |
2564 SaveConsoleTitleAndIcon(void) | |
2565 { | |
2566 /* Save the original title. */ | |
2567 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) | |
2568 return; | |
2569 | |
2570 /* | |
2571 * Obtain a handle to the console window using GetConsoleWindow() from | |
2572 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2573 * This function only exists on NT-based Windows, starting with Windows | |
2574 * 2000. On older operating systems, we can't change the window icon | |
2575 * anyway. | |
2576 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2577 g_hWnd = GetConsoleWindow(); |
7 | 2578 if (g_hWnd == NULL) |
2579 return; | |
2580 | |
2581 /* Save the original console window icon. */ | |
2582 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); | |
2583 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2584 return; | |
2585 | |
2586 /* Extract the first icon contained in the Vim executable. */ | |
6249 | 2587 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2588 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2589 if (g_hVimIcon != NULL) |
2590 g_fCanChangeIcon = TRUE; | |
2591 } | |
2592 #endif | |
2593 | |
2594 static int g_fWindInitCalled = FALSE; | |
2595 static int g_fTermcapMode = FALSE; | |
2596 static CONSOLE_CURSOR_INFO g_cci; | |
2597 static DWORD g_cmodein = 0; | |
2598 static DWORD g_cmodeout = 0; | |
2599 | |
2600 /* | |
2601 * non-GUI version of mch_init(). | |
2602 */ | |
2603 void | |
26 | 2604 mch_init(void) |
7 | 2605 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2606 #ifndef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2607 CONSOLE_SCREEN_BUFFER_INFO csbi; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2608 #endif |
7 | 2609 #ifndef __MINGW32__ |
2610 extern int _fmode; | |
2611 #endif | |
2612 | |
2584 | 2613 /* Silently handle invalid parameters to CRT functions */ |
2614 SET_INVALID_PARAM_HANDLER; | |
2615 | |
7 | 2616 /* Let critical errors result in a failure, not in a dialog box. Required |
2617 * for the timestamp test to work on removed floppies. */ | |
2618 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2619 | |
2620 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2621 out_flush(); | |
2622 | |
2623 /* Obtain handles for the standard Console I/O devices */ | |
2624 if (read_cmd_fd == 0) | |
2625 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2626 else | |
2627 create_conin(); | |
2628 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
|
2629 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2630 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2631 /* Save the initial console buffer for later restoration */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2632 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2633 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2634 #else |
7 | 2635 /* Get current text attributes */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2636 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2637 g_attrCurrent = g_attrDefault = csbi.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2638 #endif |
7 | 2639 if (cterm_normal_fg_color == 0) |
2640 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2641 if (cterm_normal_bg_color == 0) | |
2642 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2643 | |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
2644 // Fg and Bg color index nunmber at startup |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
2645 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
|
2646 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
|
2647 |
7 | 2648 /* set termcap codes to current text attributes */ |
2649 update_tcap(g_attrCurrent); | |
2650 | |
2651 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2652 GetConsoleMode(g_hConIn, &g_cmodein); | |
2653 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2654 | |
2655 #ifdef FEAT_TITLE | |
2656 SaveConsoleTitleAndIcon(); | |
2657 /* | |
2658 * Set both the small and big icons of the console window to Vim's icon. | |
2659 * Note that Vim presently only has one size of icon (32x32), but it | |
2660 * automatically gets scaled down to 16x16 when setting the small icon. | |
2661 */ | |
2662 if (g_fCanChangeIcon) | |
2663 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2664 #endif | |
2665 | |
2666 ui_get_shellsize(); | |
2667 | |
2668 #ifdef MCH_WRITE_DUMP | |
2669 fdDump = fopen("dump", "wt"); | |
2670 | |
2671 if (fdDump) | |
2672 { | |
2673 time_t t; | |
2674 | |
2675 time(&t); | |
2676 fputs(ctime(&t), fdDump); | |
2677 fflush(fdDump); | |
2678 } | |
2679 #endif | |
2680 | |
2681 g_fWindInitCalled = TRUE; | |
2682 | |
2683 #ifdef FEAT_MOUSE | |
2684 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2685 #endif | |
2686 | |
2687 #ifdef FEAT_CLIPBOARD | |
4168 | 2688 win_clip_init(); |
7 | 2689 #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
|
2690 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2691 vtp_init(); |
7 | 2692 } |
2693 | |
2694 /* | |
2695 * non-GUI version of mch_exit(). | |
2696 * Shut down and exit with status `r' | |
2697 * Careful: mch_exit() may be called before mch_init()! | |
2698 */ | |
2699 void | |
2700 mch_exit(int r) | |
2701 { | |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2702 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
|
2703 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2704 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
|
2705 |
7 | 2706 stoptermcap(); |
2707 if (g_fWindInitCalled) | |
2708 settmode(TMODE_COOK); | |
2709 | |
2710 ml_close_all(TRUE); /* remove all memfiles */ | |
2711 | |
2712 if (g_fWindInitCalled) | |
2713 { | |
2714 #ifdef FEAT_TITLE | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14473
diff
changeset
|
2715 mch_restore_title(SAVE_RESTORE_BOTH); |
7 | 2716 /* |
2717 * Restore both the small and big icons of the console window to | |
2718 * what they were at startup. Don't do this when the window is | |
2719 * closed, Vim would hang here. | |
2720 */ | |
2721 if (g_fCanChangeIcon && !g_fForceExit) | |
2722 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
2723 #endif | |
2724 | |
2725 #ifdef MCH_WRITE_DUMP | |
2726 if (fdDump) | |
2727 { | |
2728 time_t t; | |
2729 | |
2730 time(&t); | |
2731 fputs(ctime(&t), fdDump); | |
2732 fclose(fdDump); | |
2733 } | |
2734 fdDump = NULL; | |
2735 #endif | |
2736 } | |
2737 | |
2738 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2739 SetConsoleMode(g_hConIn, g_cmodein); | |
2740 SetConsoleMode(g_hConOut, g_cmodeout); | |
2741 | |
2742 #ifdef DYNAMIC_GETTEXT | |
2743 dyn_libintl_end(); | |
2744 #endif | |
2745 | |
2746 exit(r); | |
2747 } | |
2748 #endif /* !FEAT_GUI_W32 */ | |
2749 | |
2750 /* | |
2751 * Do we have an interactive window? | |
2752 */ | |
2753 int | |
2754 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
|
2755 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
|
2756 char **argv UNUSED) |
7 | 2757 { |
2758 get_exe_name(); | |
2759 | |
2760 #ifdef FEAT_GUI_W32 | |
2761 return OK; /* GUI always has a tty */ | |
2762 #else | |
2763 if (isatty(1)) | |
2764 return OK; | |
2765 return FAIL; | |
2766 #endif | |
2767 } | |
2768 | |
2769 | |
5326 | 2770 #ifdef FEAT_MBYTE |
2771 /* | |
2772 * fname_casew(): Wide version of fname_case(). Set the case of the file name, | |
2773 * if it already exists. When "len" is > 0, also expand short to long | |
2774 * filenames. | |
2775 * Return FAIL if wide functions are not available, OK otherwise. | |
2776 * NOTE: much of this is identical to fname_case(), keep in sync! | |
2777 */ | |
2778 static int | |
2779 fname_casew( | |
2780 WCHAR *name, | |
2781 int len) | |
2782 { | |
2783 WCHAR szTrueName[_MAX_PATH + 2]; | |
2784 WCHAR szTrueNameTemp[_MAX_PATH + 2]; | |
2785 WCHAR *ptrue, *ptruePrev; | |
2786 WCHAR *porig, *porigPrev; | |
2787 int flen; | |
2788 WIN32_FIND_DATAW fb; | |
5529 | 2789 HANDLE hFind = INVALID_HANDLE_VALUE; |
5326 | 2790 int c; |
2791 int slen; | |
2792 | |
2793 flen = (int)wcslen(name); | |
2794 if (flen > _MAX_PATH) | |
2795 return OK; | |
2796 | |
2797 /* slash_adjust(name) not needed, already adjusted by fname_case(). */ | |
2798 | |
2799 /* Build the new name in szTrueName[] one component at a time. */ | |
2800 porig = name; | |
2801 ptrue = szTrueName; | |
2802 | |
2803 if (iswalpha(porig[0]) && porig[1] == L':') | |
2804 { | |
2805 /* copy leading drive letter */ | |
2806 *ptrue++ = *porig++; | |
2807 *ptrue++ = *porig++; | |
2808 } | |
5529 | 2809 *ptrue = NUL; /* in case nothing follows */ |
5326 | 2810 |
2811 while (*porig != NUL) | |
2812 { | |
2813 /* copy \ characters */ | |
2814 while (*porig == psepc) | |
2815 *ptrue++ = *porig++; | |
2816 | |
2817 ptruePrev = ptrue; | |
2818 porigPrev = porig; | |
2819 while (*porig != NUL && *porig != psepc) | |
2820 { | |
2821 *ptrue++ = *porig++; | |
2822 } | |
2823 *ptrue = NUL; | |
2824 | |
2825 /* To avoid a slow failure append "\*" when searching a directory, | |
2826 * server or network share. */ | |
2827 wcscpy(szTrueNameTemp, szTrueName); | |
2828 slen = (int)wcslen(szTrueNameTemp); | |
2829 if (*porig == psepc && slen + 2 < _MAX_PATH) | |
2830 wcscpy(szTrueNameTemp + slen, L"\\*"); | |
2831 | |
2832 /* Skip "", "." and "..". */ | |
2833 if (ptrue > ptruePrev | |
2834 && (ptruePrev[0] != L'.' | |
2835 || (ptruePrev[1] != NUL | |
2836 && (ptruePrev[1] != L'.' || ptruePrev[2] != NUL))) | |
2837 && (hFind = FindFirstFileW(szTrueNameTemp, &fb)) | |
2838 != INVALID_HANDLE_VALUE) | |
2839 { | |
2840 c = *porig; | |
2841 *porig = NUL; | |
2842 | |
2843 /* Only use the match when it's the same name (ignoring case) or | |
2844 * expansion is allowed and there is a match with the short name | |
2845 * and there is enough room. */ | |
2846 if (_wcsicoll(porigPrev, fb.cFileName) == 0 | |
2847 || (len > 0 | |
2848 && (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0 | |
2849 && (int)(ptruePrev - szTrueName) | |
2850 + (int)wcslen(fb.cFileName) < len))) | |
2851 { | |
2852 wcscpy(ptruePrev, fb.cFileName); | |
2853 | |
2854 /* Look for exact match and prefer it if found. Must be a | |
2855 * long name, otherwise there would be only one match. */ | |
2856 while (FindNextFileW(hFind, &fb)) | |
2857 { | |
2858 if (*fb.cAlternateFileName != NUL | |
2859 && (wcscoll(porigPrev, fb.cFileName) == 0 | |
2860 || (len > 0 | |
2861 && (_wcsicoll(porigPrev, | |
2862 fb.cAlternateFileName) == 0 | |
2863 && (int)(ptruePrev - szTrueName) | |
2864 + (int)wcslen(fb.cFileName) < len)))) | |
2865 { | |
2866 wcscpy(ptruePrev, fb.cFileName); | |
2867 break; | |
2868 } | |
2869 } | |
2870 } | |
2871 FindClose(hFind); | |
2872 *porig = c; | |
2873 ptrue = ptruePrev + wcslen(ptruePrev); | |
2874 } | |
2875 } | |
2876 | |
2877 wcscpy(name, szTrueName); | |
2878 return OK; | |
2879 } | |
2880 #endif | |
2881 | |
7 | 2882 /* |
2883 * fname_case(): Set the case of the file name, if it already exists. | |
2884 * When "len" is > 0, also expand short to long filenames. | |
5326 | 2885 * NOTE: much of this is identical to fname_casew(), keep in sync! |
7 | 2886 */ |
2887 void | |
2888 fname_case( | |
2889 char_u *name, | |
2890 int len) | |
2891 { | |
2892 char szTrueName[_MAX_PATH + 2]; | |
2604 | 2893 char szTrueNameTemp[_MAX_PATH + 2]; |
7 | 2894 char *ptrue, *ptruePrev; |
2895 char *porig, *porigPrev; | |
2896 int flen; | |
2897 WIN32_FIND_DATA fb; | |
2898 HANDLE hFind; | |
2899 int c; | |
2604 | 2900 int slen; |
7 | 2901 |
434 | 2902 flen = (int)STRLEN(name); |
5326 | 2903 if (flen == 0) |
7 | 2904 return; |
2905 | |
2906 slash_adjust(name); | |
2907 | |
5326 | 2908 #ifdef FEAT_MBYTE |
2909 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2910 { | |
2911 WCHAR *p = enc_to_utf16(name, NULL); | |
2912 | |
2913 if (p != NULL) | |
2914 { | |
2915 char_u *q; | |
6262 | 2916 WCHAR buf[_MAX_PATH + 1]; |
2917 | |
2918 wcsncpy(buf, p, _MAX_PATH); | |
2919 buf[_MAX_PATH] = L'\0'; | |
5326 | 2920 vim_free(p); |
2921 | |
2922 if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK) | |
2923 { | |
2924 q = utf16_to_enc(buf, NULL); | |
2925 if (q != NULL) | |
2926 { | |
2927 vim_strncpy(name, q, (len > 0) ? len - 1 : flen); | |
2928 vim_free(q); | |
2929 return; | |
2930 } | |
2931 } | |
2932 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2933 return; |
5326 | 2934 } |
2935 #endif | |
2936 | |
2937 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH. | |
2938 * So we should check this after calling wide function. */ | |
2939 if (flen > _MAX_PATH) | |
2940 return; | |
2941 | |
7 | 2942 /* Build the new name in szTrueName[] one component at a time. */ |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2943 porig = (char *)name; |
7 | 2944 ptrue = szTrueName; |
2945 | |
2946 if (isalpha(porig[0]) && porig[1] == ':') | |
2947 { | |
2948 /* copy leading drive letter */ | |
2949 *ptrue++ = *porig++; | |
2950 *ptrue++ = *porig++; | |
2951 } | |
5529 | 2952 *ptrue = NUL; /* in case nothing follows */ |
7 | 2953 |
2954 while (*porig != NUL) | |
2955 { | |
2956 /* copy \ characters */ | |
2957 while (*porig == psepc) | |
2958 *ptrue++ = *porig++; | |
2959 | |
2960 ptruePrev = ptrue; | |
2961 porigPrev = porig; | |
2962 while (*porig != NUL && *porig != psepc) | |
2963 { | |
2964 #ifdef FEAT_MBYTE | |
2965 int l; | |
2966 | |
2967 if (enc_dbcs) | |
2968 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2969 l = (*mb_ptr2len)((char_u *)porig); |
7 | 2970 while (--l >= 0) |
2971 *ptrue++ = *porig++; | |
2972 } | |
2973 else | |
2974 #endif | |
2975 *ptrue++ = *porig++; | |
2976 } | |
2977 *ptrue = NUL; | |
2978 | |
2604 | 2979 /* To avoid a slow failure append "\*" when searching a directory, |
2980 * server or network share. */ | |
2981 STRCPY(szTrueNameTemp, szTrueName); | |
2615 | 2982 slen = (int)strlen(szTrueNameTemp); |
2604 | 2983 if (*porig == psepc && slen + 2 < _MAX_PATH) |
2984 STRCPY(szTrueNameTemp + slen, "\\*"); | |
2985 | |
7 | 2986 /* Skip "", "." and "..". */ |
2987 if (ptrue > ptruePrev | |
2988 && (ptruePrev[0] != '.' | |
2989 || (ptruePrev[1] != NUL | |
2990 && (ptruePrev[1] != '.' || ptruePrev[2] != NUL))) | |
2604 | 2991 && (hFind = FindFirstFile(szTrueNameTemp, &fb)) |
7 | 2992 != INVALID_HANDLE_VALUE) |
2993 { | |
2994 c = *porig; | |
2995 *porig = NUL; | |
2996 | |
2997 /* Only use the match when it's the same name (ignoring case) or | |
2998 * expansion is allowed and there is a match with the short name | |
2999 * and there is enough room. */ | |
3000 if (_stricoll(porigPrev, fb.cFileName) == 0 | |
3001 || (len > 0 | |
3002 && (_stricoll(porigPrev, fb.cAlternateFileName) == 0 | |
3003 && (int)(ptruePrev - szTrueName) | |
3004 + (int)strlen(fb.cFileName) < len))) | |
3005 { | |
3006 STRCPY(ptruePrev, fb.cFileName); | |
3007 | |
3008 /* Look for exact match and prefer it if found. Must be a | |
3009 * long name, otherwise there would be only one match. */ | |
3010 while (FindNextFile(hFind, &fb)) | |
3011 { | |
3012 if (*fb.cAlternateFileName != NUL | |
3013 && (strcoll(porigPrev, fb.cFileName) == 0 | |
3014 || (len > 0 | |
3015 && (_stricoll(porigPrev, | |
3016 fb.cAlternateFileName) == 0 | |
3017 && (int)(ptruePrev - szTrueName) | |
3018 + (int)strlen(fb.cFileName) < len)))) | |
3019 { | |
3020 STRCPY(ptruePrev, fb.cFileName); | |
3021 break; | |
3022 } | |
3023 } | |
3024 } | |
3025 FindClose(hFind); | |
3026 *porig = c; | |
3027 ptrue = ptruePrev + strlen(ptruePrev); | |
3028 } | |
3029 } | |
3030 | |
3031 STRCPY(name, szTrueName); | |
3032 } | |
3033 | |
3034 | |
3035 /* | |
3036 * Insert user name in s[len]. | |
3037 */ | |
3038 int | |
3039 mch_get_user_name( | |
26 | 3040 char_u *s, |
3041 int len) | |
7 | 3042 { |
1414 | 3043 char szUserName[256 + 1]; /* UNLEN is 256 */ |
7 | 3044 DWORD cch = sizeof szUserName; |
3045 | |
5549 | 3046 #ifdef FEAT_MBYTE |
3047 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3048 { | |
3049 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ | |
3050 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); | |
3051 | |
3052 if (GetUserNameW(wszUserName, &wcch)) | |
3053 { | |
3054 char_u *p = utf16_to_enc(wszUserName, NULL); | |
3055 | |
3056 if (p != NULL) | |
3057 { | |
3058 vim_strncpy(s, p, len - 1); | |
3059 vim_free(p); | |
3060 return OK; | |
3061 } | |
3062 } | |
3063 } | |
3064 #endif | |
7 | 3065 if (GetUserName(szUserName, &cch)) |
3066 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3067 vim_strncpy(s, (char_u *)szUserName, len - 1); |
7 | 3068 return OK; |
3069 } | |
3070 s[0] = NUL; | |
3071 return FAIL; | |
3072 } | |
3073 | |
3074 | |
3075 /* | |
3076 * Insert host name in s[len]. | |
3077 */ | |
3078 void | |
3079 mch_get_host_name( | |
3080 char_u *s, | |
3081 int len) | |
3082 { | |
3083 DWORD cch = len; | |
3084 | |
5551 | 3085 #ifdef FEAT_MBYTE |
3086 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3087 { | |
3088 WCHAR wszHostName[256 + 1]; | |
3089 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); | |
3090 | |
3091 if (GetComputerNameW(wszHostName, &wcch)) | |
3092 { | |
3093 char_u *p = utf16_to_enc(wszHostName, NULL); | |
3094 | |
3095 if (p != NULL) | |
3096 { | |
3097 vim_strncpy(s, p, len - 1); | |
3098 vim_free(p); | |
3099 return; | |
3100 } | |
3101 } | |
3102 } | |
3103 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3104 if (!GetComputerName((LPSTR)s, &cch)) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3105 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1); |
7 | 3106 } |
3107 | |
3108 | |
3109 /* | |
3110 * return process ID | |
3111 */ | |
3112 long | |
26 | 3113 mch_get_pid(void) |
7 | 3114 { |
3115 return (long)GetCurrentProcessId(); | |
3116 } | |
3117 | |
3118 | |
3119 /* | |
3120 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
3121 * Return OK for success, FAIL for failure. | |
3122 */ | |
3123 int | |
3124 mch_dirname( | |
3125 char_u *buf, | |
3126 int len) | |
3127 { | |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3128 char_u abuf[_MAX_PATH + 1]; |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3129 DWORD lfnlen; |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3130 |
7 | 3131 /* |
3132 * Originally this was: | |
3133 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
3134 * But the Win32s known bug list says that getcwd() doesn't work | |
3135 * so use the Win32 system call instead. <Negri> | |
3136 */ | |
3137 #ifdef FEAT_MBYTE | |
3138 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3139 { | |
3140 WCHAR wbuf[_MAX_PATH + 1]; | |
3141 | |
3142 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) | |
3143 { | |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3144 WCHAR wcbuf[_MAX_PATH + 1]; |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3145 char_u *p = NULL; |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3146 |
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3147 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0) |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3148 { |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3149 p = utf16_to_enc(wcbuf, NULL); |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3150 if (STRLEN(p) >= (size_t)len) |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3151 { |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3152 // long path name is too long, fall back to short one |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3153 vim_free(p); |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3154 p = NULL; |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3155 } |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3156 } |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3157 if (p == NULL) |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3158 p = utf16_to_enc(wbuf, NULL); |
7 | 3159 |
3160 if (p != NULL) | |
3161 { | |
417 | 3162 vim_strncpy(buf, p, len - 1); |
7 | 3163 vim_free(p); |
3164 return OK; | |
3165 } | |
3166 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3167 return FAIL; |
7 | 3168 } |
3169 #endif | |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3170 if (GetCurrentDirectory(len, (LPSTR)buf) == 0) |
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3171 return FAIL; |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3172 lfnlen = GetLongPathNameA((LPCSTR)buf, (LPSTR)abuf, _MAX_PATH); |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3173 if (lfnlen == 0 || lfnlen >= (DWORD)len) |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3174 // Failed to get long path name or it's too long: fall back to the |
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3175 // short path name. |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3176 return OK; |
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3177 |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
3178 STRCPY(buf, abuf); |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
3179 return OK; |
7 | 3180 } |
3181 | |
3182 /* | |
5494 | 3183 * Get file permissions for "name". |
3184 * Return mode_t or -1 for error. | |
7 | 3185 */ |
3186 long | |
26 | 3187 mch_getperm(char_u *name) |
7 | 3188 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
3189 stat_T st; |
5494 | 3190 int n; |
3191 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3192 n = mch_stat((char *)name, &st); |
5588 | 3193 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 3194 } |
3195 | |
3196 | |
3197 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3198 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3199 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3200 * Return FAIL for failure, OK otherwise. |
7 | 3201 */ |
3202 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3203 mch_setperm(char_u *name, long perm) |
7 | 3204 { |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3205 long n = -1; |
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3206 |
7 | 3207 #ifdef FEAT_MBYTE |
3208 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3209 { | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3210 WCHAR *p = enc_to_utf16(name, NULL); |
7 | 3211 |
3212 if (p != NULL) | |
3213 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3214 n = _wchmod(p, perm); |
7 | 3215 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3216 if (n == -1) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3217 return FAIL; |
7 | 3218 } |
3219 } | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3220 if (n == -1) |
7 | 3221 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3222 n = _chmod((const char *)name, perm); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3223 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3224 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3225 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3226 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3227 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3228 return OK; |
7 | 3229 } |
3230 | |
3231 /* | |
3232 * Set hidden flag for "name". | |
3233 */ | |
3234 void | |
3235 mch_hide(char_u *name) | |
3236 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3237 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3238 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3239 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3240 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3241 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3242 win32_setattrs(name, attrs); |
7 | 3243 } |
3244 | |
3245 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3246 * 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
|
3247 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3248 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3249 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3250 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3251 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3252 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3253 if (f == -1) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3254 return FALSE; /* file does not exist at all */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3255 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3256 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3257 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3258 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3259 /* |
7 | 3260 * return TRUE if "name" is a directory |
3261 * return FALSE if "name" is not a directory or upon error | |
3262 */ | |
3263 int | |
3264 mch_isdir(char_u *name) | |
3265 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3266 int f = win32_getattrs(name); |
7 | 3267 |
3268 if (f == -1) | |
3269 return FALSE; /* file does not exist at all */ | |
3270 | |
3271 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3272 } | |
3273 | |
3274 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3275 * 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
|
3276 * 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
|
3277 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3278 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3279 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3280 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3281 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3282 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
|
3283 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3284 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3285 /* |
2803 | 3286 * Create directory "name". |
3287 * Return 0 on success, -1 on error. | |
3288 */ | |
3289 int | |
3290 mch_mkdir(char_u *name) | |
3291 { | |
3292 #ifdef FEAT_MBYTE | |
3293 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3294 { | |
3295 WCHAR *p; | |
3296 int retval; | |
3297 | |
3298 p = enc_to_utf16(name, NULL); | |
3299 if (p == NULL) | |
3300 return -1; | |
3301 retval = _wmkdir(p); | |
3302 vim_free(p); | |
3303 return retval; | |
3304 } | |
3305 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3306 return _mkdir((const char *)name); |
2803 | 3307 } |
3308 | |
3309 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3310 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3311 * 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
|
3312 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3313 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3314 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3315 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3316 #ifdef FEAT_MBYTE |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3317 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3318 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3319 WCHAR *p; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3320 int retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3321 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3322 p = enc_to_utf16(name, NULL); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3323 if (p == NULL) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3324 return -1; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3325 retval = _wrmdir(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3326 vim_free(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3327 return retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3328 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3329 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3330 return _rmdir((const char *)name); |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3331 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3332 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3333 /* |
696 | 3334 * Return TRUE if file "fname" has more than one link. |
3335 */ | |
3336 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3337 mch_is_hard_link(char_u *fname) |
696 | 3338 { |
2793 | 3339 BY_HANDLE_FILE_INFORMATION info; |
3340 | |
3341 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3342 && info.nNumberOfLinks > 1; | |
3343 } | |
3344 | |
3345 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3346 * 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
|
3347 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3348 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3349 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3350 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3351 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3352 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3353 WIN32_FIND_DATAA findDataA; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3354 DWORD fileFlags = 0, reparseTag = 0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3355 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3356 WCHAR *wn = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3357 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3358 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3359 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3360 wn = enc_to_utf16(name, NULL); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3361 if (wn != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3362 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3363 hFind = FindFirstFileW(wn, &findDataW); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3364 vim_free(wn); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3365 if (hFind != INVALID_HANDLE_VALUE) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3366 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3367 fileFlags = findDataW.dwFileAttributes; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3368 reparseTag = findDataW.dwReserved0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3369 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3370 } |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3371 else |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3372 #endif |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3373 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3374 hFind = FindFirstFile((LPCSTR)name, &findDataA); |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3375 if (hFind != INVALID_HANDLE_VALUE) |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3376 { |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3377 fileFlags = findDataA.dwFileAttributes; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3378 reparseTag = findDataA.dwReserved0; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3379 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3380 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3381 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3382 if (hFind != INVALID_HANDLE_VALUE) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3383 FindClose(hFind); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3384 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3385 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
|
3386 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3387 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3388 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3389 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3390 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3391 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3392 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3393 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3394 * 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
|
3395 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3396 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3397 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3398 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3399 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3400 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
|
3401 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3402 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3403 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3404 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3405 /* |
2793 | 3406 * Get the by-handle-file-information for "fname". |
3407 * Returns FILEINFO_OK when OK. | |
3408 * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
3409 * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
3410 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3411 */ | |
3412 int | |
3413 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3414 { | |
696 | 3415 HANDLE hFile; |
2793 | 3416 int res = FILEINFO_READ_FAIL; |
696 | 3417 #ifdef FEAT_MBYTE |
3418 WCHAR *wn = NULL; | |
3419 | |
3420 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2793 | 3421 { |
1752 | 3422 wn = enc_to_utf16(fname, NULL); |
2793 | 3423 if (wn == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3424 return FILEINFO_ENC_FAIL; |
2793 | 3425 } |
696 | 3426 if (wn != NULL) |
3427 { | |
3428 hFile = CreateFileW(wn, /* file name */ | |
3429 GENERIC_READ, /* access mode */ | |
2793 | 3430 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3431 NULL, /* security descriptor */ |
3432 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3433 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3434 NULL); /* handle to template file */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3435 vim_free(wn); |
696 | 3436 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3437 else |
696 | 3438 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3439 hFile = CreateFile((LPCSTR)fname, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3440 GENERIC_READ, /* access mode */ |
2793 | 3441 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3442 NULL, /* security descriptor */ |
3443 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3444 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3445 NULL); /* handle to template file */ |
3446 | |
3447 if (hFile != INVALID_HANDLE_VALUE) | |
3448 { | |
2793 | 3449 if (GetFileInformationByHandle(hFile, info) != 0) |
3450 res = FILEINFO_OK; | |
3451 else | |
3452 res = FILEINFO_INFO_FAIL; | |
696 | 3453 CloseHandle(hFile); |
3454 } | |
3455 | |
3456 return res; | |
3457 } | |
3458 | |
3459 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3460 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3461 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3462 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3463 */ |
5494 | 3464 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3465 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3466 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3467 int attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3468 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3469 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3470 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3471 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3472 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3473 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3474 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3475 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3476 attr = GetFileAttributesW(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3477 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3478 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3479 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3480 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3481 attr = GetFileAttributes((char *)name); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3482 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3483 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3484 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3485 |
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 * set file attributes for `name' to `attrs' |
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 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3490 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3491 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3492 win32_setattrs(char_u *name, int attrs) |
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 res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3495 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3496 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3497 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3498 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3499 p = enc_to_utf16(name, NULL); |
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 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3502 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3503 res = SetFileAttributesW(p, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3504 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3505 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3506 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3507 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3508 res = SetFileAttributes((char *)name, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3509 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3510 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3511 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3512 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3513 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3514 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3515 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3516 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3517 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3518 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3519 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3520 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3521 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3522 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3523 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3524 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3525 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3526 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3527 /* |
7 | 3528 * Return TRUE if file or directory "name" is writable (not readonly). |
3529 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3530 * delete a file. Let's say this means it is writable. | |
3531 */ | |
3532 int | |
3533 mch_writable(char_u *name) | |
3534 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3535 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3536 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3537 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3538 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3539 } |
3540 | |
3541 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3542 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3543 * 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
|
3544 * 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
|
3545 * the allocated memory. |
7 | 3546 */ |
3547 int | |
6700 | 3548 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3549 { |
10 | 3550 char_u buf[_MAX_PATH]; |
835 | 3551 int len = (int)STRLEN(name); |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3552 char_u *p, *saved; |
10 | 3553 |
3554 if (len >= _MAX_PATH) /* safety check */ | |
3555 return FALSE; | |
3556 | |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3557 /* Ty using the name directly when a Unix-shell like 'shell'. */ |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3558 if (strstr((char *)gettail(p_sh), "sh") != NULL) |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3559 if (executable_exists((char *)name, path, use_path)) |
10 | 3560 return TRUE; |
3561 | |
3562 /* | |
3563 * Loop over all extensions in $PATHEXT. | |
3564 */ | |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3565 p = mch_getenv("PATHEXT"); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3566 if (p == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3567 p = (char_u *)".com;.exe;.bat;.cmd"; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3568 saved = vim_strsave(p); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3569 if (saved == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3570 return FALSE; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3571 p = saved; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3572 while (*p) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3573 { |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3574 char_u *tmp = vim_strchr(p, ';'); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3575 |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3576 if (tmp != NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3577 *tmp = NUL; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3578 if (_stricoll((char *)name + len - STRLEN(p), (char *)p) == 0 |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3579 && executable_exists((char *)name, path, use_path)) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3580 { |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3581 vim_free(saved); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3582 return TRUE; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3583 } |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3584 if (tmp == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3585 break; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3586 p = tmp + 1; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3587 } |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3588 vim_free(saved); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3589 |
417 | 3590 vim_strncpy(buf, name, _MAX_PATH - 1); |
10 | 3591 p = mch_getenv("PATHEXT"); |
3592 if (p == NULL) | |
3593 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3594 while (*p) | |
3595 { | |
3596 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3597 { | |
3598 /* A single "." means no extension is added. */ | |
3599 buf[len] = NUL; | |
3600 ++p; | |
3601 if (*p) | |
3602 ++p; | |
3603 } | |
3604 else | |
3605 copy_option_part(&p, buf + len, _MAX_PATH - len, ";"); | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3606 if (executable_exists((char *)buf, path, use_path)) |
10 | 3607 return TRUE; |
3608 } | |
3609 return FALSE; | |
7 | 3610 } |
3611 | |
3612 /* | |
3613 * Check what "name" is: | |
3614 * NODE_NORMAL: file or directory (or doesn't exist) | |
3615 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3616 * NODE_OTHER: non-writable things | |
3617 */ | |
3618 int | |
3619 mch_nodetype(char_u *name) | |
3620 { | |
3621 HANDLE hFile; | |
3622 int type; | |
5324 | 3623 #ifdef FEAT_MBYTE |
3624 WCHAR *wn = NULL; | |
3625 #endif | |
7 | 3626 |
1004 | 3627 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
3628 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE | |
3629 * here. */ | |
3630 if (STRNCMP(name, "\\\\.\\", 4) == 0) | |
3631 return NODE_WRITABLE; | |
3632 | |
5324 | 3633 #ifdef FEAT_MBYTE |
3634 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3635 wn = enc_to_utf16(name, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3636 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3637 if (wn != NULL) |
5324 | 3638 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3639 hFile = CreateFileW(wn, /* file name */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3640 GENERIC_WRITE, /* access mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3641 0, /* share mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3642 NULL, /* security descriptor */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3643 OPEN_EXISTING, /* creation disposition */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3644 0, /* file attributes */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3645 NULL); /* handle to template file */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3646 vim_free(wn); |
5324 | 3647 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3648 else |
5324 | 3649 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3650 hFile = CreateFile((LPCSTR)name, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3651 GENERIC_WRITE, /* access mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3652 0, /* share mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3653 NULL, /* security descriptor */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3654 OPEN_EXISTING, /* creation disposition */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3655 0, /* file attributes */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3656 NULL); /* handle to template file */ |
5324 | 3657 |
7 | 3658 if (hFile == INVALID_HANDLE_VALUE) |
3659 return NODE_NORMAL; | |
3660 | |
3661 type = GetFileType(hFile); | |
3662 CloseHandle(hFile); | |
3663 if (type == FILE_TYPE_CHAR) | |
3664 return NODE_WRITABLE; | |
3665 if (type == FILE_TYPE_DISK) | |
3666 return NODE_NORMAL; | |
3667 return NODE_OTHER; | |
3668 } | |
3669 | |
3670 #ifdef HAVE_ACL | |
3671 struct my_acl | |
3672 { | |
3673 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3674 PSID pSidOwner; | |
3675 PSID pSidGroup; | |
3676 PACL pDacl; | |
3677 PACL pSacl; | |
3678 }; | |
3679 #endif | |
3680 | |
3681 /* | |
3682 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3683 * Return NULL if the ACL is not available for whatever reason. | |
3684 */ | |
3685 vim_acl_T | |
26 | 3686 mch_get_acl(char_u *fname) |
7 | 3687 { |
3688 #ifndef HAVE_ACL | |
3689 return (vim_acl_T)NULL; | |
3690 #else | |
3691 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3692 DWORD err; |
7 | 3693 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3694 p = (struct my_acl *)alloc_clear((unsigned)sizeof(struct my_acl)); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3695 if (p != NULL) |
7 | 3696 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3697 # ifdef FEAT_MBYTE |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3698 WCHAR *wn = NULL; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3699 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3700 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3701 wn = enc_to_utf16(fname, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3702 if (wn != NULL) |
7 | 3703 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3704 /* Try to retrieve the entire security descriptor. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3705 err = GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3706 wn, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3707 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3708 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3709 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3710 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3711 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3712 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3713 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3714 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3715 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3716 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3717 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3718 err == ERROR_PRIVILEGE_NOT_HELD) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3719 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3720 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3721 (void)GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3722 wn, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3723 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3724 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3725 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3726 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3727 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3728 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3729 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3730 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3731 if (p->pSecurityDescriptor == NULL) |
7 | 3732 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3733 mch_free_acl((vim_acl_T)p); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3734 p = NULL; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3735 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3736 vim_free(wn); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3737 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3738 else |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3739 # endif |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3740 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3741 /* Try to retrieve the entire security descriptor. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3742 err = GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3743 (LPSTR)fname, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3744 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3745 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3746 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3747 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3748 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3749 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3750 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3751 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3752 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3753 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3754 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3755 err == ERROR_PRIVILEGE_NOT_HELD) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3756 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3757 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3758 (void)GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3759 (LPSTR)fname, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3760 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3761 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3762 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3763 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3764 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3765 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3766 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3767 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3768 if (p->pSecurityDescriptor == NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3769 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3770 mch_free_acl((vim_acl_T)p); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3771 p = NULL; |
7 | 3772 } |
3773 } | |
3774 } | |
3775 | |
3776 return (vim_acl_T)p; | |
3777 #endif | |
3778 } | |
3779 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3780 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3781 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3782 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3783 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3784 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3785 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3786 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3787 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3788 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3789 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3790 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3791 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3792 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3793 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3794 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3795 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3796 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3797 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3798 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3799 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3800 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3801 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3802 |
7 | 3803 /* |
3804 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3805 * Errors are ignored. | |
3806 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3807 */ | |
3808 void | |
26 | 3809 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3810 { |
3811 #ifdef HAVE_ACL | |
3812 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
|
3813 SECURITY_INFORMATION sec_info = 0; |
7 | 3814 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3815 if (p != NULL) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3816 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3817 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3818 WCHAR *wn = NULL; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3819 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3820 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3821 /* Set security flags */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3822 if (p->pSidOwner) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3823 sec_info |= OWNER_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3824 if (p->pSidGroup) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3825 sec_info |= GROUP_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3826 if (p->pDacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3827 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3828 sec_info |= DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3829 /* Do not inherit its parent's DACL. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3830 * If the DACL is inherited, Cygwin permissions would be changed. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3831 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3832 if (!is_acl_inherited(p->pDacl)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3833 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3834 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3835 if (p->pSacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3836 sec_info |= SACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3837 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3838 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3839 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3840 wn = enc_to_utf16(fname, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3841 if (wn != NULL) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3842 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3843 (void)SetNamedSecurityInfoW( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3844 wn, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3845 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3846 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3847 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3848 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3849 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3850 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3851 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3852 vim_free(wn); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3853 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3854 else |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3855 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3856 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3857 (void)SetNamedSecurityInfo( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3858 (LPSTR)fname, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3859 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3860 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3861 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3862 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3863 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3864 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3865 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3866 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3867 } |
7 | 3868 #endif |
3869 } | |
3870 | |
3871 void | |
26 | 3872 mch_free_acl(vim_acl_T acl) |
7 | 3873 { |
3874 #ifdef HAVE_ACL | |
3875 struct my_acl *p = (struct my_acl *)acl; | |
3876 | |
3877 if (p != NULL) | |
3878 { | |
3879 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3880 vim_free(p); | |
3881 } | |
3882 #endif | |
3883 } | |
3884 | |
3885 #ifndef FEAT_GUI_W32 | |
3886 | |
3887 /* | |
3888 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3889 */ | |
3890 static BOOL WINAPI | |
3891 handler_routine( | |
3892 DWORD dwCtrlType) | |
3893 { | |
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
|
3894 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
|
3895 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
|
3896 |
7 | 3897 switch (dwCtrlType) |
3898 { | |
3899 case CTRL_C_EVENT: | |
3900 if (ctrl_c_interrupts) | |
3901 g_fCtrlCPressed = TRUE; | |
3902 return TRUE; | |
3903 | |
3904 case CTRL_BREAK_EVENT: | |
3905 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
|
3906 ctrl_break_was_pressed = TRUE; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3907 /* ReadConsoleInput is blocking, send a key event to continue. */ |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3908 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
|
3909 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
|
3910 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
|
3911 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
|
3912 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
|
3913 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
|
3914 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
|
3915 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3916 return TRUE; |
3917 | |
3918 /* fatal events: shut down gracefully */ | |
3919 case CTRL_CLOSE_EVENT: | |
3920 case CTRL_LOGOFF_EVENT: | |
3921 case CTRL_SHUTDOWN_EVENT: | |
3922 windgoto((int)Rows - 1, 0); | |
3923 g_fForceExit = TRUE; | |
3924 | |
1569 | 3925 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3926 (dwCtrlType == CTRL_CLOSE_EVENT |
3927 ? _("close") | |
3928 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3929 ? _("logoff") | |
3930 : _("shutdown"))); | |
3931 #ifdef DEBUG | |
3932 OutputDebugString(IObuff); | |
3933 #endif | |
3934 | |
3935 preserve_exit(); /* output IObuff, preserve files and exit */ | |
3936 | |
3937 return TRUE; /* not reached */ | |
3938 | |
3939 default: | |
3940 return FALSE; | |
3941 } | |
3942 } | |
3943 | |
3944 | |
3945 /* | |
3946 * set the tty in (raw) ? "raw" : "cooked" mode | |
3947 */ | |
3948 void | |
26 | 3949 mch_settmode(int tmode) |
7 | 3950 { |
3951 DWORD cmodein; | |
3952 DWORD cmodeout; | |
3953 BOOL bEnableHandler; | |
3954 | |
3955 GetConsoleMode(g_hConIn, &cmodein); | |
3956 GetConsoleMode(g_hConOut, &cmodeout); | |
3957 if (tmode == TMODE_RAW) | |
3958 { | |
3959 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3960 ENABLE_ECHO_INPUT); | |
3961 #ifdef FEAT_MOUSE | |
3962 if (g_fMouseActive) | |
3963 cmodein |= ENABLE_MOUSE_INPUT; | |
3964 #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
|
3965 cmodeout &= ~( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3966 #ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3967 /* Do not turn off the ENABLE_PROCESSRD_OUTPUT flag when using |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3968 * VTP. */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3969 ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) | |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3970 #else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3971 ENABLE_PROCESSED_OUTPUT | |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3972 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3973 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3974 bEnableHandler = TRUE; |
3975 } | |
3976 else /* cooked */ | |
3977 { | |
3978 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3979 ENABLE_ECHO_INPUT); | |
3980 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3981 bEnableHandler = FALSE; | |
3982 } | |
3983 SetConsoleMode(g_hConIn, cmodein); | |
3984 SetConsoleMode(g_hConOut, cmodeout); | |
3985 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3986 | |
3987 #ifdef MCH_WRITE_DUMP | |
3988 if (fdDump) | |
3989 { | |
3990 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3991 tmode == TMODE_RAW ? "raw" : | |
3992 tmode == TMODE_COOK ? "cooked" : "normal", | |
3993 cmodein, cmodeout); | |
3994 fflush(fdDump); | |
3995 } | |
3996 #endif | |
3997 } | |
3998 | |
3999 | |
4000 /* | |
4001 * Get the size of the current window in `Rows' and `Columns' | |
4002 * Return OK when size could be determined, FAIL otherwise. | |
4003 */ | |
4004 int | |
26 | 4005 mch_get_shellsize(void) |
7 | 4006 { |
4007 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
4008 | |
4009 if (!g_fTermcapMode && g_cbTermcap.IsValid) | |
4010 { | |
4011 /* | |
4012 * For some reason, we are trying to get the screen dimensions | |
4013 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
4014 * variables are really intended to mean the size of Vim screen | |
4015 * while in termcap mode. | |
4016 */ | |
4017 Rows = g_cbTermcap.Info.dwSize.Y; | |
4018 Columns = g_cbTermcap.Info.dwSize.X; | |
4019 } | |
4020 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
4021 { | |
4022 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
4023 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
4024 } | |
4025 else | |
4026 { | |
4027 Rows = 25; | |
4028 Columns = 80; | |
4029 } | |
4030 return OK; | |
4031 } | |
4032 | |
4033 /* | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4034 * 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
|
4035 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4036 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4037 ResizeConBuf( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4038 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4039 COORD coordScreen) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4040 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4041 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
|
4042 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4043 #ifdef MCH_WRITE_DUMP |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4044 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4045 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4046 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
|
4047 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4048 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4049 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4050 #endif |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4051 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4052 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4053 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4054 /* |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4055 * 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
|
4056 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4057 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4058 ResizeWindow( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4059 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4060 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
|
4061 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4062 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
|
4063 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4064 #ifdef MCH_WRITE_DUMP |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4065 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4066 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4067 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
|
4068 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4069 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4070 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4071 #endif |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4072 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4073 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4074 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4075 /* |
7 | 4076 * Set a console window to `xSize' * `ySize' |
4077 */ | |
4078 static void | |
4079 ResizeConBufAndWindow( | |
26 | 4080 HANDLE hConsole, |
4081 int xSize, | |
4082 int ySize) | |
7 | 4083 { |
4084 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ | |
4085 SMALL_RECT srWindowRect; /* hold the new console size */ | |
4086 COORD coordScreen; | |
14619
5e85d326d616
patch 8.1.0323: reverse order of VTP calls only needed the first time
Christian Brabandt <cb@256bit.org>
parents:
14567
diff
changeset
|
4087 static int resized = FALSE; |
7 | 4088 |
4089 #ifdef MCH_WRITE_DUMP | |
4090 if (fdDump) | |
4091 { | |
4092 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
4093 fflush(fdDump); | |
4094 } | |
4095 #endif | |
4096 | |
4097 /* get the largest size we can size the console window to */ | |
4098 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
4099 | |
4100 /* define the new console window size and scroll position */ | |
4101 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
4102 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
4103 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
4104 | |
4105 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
4106 { | |
4107 int sx, sy; | |
4108 | |
4109 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
4110 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
4111 if (sy < ySize || sx < xSize) | |
4112 { | |
4113 /* | |
4114 * Increasing number of lines/columns, do buffer first. | |
4115 * Use the maximal size in x and y direction. | |
4116 */ | |
4117 if (sy < ySize) | |
4118 coordScreen.Y = ySize; | |
4119 else | |
4120 coordScreen.Y = sy; | |
4121 if (sx < xSize) | |
4122 coordScreen.X = xSize; | |
4123 else | |
4124 coordScreen.X = sx; | |
4125 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
4126 } | |
4127 } | |
4128 | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4129 // define the new console buffer size |
7 | 4130 coordScreen.X = xSize; |
4131 coordScreen.Y = ySize; | |
4132 | |
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
|
4133 // 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
|
4134 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
|
4135 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4136 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
|
4137 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
|
4138 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4139 else |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4140 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4141 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
|
4142 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
|
4143 resized = TRUE; |
7 | 4144 } |
4145 } | |
4146 | |
4147 | |
4148 /* | |
4149 * Set the console window to `Rows' * `Columns' | |
4150 */ | |
4151 void | |
26 | 4152 mch_set_shellsize(void) |
7 | 4153 { |
4154 COORD coordScreen; | |
4155 | |
4156 /* Don't change window size while still starting up */ | |
4157 if (suppress_winsize != 0) | |
4158 { | |
4159 suppress_winsize = 2; | |
4160 return; | |
4161 } | |
4162 | |
4163 if (term_console) | |
4164 { | |
4165 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
4166 | |
4167 /* Clamp Rows and Columns to reasonable values */ | |
4168 if (Rows > coordScreen.Y) | |
4169 Rows = coordScreen.Y; | |
4170 if (Columns > coordScreen.X) | |
4171 Columns = coordScreen.X; | |
4172 | |
4173 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
4174 } | |
4175 } | |
4176 | |
4177 /* | |
4178 * Rows and/or Columns has changed. | |
4179 */ | |
4180 void | |
26 | 4181 mch_new_shellsize(void) |
7 | 4182 { |
4183 set_scroll_region(0, 0, Columns - 1, Rows - 1); | |
4184 } | |
4185 | |
4186 | |
4187 /* | |
4188 * Called when started up, to set the winsize that was delayed. | |
4189 */ | |
4190 void | |
26 | 4191 mch_set_winsize_now(void) |
7 | 4192 { |
4193 if (suppress_winsize == 2) | |
4194 { | |
4195 suppress_winsize = 0; | |
4196 mch_set_shellsize(); | |
4197 shell_resized(); | |
4198 } | |
4199 suppress_winsize = 0; | |
4200 } | |
4201 #endif /* FEAT_GUI_W32 */ | |
4202 | |
5547 | 4203 static BOOL |
4204 vim_create_process( | |
5556 | 4205 char *cmd, |
5569 | 4206 BOOL inherit_handles, |
5547 | 4207 DWORD flags, |
4208 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
|
4209 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
|
4210 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4211 char *cwd) |
5547 | 4212 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4213 #ifdef FEAT_MBYTE |
5547 | 4214 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
4215 { | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4216 BOOL ret; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4217 WCHAR *wcmd, *wcwd = NULL; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4218 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4219 wcmd = enc_to_utf16((char_u *)cmd, NULL); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4220 if (wcmd == NULL) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4221 goto fallback; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4222 if (cwd != NULL) |
5547 | 4223 { |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4224 wcwd = enc_to_utf16((char_u *)cwd, NULL); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4225 if (wcwd == NULL) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4226 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4227 vim_free(wcmd); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4228 goto fallback; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4229 } |
5547 | 4230 } |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4231 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4232 ret = CreateProcessW( |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4233 NULL, /* Executable name */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4234 wcmd, /* Command to execute */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4235 NULL, /* Process security attributes */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4236 NULL, /* Thread security attributes */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4237 inherit_handles, /* Inherit handles */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4238 flags, /* Creation flags */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4239 env, /* Environment */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4240 wcwd, /* Current directory */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4241 (LPSTARTUPINFOW)si, /* Startup information */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4242 pi); /* Process information */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4243 vim_free(wcmd); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4244 if (wcwd != NULL) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4245 vim_free(wcwd); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4246 return ret; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4247 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4248 fallback: |
5547 | 4249 #endif |
4250 return CreateProcess( | |
4251 NULL, /* Executable name */ | |
4252 cmd, /* Command to execute */ | |
4253 NULL, /* Process security attributes */ | |
4254 NULL, /* Thread security attributes */ | |
4255 inherit_handles, /* Inherit handles */ | |
4256 flags, /* Creation flags */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4257 env, /* Environment */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4258 cwd, /* Current directory */ |
5547 | 4259 si, /* Startup information */ |
4260 pi); /* Process information */ | |
4261 } | |
7 | 4262 |
4263 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4264 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
|
4265 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
|
4266 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
|
4267 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
|
4268 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4269 #ifdef FEAT_MBYTE |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4270 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4271 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4272 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4273 if (wcmd != NULL) |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4274 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4275 HINSTANCE ret; |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4276 ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, 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
|
4277 vim_free(wcmd); |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4278 return ret; |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4279 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4280 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4281 #endif |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4282 return ShellExecute(NULL, NULL, cmd, NULL, NULL, 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
|
4283 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4284 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4285 |
7 | 4286 #if defined(FEAT_GUI_W32) || defined(PROTO) |
4287 | |
4288 /* | |
4289 * Specialised version of system() for Win32 GUI mode. | |
4290 * This version proceeds as follows: | |
4291 * 1. Create a console window for use by the subprocess | |
4292 * 2. Run the subprocess (it gets the allocated console by default) | |
4293 * 3. Wait for the subprocess to terminate and get its exit code | |
4294 * 4. Prompt the user to press a key to close the console window | |
4295 */ | |
4296 static int | |
2935 | 4297 mch_system_classic(char *cmd, int options) |
7 | 4298 { |
4299 STARTUPINFO si; | |
4300 PROCESS_INFORMATION pi; | |
4301 DWORD ret = 0; | |
4302 HWND hwnd = GetFocus(); | |
4303 | |
4304 si.cb = sizeof(si); | |
4305 si.lpReserved = NULL; | |
4306 si.lpDesktop = NULL; | |
4307 si.lpTitle = NULL; | |
4308 si.dwFlags = STARTF_USESHOWWINDOW; | |
4309 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4310 * It's nicer to run a filter command in a minimized window. |
2643 | 4311 * Don't activate the window to keep focus on Vim. |
7 | 4312 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4313 if (options & SHELL_DOOUT) |
2643 | 4314 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 4315 else |
4316 si.wShowWindow = SW_SHOWNORMAL; | |
4317 si.cbReserved2 = 0; | |
4318 si.lpReserved2 = NULL; | |
4319 | |
4320 /* Now, run the command */ | |
5547 | 4321 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
|
4322 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
|
4323 &si, &pi, NULL, NULL); |
7 | 4324 |
4325 /* Wait for the command to terminate before continuing */ | |
4326 { | |
4327 #ifdef FEAT_GUI | |
4328 int delay = 1; | |
4329 | |
4330 /* Keep updating the window while waiting for the shell to finish. */ | |
4331 for (;;) | |
4332 { | |
4333 MSG msg; | |
4334 | |
3010 | 4335 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 4336 { |
4337 TranslateMessage(&msg); | |
3010 | 4338 pDispatchMessage(&msg); |
3720 | 4339 delay = 1; |
4340 continue; | |
7 | 4341 } |
4342 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4343 break; | |
4344 | |
4345 /* We start waiting for a very short time and then increase it, so | |
4346 * that we respond quickly when the process is quick, and don't | |
4347 * consume too much overhead when it's slow. */ | |
4348 if (delay < 50) | |
4349 delay += 10; | |
4350 } | |
4351 #else | |
4352 WaitForSingleObject(pi.hProcess, INFINITE); | |
4353 #endif | |
4354 | |
4355 /* Get the command exit code */ | |
4356 GetExitCodeProcess(pi.hProcess, &ret); | |
4357 } | |
4358 | |
4359 /* Close the handles to the subprocess, so that it goes away */ | |
4360 CloseHandle(pi.hThread); | |
4361 CloseHandle(pi.hProcess); | |
4362 | |
4363 /* Try to get input focus back. Doesn't always work though. */ | |
4364 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
4365 | |
4366 return ret; | |
4367 } | |
2935 | 4368 |
4369 /* | |
4370 * Thread launched by the gui to send the current buffer data to the | |
4371 * process. This way avoid to hang up vim totally if the children | |
4372 * process take a long time to process the lines. | |
4373 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4374 static unsigned int __stdcall |
2935 | 4375 sub_process_writer(LPVOID param) |
4376 { | |
4377 HANDLE g_hChildStd_IN_Wr = param; | |
4378 linenr_T lnum = curbuf->b_op_start.lnum; | |
4379 DWORD len = 0; | |
4380 DWORD l; | |
4381 char_u *lp = ml_get(lnum); | |
4382 char_u *s; | |
4383 int written = 0; | |
4384 | |
4385 for (;;) | |
4386 { | |
4387 l = (DWORD)STRLEN(lp + written); | |
4388 if (l == 0) | |
4389 len = 0; | |
4390 else if (lp[written] == NL) | |
4391 { | |
4392 /* NL -> NUL translation */ | |
4393 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
4394 } | |
4395 else | |
4396 { | |
4397 s = vim_strchr(lp + written, NL); | |
4398 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4399 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4400 &len, NULL); | |
4401 } | |
4402 if (len == (int)l) | |
4403 { | |
4404 /* Finished a line, add a NL, unless this line should not have | |
4405 * one. */ | |
4406 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4407 || (!curbuf->b_p_bin |
4408 && curbuf->b_p_fixeol) | |
2935 | 4409 || (lnum != curbuf->b_no_eol_lnum |
4410 && (lnum != curbuf->b_ml.ml_line_count | |
4411 || curbuf->b_p_eol))) | |
4412 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4413 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
|
4414 (LPDWORD)&vim_ignored, NULL); |
2935 | 4415 } |
4416 | |
4417 ++lnum; | |
4418 if (lnum > curbuf->b_op_end.lnum) | |
4419 break; | |
4420 | |
4421 lp = ml_get(lnum); | |
4422 written = 0; | |
4423 } | |
4424 else if (len > 0) | |
4425 written += len; | |
4426 } | |
4427 | |
4428 /* finished all the lines, close pipe */ | |
4429 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4430 return 0; |
2935 | 4431 } |
4432 | |
4433 | |
4434 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4435 | |
4436 /* | |
4437 * This function read from the children's stdout and write the | |
4438 * data on screen or in the buffer accordingly. | |
4439 */ | |
4440 static void | |
4441 dump_pipe(int options, | |
4442 HANDLE g_hChildStd_OUT_Rd, | |
4443 garray_T *ga, | |
4444 char_u buffer[], | |
4445 DWORD *buffer_off) | |
4446 { | |
4447 DWORD availableBytes = 0; | |
4448 DWORD i; | |
4449 int ret; | |
4450 DWORD len; | |
4451 DWORD toRead; | |
4452 int repeatCount; | |
4453 | |
4454 /* we query the pipe to see if there is any data to read | |
4455 * to avoid to perform a blocking read */ | |
4456 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4457 NULL, /* optional buffer */ | |
3622 | 4458 0, /* buffer size */ |
2935 | 4459 NULL, /* number of read bytes */ |
4460 &availableBytes, /* available bytes total */ | |
4461 NULL); /* byteLeft */ | |
4462 | |
4463 repeatCount = 0; | |
4464 /* We got real data in the pipe, read it */ | |
3622 | 4465 while (ret != 0 && availableBytes > 0) |
2935 | 4466 { |
4467 repeatCount++; | |
4468 toRead = | |
4469 # ifdef FEAT_MBYTE | |
4470 (DWORD)(BUFLEN - *buffer_off); | |
4471 # else | |
4472 (DWORD)BUFLEN; | |
4473 # endif | |
4474 toRead = availableBytes < toRead ? availableBytes : toRead; | |
4475 ReadFile(g_hChildStd_OUT_Rd, buffer | |
4476 # ifdef FEAT_MBYTE | |
4477 + *buffer_off, toRead | |
4478 # else | |
4479 , toRead | |
4480 # endif | |
4481 , &len, NULL); | |
4482 | |
4483 /* If we haven't read anything, there is a problem */ | |
4484 if (len == 0) | |
4485 break; | |
4486 | |
4487 availableBytes -= len; | |
4488 | |
4489 if (options & SHELL_READ) | |
4490 { | |
4491 /* Do NUL -> NL translation, append NL separated | |
4492 * lines to the current buffer. */ | |
4493 for (i = 0; i < len; ++i) | |
4494 { | |
4495 if (buffer[i] == NL) | |
4496 append_ga_line(ga); | |
4497 else if (buffer[i] == NUL) | |
4498 ga_append(ga, NL); | |
4499 else | |
4500 ga_append(ga, buffer[i]); | |
4501 } | |
4502 } | |
4503 # ifdef FEAT_MBYTE | |
4504 else if (has_mbyte) | |
4505 { | |
4506 int l; | |
3030 | 4507 int c; |
4508 char_u *p; | |
2935 | 4509 |
4510 len += *buffer_off; | |
4511 buffer[len] = NUL; | |
4512 | |
4513 /* Check if the last character in buffer[] is | |
4514 * incomplete, keep these bytes for the next | |
4515 * round. */ | |
4516 for (p = buffer; p < buffer + len; p += l) | |
4517 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4518 l = MB_CPTR2LEN(p); |
2935 | 4519 if (l == 0) |
4520 l = 1; /* NUL byte? */ | |
4521 else if (MB_BYTE2LEN(*p) != l) | |
4522 break; | |
4523 } | |
4524 if (p == buffer) /* no complete character */ | |
4525 { | |
4526 /* avoid getting stuck at an illegal byte */ | |
4527 if (len >= 12) | |
4528 ++p; | |
4529 else | |
4530 { | |
4531 *buffer_off = len; | |
4532 return; | |
4533 } | |
4534 } | |
4535 c = *p; | |
4536 *p = NUL; | |
4537 msg_puts(buffer); | |
4538 if (p < buffer + len) | |
4539 { | |
4540 *p = c; | |
4541 *buffer_off = (DWORD)((buffer + len) - p); | |
4542 mch_memmove(buffer, p, *buffer_off); | |
4543 return; | |
4544 } | |
4545 *buffer_off = 0; | |
4546 } | |
4547 # endif /* FEAT_MBYTE */ | |
4548 else | |
4549 { | |
4550 buffer[len] = NUL; | |
4551 msg_puts(buffer); | |
4552 } | |
4553 | |
4554 windgoto(msg_row, msg_col); | |
4555 cursor_on(); | |
4556 out_flush(); | |
4557 } | |
4558 } | |
4559 | |
4560 /* | |
4561 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4562 * for communication and doesn't open any new window. | |
4563 */ | |
4564 static int | |
4565 mch_system_piped(char *cmd, int options) | |
4566 { | |
4567 STARTUPINFO si; | |
4568 PROCESS_INFORMATION pi; | |
4569 DWORD ret = 0; | |
4570 | |
4571 HANDLE g_hChildStd_IN_Rd = NULL; | |
4572 HANDLE g_hChildStd_IN_Wr = NULL; | |
4573 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4574 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4575 | |
4576 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4577 DWORD len; | |
4578 | |
4579 /* buffer used to receive keys */ | |
4580 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4581 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4582 | |
4583 DWORD i; | |
4584 int c; | |
4585 int noread_cnt = 0; | |
4586 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
|
4587 int delay = 1; |
2935 | 4588 DWORD buffer_off = 0; /* valid bytes in buffer[] */ |
3361 | 4589 char *p = NULL; |
2935 | 4590 |
4591 SECURITY_ATTRIBUTES saAttr; | |
4592 | |
4593 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4594 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4595 saAttr.bInheritHandle = TRUE; | |
4596 saAttr.lpSecurityDescriptor = NULL; | |
4597 | |
4598 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4599 /* 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
|
4600 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4601 /* Create a pipe for the child process's STDIN. */ |
4602 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4603 /* 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
|
4604 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4605 { |
4606 CloseHandle(g_hChildStd_IN_Rd); | |
4607 CloseHandle(g_hChildStd_IN_Wr); | |
4608 CloseHandle(g_hChildStd_OUT_Rd); | |
4609 CloseHandle(g_hChildStd_OUT_Wr); | |
4610 MSG_PUTS(_("\nCannot create pipes\n")); | |
4611 } | |
4612 | |
4613 si.cb = sizeof(si); | |
4614 si.lpReserved = NULL; | |
4615 si.lpDesktop = NULL; | |
4616 si.lpTitle = NULL; | |
4617 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4618 | |
4619 /* set-up our file redirection */ | |
4620 si.hStdError = g_hChildStd_OUT_Wr; | |
4621 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4622 si.hStdInput = g_hChildStd_IN_Rd; | |
4623 si.wShowWindow = SW_HIDE; | |
4624 si.cbReserved2 = 0; | |
4625 si.lpReserved2 = NULL; | |
4626 | |
4627 if (options & SHELL_READ) | |
4628 ga_init2(&ga, 1, BUFLEN); | |
4629 | |
3361 | 4630 if (cmd != NULL) |
4631 { | |
4632 p = (char *)vim_strsave((char_u *)cmd); | |
4633 if (p != NULL) | |
4634 unescape_shellxquote((char_u *)p, p_sxe); | |
4635 else | |
4636 p = cmd; | |
4637 } | |
4638 | |
5547 | 4639 /* Now, run the command. |
4640 * About "Inherit handles" being TRUE: this command can be litigious, | |
4641 * handle inheritance was deactivated for pending temp file, but, if we | |
4642 * 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
|
4643 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
|
4644 &si, &pi, NULL, NULL); |
2935 | 4645 |
3361 | 4646 if (p != cmd) |
4647 vim_free(p); | |
2935 | 4648 |
4649 /* Close our unused side of the pipes */ | |
4650 CloseHandle(g_hChildStd_IN_Rd); | |
4651 CloseHandle(g_hChildStd_OUT_Wr); | |
4652 | |
4653 if (options & SHELL_WRITE) | |
4654 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4655 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4656 _beginthreadex(NULL, /* security attributes */ |
2935 | 4657 0, /* default stack size */ |
4658 sub_process_writer, /* function to be executed */ | |
4659 g_hChildStd_IN_Wr, /* parameter */ | |
4660 0, /* creation flag, start immediately */ | |
4661 NULL); /* we don't care about thread id */ | |
4662 CloseHandle(thread); | |
4663 g_hChildStd_IN_Wr = NULL; | |
4664 } | |
4665 | |
4666 /* Keep updating the window while waiting for the shell to finish. */ | |
4667 for (;;) | |
4668 { | |
4669 MSG msg; | |
4670 | |
5553 | 4671 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4672 { |
4673 TranslateMessage(&msg); | |
5553 | 4674 pDispatchMessage(&msg); |
2935 | 4675 } |
4676 | |
4677 /* write pipe information in the window */ | |
4678 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4679 # ifdef FEAT_GUI | |
4680 || gui.in_use | |
4681 # endif | |
4682 ) | |
4683 { | |
4684 len = 0; | |
4685 if (!(options & SHELL_EXPAND) | |
4686 && ((options & | |
4687 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4688 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4689 # ifdef FEAT_GUI | |
4690 || gui.in_use | |
4691 # endif | |
4692 ) | |
4693 && (ta_len > 0 || noread_cnt > 4)) | |
4694 { | |
4695 if (ta_len == 0) | |
4696 { | |
4697 /* Get extra characters when we don't have any. Reset the | |
4698 * counter and timer. */ | |
4699 noread_cnt = 0; | |
4700 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4701 } | |
4702 if (ta_len > 0 || len > 0) | |
4703 { | |
4704 /* | |
4705 * For pipes: Check for CTRL-C: send interrupt signal to | |
4706 * child. Check for CTRL-D: EOF, close pipe to child. | |
4707 */ | |
4708 if (len == 1 && cmd != NULL) | |
4709 { | |
4710 if (ta_buf[ta_len] == Ctrl_C) | |
4711 { | |
4712 /* Learn what exit code is expected, for | |
4713 * now put 9 as SIGKILL */ | |
4714 TerminateProcess(pi.hProcess, 9); | |
4715 } | |
4716 if (ta_buf[ta_len] == Ctrl_D) | |
4717 { | |
4718 CloseHandle(g_hChildStd_IN_Wr); | |
4719 g_hChildStd_IN_Wr = NULL; | |
4720 } | |
4721 } | |
4722 | |
4723 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4724 for (i = ta_len; i < ta_len + len; ++i) | |
4725 { | |
4726 if (ta_buf[i] == CSI && len - i > 2) | |
4727 { | |
4728 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4729 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4730 { | |
4731 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4732 (size_t)(len - i - 2)); | |
4733 if (c == K_DEL || c == K_KDEL) | |
4734 ta_buf[i] = DEL; | |
4735 else | |
4736 ta_buf[i] = Ctrl_H; | |
4737 len -= 2; | |
4738 } | |
4739 } | |
4740 else if (ta_buf[i] == '\r') | |
4741 ta_buf[i] = '\n'; | |
4742 # ifdef FEAT_MBYTE | |
4743 if (has_mbyte) | |
4744 i += (*mb_ptr2len_len)(ta_buf + i, | |
4745 ta_len + len - i) - 1; | |
4746 # endif | |
4747 } | |
4748 | |
4749 /* | |
4750 * For pipes: echo the typed characters. For a pty this | |
4751 * does not seem to work. | |
4752 */ | |
4753 for (i = ta_len; i < ta_len + len; ++i) | |
4754 { | |
4755 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4756 msg_putchar(ta_buf[i]); | |
4757 # ifdef FEAT_MBYTE | |
4758 else if (has_mbyte) | |
4759 { | |
4760 int l = (*mb_ptr2len)(ta_buf + i); | |
4761 | |
4762 msg_outtrans_len(ta_buf + i, l); | |
4763 i += l - 1; | |
4764 } | |
4765 # endif | |
4766 else | |
4767 msg_outtrans_len(ta_buf + i, 1); | |
4768 } | |
4769 windgoto(msg_row, msg_col); | |
4770 out_flush(); | |
4771 | |
4772 ta_len += len; | |
4773 | |
4774 /* | |
4775 * Write the characters to the child, unless EOF has been | |
4776 * typed for pipes. Write one character at a time, to | |
4777 * avoid losing too much typeahead. When writing buffer | |
4778 * lines, drop the typed characters (only check for | |
4779 * CTRL-C). | |
4780 */ | |
4781 if (options & SHELL_WRITE) | |
4782 ta_len = 0; | |
4783 else if (g_hChildStd_IN_Wr != NULL) | |
4784 { | |
4785 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4786 1, &len, NULL); | |
4787 // if we are typing in, we want to keep things reactive | |
4788 delay = 1; | |
4789 if (len > 0) | |
4790 { | |
4791 ta_len -= len; | |
4792 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4793 } | |
4794 } | |
4795 } | |
4796 } | |
4797 } | |
4798 | |
4799 if (ta_len) | |
4800 ui_inchar_undo(ta_buf, ta_len); | |
4801 | |
4802 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4803 { | |
3030 | 4804 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4805 break; |
4806 } | |
4807 | |
4808 ++noread_cnt; | |
3030 | 4809 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4810 |
4811 /* We start waiting for a very short time and then increase it, so | |
4812 * that we respond quickly when the process is quick, and don't | |
4813 * consume too much overhead when it's slow. */ | |
4814 if (delay < 50) | |
4815 delay += 10; | |
4816 } | |
4817 | |
4818 /* Close the pipe */ | |
4819 CloseHandle(g_hChildStd_OUT_Rd); | |
4820 if (g_hChildStd_IN_Wr != NULL) | |
4821 CloseHandle(g_hChildStd_IN_Wr); | |
4822 | |
4823 WaitForSingleObject(pi.hProcess, INFINITE); | |
4824 | |
4825 /* Get the command exit code */ | |
4826 GetExitCodeProcess(pi.hProcess, &ret); | |
4827 | |
4828 if (options & SHELL_READ) | |
4829 { | |
4830 if (ga.ga_len > 0) | |
4831 { | |
4832 append_ga_line(&ga); | |
4833 /* remember that the NL was missing */ | |
4834 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4835 } | |
4836 else | |
4837 curbuf->b_no_eol_lnum = 0; | |
4838 ga_clear(&ga); | |
4839 } | |
4840 | |
4841 /* Close the handles to the subprocess, so that it goes away */ | |
4842 CloseHandle(pi.hThread); | |
4843 CloseHandle(pi.hProcess); | |
4844 | |
4845 return ret; | |
4846 } | |
4847 | |
4848 static int | |
4849 mch_system(char *cmd, int options) | |
4850 { | |
4851 /* 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
|
4852 if (!p_stmp) |
2935 | 4853 return mch_system_piped(cmd, options); |
4854 else | |
4855 return mch_system_classic(cmd, options); | |
4856 } | |
7 | 4857 #else |
4858 | |
5547 | 4859 # ifdef FEAT_MBYTE |
4860 static int | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4861 mch_system(char *cmd, int options) |
5547 | 4862 { |
4863 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4864 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4865 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 4866 if (wcmd != NULL) |
4867 { | |
4868 int ret = _wsystem(wcmd); | |
4869 vim_free(wcmd); | |
4870 return ret; | |
4871 } | |
4872 } | |
4873 return system(cmd); | |
4874 } | |
4875 # else | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4876 # define mch_system(c, o) system(c) |
5547 | 4877 # endif |
7 | 4878 |
4879 #endif | |
4880 | |
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
|
4881 #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
|
4882 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4883 * 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
|
4884 */ |
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 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
|
4886 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
|
4887 char_u *cmd, |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4888 int options UNUSED) /* SHELL_*, see vim.h */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
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 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
|
4891 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
|
4892 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
|
4893 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
|
4894 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
|
4895 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
|
4896 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
|
4897 aco_save_T aco; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4898 oparg_T oa; /* operator arguments */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4899 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4900 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4901 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
|
4902 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4903 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4904 newcmd = lalloc(cmdlen, TRUE); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4905 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
|
4906 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4907 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4908 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4909 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
|
4910 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
|
4911 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4912 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4913 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4914 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
|
4915 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
|
4916 } |
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
|
4917 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4918 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
|
4919 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4920 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
|
4921 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
|
4922 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
|
4923 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
|
4924 if (buf == NULL) |
cc7dc249e371
patch 8.0.1619: Win32 GUI: crash when winpty is not installed
Christian Brabandt <cb@256bit.org>
parents:
13487
diff
changeset
|
4925 return 255; |
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
|
4926 |
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
|
4927 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
|
4928 ++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
|
4929 |
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
|
4930 /* Find a window to make "buf" curbuf. */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4931 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
|
4932 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4933 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
|
4934 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
|
4935 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4936 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
|
4937 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4938 /* If terminal_loop() returns OK we got a key that is handled |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4939 * in Normal model. We don't do redrawing anyway. */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4940 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
|
4941 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
|
4942 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4943 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
|
4944 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
|
4945 } |
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
|
4946 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
|
4947 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
|
4948 |
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
|
4949 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
|
4950 |
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
|
4951 /* restore curwin/curbuf and a few other things */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4952 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
|
4953 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4954 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
|
4955 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
|
4956 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4957 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
|
4958 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
|
4959 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4960 #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
|
4961 |
7 | 4962 /* |
4963 * Either execute a command by calling the shell or start a new shell | |
4964 */ | |
4965 int | |
4966 mch_call_shell( | |
26 | 4967 char_u *cmd, |
4968 int options) /* SHELL_*, see vim.h */ | |
7 | 4969 { |
4970 int x = 0; | |
4971 int tmode = cur_tmode; | |
4972 #ifdef FEAT_TITLE | |
6293 | 4973 char szShellTitle[512]; |
6290 | 4974 # ifdef FEAT_MBYTE |
6293 | 4975 int did_set_title = FALSE; |
4976 | |
6290 | 4977 /* Change the title to reflect that we are in a subshell. */ |
4978 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4979 { | |
4980 WCHAR szShellTitle[512]; | |
4981 | |
4982 if (GetConsoleTitleW(szShellTitle, | |
4983 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) | |
4984 { | |
4985 if (cmd == NULL) | |
4986 wcscat(szShellTitle, L" :sh"); | |
4987 else | |
4988 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4989 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL); |
6290 | 4990 |
4991 if (wn != NULL) | |
4992 { | |
4993 wcscat(szShellTitle, L" - !"); | |
4994 if ((wcslen(szShellTitle) + wcslen(wn) < | |
4995 sizeof(szShellTitle)/sizeof(WCHAR))) | |
4996 wcscat(szShellTitle, wn); | |
4997 SetConsoleTitleW(szShellTitle); | |
4998 vim_free(wn); | |
6293 | 4999 did_set_title = TRUE; |
6290 | 5000 } |
5001 } | |
5002 } | |
5003 } | |
6293 | 5004 if (!did_set_title) |
5005 # endif | |
5006 /* Change the title to reflect that we are in a subshell. */ | |
5007 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0) | |
7 | 5008 { |
6293 | 5009 if (cmd == NULL) |
5010 strcat(szShellTitle, " :sh"); | |
5011 else | |
5012 { | |
5013 strcat(szShellTitle, " - !"); | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5014 if ((strlen(szShellTitle) + strlen((char *)cmd) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5015 < sizeof(szShellTitle))) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5016 strcat(szShellTitle, (char *)cmd); |
6293 | 5017 } |
5018 SetConsoleTitle(szShellTitle); | |
7 | 5019 } |
5020 #endif | |
5021 | |
5022 out_flush(); | |
5023 | |
5024 #ifdef MCH_WRITE_DUMP | |
5025 if (fdDump) | |
5026 { | |
5027 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
5028 fflush(fdDump); | |
5029 } | |
5030 #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
|
5031 #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
|
5032 /* TODO: make the terminal window work with input or output redirected. */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5033 if (vim_strchr(p_go, GO_TERMINAL) != 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
|
5034 && (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
|
5035 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5036 /* Use a terminal window to run the command in. */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5037 x = mch_call_shell_terminal(cmd, options); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5038 #ifdef FEAT_TITLE |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5039 resettitle(); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5040 #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
|
5041 return x; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5042 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
5043 #endif |
7 | 5044 |
5045 /* | |
5046 * Catch all deadly signals while running the external command, because a | |
5047 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
5048 */ | |
5049 signal(SIGINT, SIG_IGN); | |
5050 #if defined(__GNUC__) && !defined(__MINGW32__) | |
5051 signal(SIGKILL, SIG_IGN); | |
5052 #else | |
5053 signal(SIGBREAK, SIG_IGN); | |
5054 #endif | |
5055 signal(SIGILL, SIG_IGN); | |
5056 signal(SIGFPE, SIG_IGN); | |
5057 signal(SIGSEGV, SIG_IGN); | |
5058 signal(SIGTERM, SIG_IGN); | |
5059 signal(SIGABRT, SIG_IGN); | |
5060 | |
5061 if (options & SHELL_COOKED) | |
5062 settmode(TMODE_COOK); /* set to normal mode */ | |
5063 | |
5064 if (cmd == NULL) | |
5065 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5066 x = mch_system((char *)p_sh, options); |
7 | 5067 } |
5068 else | |
5069 { | |
5070 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 5071 char_u *newcmd = NULL; |
5072 char_u *cmdbase = cmd; | |
5073 long_u cmdlen; | |
3361 | 5074 |
5075 /* Skip a leading ", ( and "(. */ | |
5076 if (*cmdbase == '"' ) | |
5077 ++cmdbase; | |
5078 if (*cmdbase == '(') | |
5079 ++cmdbase; | |
5080 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5081 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 5082 { |
5083 STARTUPINFO si; | |
5084 PROCESS_INFORMATION pi; | |
5085 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
|
5086 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 5087 char_u *p; |
5088 | |
5627 | 5089 ZeroMemory(&si, sizeof(si)); |
3361 | 5090 si.cb = sizeof(si); |
5091 si.lpReserved = NULL; | |
5092 si.lpDesktop = NULL; | |
5093 si.lpTitle = NULL; | |
5094 si.dwFlags = 0; | |
5095 si.cbReserved2 = 0; | |
5096 si.lpReserved2 = NULL; | |
5097 | |
5098 cmdbase = skipwhite(cmdbase + 5); | |
5099 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
|
5100 && VIM_ISWHITE(cmdbase[4])) |
3361 | 5101 { |
5102 cmdbase = skipwhite(cmdbase + 4); | |
5103 si.dwFlags = STARTF_USESHOWWINDOW; | |
5104 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
|
5105 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 5106 } |
5107 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
|
5108 && VIM_ISWHITE(cmdbase[2])) |
3361 | 5109 { |
5110 cmdbase = skipwhite(cmdbase + 2); | |
5111 flags = CREATE_NO_WINDOW; | |
5112 si.dwFlags = STARTF_USESTDHANDLES; | |
5113 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 5114 GENERIC_READ, // Access flags |
3361 | 5115 0, // Share flags |
3363 | 5116 NULL, // Security att. |
5117 OPEN_EXISTING, // Open flags | |
5118 FILE_ATTRIBUTE_NORMAL, // File att. | |
5119 NULL); // Temp file | |
3361 | 5120 si.hStdOutput = si.hStdInput; |
5121 si.hStdError = si.hStdInput; | |
5122 } | |
5123 | |
5124 /* Remove a trailing ", ) and )" if they have a match | |
5125 * at the start of the command. */ | |
5126 if (cmdbase > cmd) | |
5127 { | |
5128 p = cmdbase + STRLEN(cmdbase); | |
5129 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
5130 *--p = NUL; | |
5131 if (p > cmdbase && p[-1] == ')' | |
5132 && (*cmd =='(' || cmd[1] == '(')) | |
5133 *--p = NUL; | |
5134 } | |
5135 | |
3363 | 5136 newcmd = cmdbase; |
5137 unescape_shellxquote(cmdbase, p_sxe); | |
5138 | |
3361 | 5139 /* |
3363 | 5140 * If creating new console, arguments are passed to the |
5141 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
5142 * correctly for current 'cmd.exe'. So unescape characters in | |
5143 * shellxescape except '|' for avoiding to be treated as | |
5144 * argument to them. Pass the arguments to sub-shell. | |
3361 | 5145 */ |
3363 | 5146 if (flags != CREATE_NEW_CONSOLE) |
5147 { | |
5148 char_u *subcmd; | |
3367 | 5149 char_u *cmd_shell = mch_getenv("COMSPEC"); |
5150 | |
5151 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
|
5152 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5153 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5154 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5155 (char_u *)"|", '^', FALSE); |
3363 | 5156 if (subcmd != NULL) |
5157 { | |
5158 /* make "cmd.exe /c arguments" */ | |
5159 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
5160 newcmd = lalloc(cmdlen, TRUE); | |
5161 if (newcmd != NULL) | |
5162 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 5163 cmd_shell, subcmd); |
3363 | 5164 else |
5165 newcmd = cmdbase; | |
3367 | 5166 vim_free(subcmd); |
3363 | 5167 } |
5168 } | |
3361 | 5169 |
5170 /* | |
5171 * Now, start the command as a process, so that it doesn't | |
5172 * inherit our handles which causes unpleasant dangling swap | |
5173 * files if we exit before the spawned process | |
5174 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5175 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
|
5176 &si, &pi, NULL, NULL)) |
3361 | 5177 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
|
5178 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
|
5179 > (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
|
5180 x = 0; |
3361 | 5181 else |
5182 { | |
5183 x = -1; | |
5184 #ifdef FEAT_GUI_W32 | |
5185 EMSG(_("E371: Command not found")); | |
5186 #endif | |
5187 } | |
3363 | 5188 |
5189 if (newcmd != cmdbase) | |
5190 vim_free(newcmd); | |
5191 | |
5627 | 5192 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 5193 { |
5627 | 5194 /* Close the handle to \\.\NUL created above. */ |
3361 | 5195 CloseHandle(si.hStdInput); |
5196 } | |
5197 /* Close the handles to the subprocess, so that it goes away */ | |
5198 CloseHandle(pi.hThread); | |
5199 CloseHandle(pi.hProcess); | |
5200 } | |
5201 else | |
5202 { | |
3363 | 5203 cmdlen = ( |
7 | 5204 #ifdef FEAT_GUI_W32 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5205 (!p_stmp ? 0 : STRLEN(vimrun_path)) + |
7 | 5206 #endif |
1569 | 5207 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10); |
5208 | |
3361 | 5209 newcmd = lalloc(cmdlen, TRUE); |
5210 if (newcmd != NULL) | |
7 | 5211 { |
5212 #if defined(FEAT_GUI_W32) | |
5213 if (need_vimrun_warning) | |
5214 { | |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5215 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
|
5216 "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
|
5217 "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
|
5218 char *title = _("Vim Warning"); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5219 # ifdef FEAT_MBYTE |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5220 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5221 { |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5222 WCHAR *wmsg = enc_to_utf16((char_u *)msg, NULL); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5223 WCHAR *wtitle = enc_to_utf16((char_u *)title, NULL); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5224 |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5225 if (wmsg != NULL && wtitle != NULL) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5226 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5227 vim_free(wmsg); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5228 vim_free(wtitle); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5229 } |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5230 else |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5231 # endif |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5232 MessageBox(NULL, msg, title, MB_ICONWARNING); |
7 | 5233 need_vimrun_warning = FALSE; |
5234 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5235 if (!s_dont_use_vimrun && p_stmp) |
7 | 5236 /* Use vimrun to execute the command. It opens a console |
5237 * 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
|
5238 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 5239 vimrun_path, |
5240 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
5241 ? "-s " : "", | |
5242 p_sh, p_shcf, cmd); | |
5243 else | |
5244 #endif | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5245 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 5246 p_sh, p_shcf, cmd); |
7 | 5247 x = mch_system((char *)newcmd, options); |
3361 | 5248 vim_free(newcmd); |
7 | 5249 } |
5250 } | |
5251 } | |
5252 | |
5253 if (tmode == TMODE_RAW) | |
5254 settmode(TMODE_RAW); /* set to raw mode */ | |
5255 | |
5256 /* Print the return value, unless "vimrun" was used. */ | |
5257 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent | |
5258 #if defined(FEAT_GUI_W32) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5259 && ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) |
7 | 5260 #endif |
5261 ) | |
5262 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5263 smsg((char_u *)_("shell returned %d"), x); |
7 | 5264 msg_putchar('\n'); |
5265 } | |
5266 #ifdef FEAT_TITLE | |
5267 resettitle(); | |
5268 #endif | |
5269 | |
5270 signal(SIGINT, SIG_DFL); | |
5271 #if defined(__GNUC__) && !defined(__MINGW32__) | |
5272 signal(SIGKILL, SIG_DFL); | |
5273 #else | |
5274 signal(SIGBREAK, SIG_DFL); | |
5275 #endif | |
5276 signal(SIGILL, SIG_DFL); | |
5277 signal(SIGFPE, SIG_DFL); | |
5278 signal(SIGSEGV, SIG_DFL); | |
5279 signal(SIGTERM, SIG_DFL); | |
5280 signal(SIGABRT, SIG_DFL); | |
5281 | |
5282 return x; | |
5283 } | |
5284 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5285 #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
|
5286 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5287 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
|
5288 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
|
5289 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
|
5290 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
|
5291 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
|
5292 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
|
5293 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5294 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5295 HANDLE h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5296 # ifdef FEAT_MBYTE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5297 WCHAR *wn = NULL; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5298 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5299 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5300 wn = enc_to_utf16(fname, NULL); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5301 if (wn != NULL) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5302 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5303 h = CreateFileW(wn, dwDesiredAccess, dwShareMode, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5304 lpSecurityAttributes, dwCreationDisposition, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5305 dwFlagsAndAttributes, NULL); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5306 vim_free(wn); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5307 } |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5308 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5309 if (wn == NULL) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5310 # endif |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5311 h = CreateFile((LPCSTR)fname, dwDesiredAccess, dwShareMode, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5312 lpSecurityAttributes, dwCreationDisposition, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5313 dwFlagsAndAttributes, NULL); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5314 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5315 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5316 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5317 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5318 * 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
|
5319 * 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
|
5320 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
5321 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
|
5322 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
|
5323 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5324 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
|
5325 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
|
5326 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
|
5327 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5328 /* for last \0 */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5329 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
|
5330 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5331 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5332 if (base) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5333 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5334 WCHAR *p = (WCHAR*) base; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5335 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5336 /* for last \0 */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5337 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
|
5338 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5339 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5340 while (*p != 0 || *(p + 1) != 0) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5341 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5342 if (ga_grow(gap, 1) == OK) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5343 *((WCHAR*)gap->ga_data + gap->ga_len++) = *p; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5344 p++; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5345 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5346 FreeEnvironmentStrings(base); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5347 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5348 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5349 |
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
|
5350 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
|
5351 { |
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
|
5352 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
|
5353 { |
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
|
5354 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
|
5355 { |
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
|
5356 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
|
5357 WCHAR *wkey = enc_to_utf16((char_u *)hi->hi_key, 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
|
5358 WCHAR *wval = enc_to_utf16(get_tv_string(item), 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
|
5359 --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
|
5360 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
|
5361 { |
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
|
5362 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
|
5363 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
|
5364 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
|
5365 |
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
|
5366 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
|
5367 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
|
5368 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
|
5369 *((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
|
5370 *((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
|
5371 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
|
5372 *((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
|
5373 *((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
|
5374 } |
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
|
5375 if (wkey != NULL) vim_free(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
|
5376 if (wval != NULL) 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
|
5377 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5378 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5379 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5380 |
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
|
5381 # 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
|
5382 { |
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
|
5383 # 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
|
5384 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
|
5385 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
|
5386 # 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
|
5387 # 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
|
5388 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
|
5389 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
|
5390 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5391 // 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
|
5392 // 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
|
5393 // 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
|
5394 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
|
5395 # 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
|
5396 + 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
|
5397 # 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
|
5398 # 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
|
5399 + 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
|
5400 # 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
|
5401 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5402 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5403 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
|
5404 { |
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
|
5405 # 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
|
5406 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
|
5407 *((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
|
5408 (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
|
5409 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
|
5410 *((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
|
5411 (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
|
5412 *((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
|
5413 # 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
|
5414 # 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
|
5415 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
|
5416 { |
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
|
5417 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
|
5418 *((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
|
5419 (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
|
5420 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
|
5421 *((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
|
5422 (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
|
5423 *((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
|
5424 } |
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
|
5425 # 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
|
5426 } |
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
|
5427 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5428 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5429 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5430 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5431 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5432 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
|
5433 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5434 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5435 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5436 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5437 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5438 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5439 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5440 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5441 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
|
5442 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5443 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5444 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
|
5445 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
|
5446 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
|
5447 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
|
5448 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
|
5449 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
|
5450 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
|
5451 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5452 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
|
5453 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5454 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5455 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5456 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5457 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5458 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5459 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5460 efd[1] = INVALID_HANDLE_VALUE; |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5461 ga_init2(&ga, (int)sizeof(wchar_t), 500); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5462 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5463 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5464 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5465 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5466 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5467 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5468 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5469 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5470 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
|
5471 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
|
5472 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5473 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5474 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5475 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5476 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5477 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5478 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5479 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5480 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5481 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5482 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5483 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5484 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5485 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
|
5486 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5487 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
|
5488 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5489 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5490 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
|
5491 { |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5492 EMSG2(_(e_notopen), fname); |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5493 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5494 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5495 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5496 else if (!use_null_for_in && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5497 (!CreatePipe(&ifd[0], &ifd[1], &saAttr, 0) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5498 || !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
|
5499 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5500 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5501 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5502 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5503 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
|
5504 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5505 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
|
5506 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5507 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5508 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
|
5509 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5510 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5511 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5512 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5513 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5514 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5515 (!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
|
5516 || !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
|
5517 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5518 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5519 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5520 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5521 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
|
5522 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5523 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
|
5524 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5525 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5526 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
|
5527 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5528 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5529 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5530 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5531 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5532 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
|
5533 (!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
|
5534 || !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
|
5535 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5536 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5537 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5538 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5539 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5540 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
|
5541 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5542 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
|
5543 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5544 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5545 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5546 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5547 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5548 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5549 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5550 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5551 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5552 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5553 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5554 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5555 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5556 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
|
5557 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5558 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5559 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
|
5560 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5561 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
|
5562 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5563 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
|
5564 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5565 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5566 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5567 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5568 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5569 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5570 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5571 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
|
5572 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5573 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5574 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5575 /* if failing, switch the way to terminate |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5576 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5577 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5578 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5579 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5580 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5581 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5582 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5583 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5584 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5585 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5586 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5587 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5588 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
|
5589 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5590 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5591 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5592 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5593 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5594 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5595 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
|
5596 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5597 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
|
5598 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5599 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
|
5600 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5601 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5602 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5603 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5604 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5605 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5606 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5607 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5608 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5609 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5610 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5611 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5612 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
|
5613 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5614 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5615 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5616 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5617 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5618 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5619 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5620 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5621 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
|
5622 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5623 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5624 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5625 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
|
5626 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5627 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
|
5628 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5629 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5630 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5631 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5632 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5633 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5634 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5635 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5636 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
|
5637 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5638 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5639 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5640 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5641 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5642 while (job != NULL) |
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 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5645 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5646 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5647 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
|
5648 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5649 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5650 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5651 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5652 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
|
5653 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5654 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5655 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5656 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5657 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5658 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5659 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5660 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
|
5661 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5662 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
|
5663 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5664 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
|
5665 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5666 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5667 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5668 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5669 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5670 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5671 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5672 terminate_all(HANDLE process, int code) |
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 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5675 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5676 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5677 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5678 if (pid != 0) |
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 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5681 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5682 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5683 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5684 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5685 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5686 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5687 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5688 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5689 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5690 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5691 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5692 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5693 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5694 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5695 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5696 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5697 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5698 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5699 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5700 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5701 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5702 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5703 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5704 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5705 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5706 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5707 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5708 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5709 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5710 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5711 * 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
|
5712 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5713 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5714 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
|
5715 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5716 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5717 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5718 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
|
5719 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5720 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5721 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5722 return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL; |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5723 return terminate_all(job->jv_proc_info.hProcess, 0) ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5724 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5725 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5726 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
|
5727 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5728 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5729 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
|
5730 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5731 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5732 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5733 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5734 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5735 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5736 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5737 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5738 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5739 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5740 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5741 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5742 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5743 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5744 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5745 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5746 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5747 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5748 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5749 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5750 |
7 | 5751 |
5752 #ifndef FEAT_GUI_W32 | |
5753 | |
5754 /* | |
5755 * Start termcap mode | |
5756 */ | |
5757 static void | |
5758 termcap_mode_start(void) | |
5759 { | |
5760 DWORD cmodein; | |
5761 | |
5762 if (g_fTermcapMode) | |
5763 return; | |
5764 | |
5765 SaveConsoleBuffer(&g_cbNonTermcap); | |
5766 | |
5767 if (g_cbTermcap.IsValid) | |
5768 { | |
5769 /* | |
5770 * We've been in termcap mode before. Restore certain screen | |
5771 * characteristics, including the buffer size and the window | |
5772 * size. Since we will be redrawing the screen, we don't need | |
5773 * to restore the actual contents of the buffer. | |
5774 */ | |
5775 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
|
5776 reset_console_color_rgb(); |
7 | 5777 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5778 Rows = g_cbTermcap.Info.dwSize.Y; | |
5779 Columns = g_cbTermcap.Info.dwSize.X; | |
5780 } | |
5781 else | |
5782 { | |
5783 /* | |
5784 * This is our first time entering termcap mode. Clear the console | |
5785 * screen buffer, and resize the buffer to match the current window | |
5786 * size. We will use this as the size of our editing environment. | |
5787 */ | |
5788 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
|
5789 set_console_color_rgb(); |
7 | 5790 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5791 } | |
5792 | |
5793 #ifdef FEAT_TITLE | |
5794 resettitle(); | |
5795 #endif | |
5796 | |
5797 GetConsoleMode(g_hConIn, &cmodein); | |
5798 #ifdef FEAT_MOUSE | |
5799 if (g_fMouseActive) | |
5800 cmodein |= ENABLE_MOUSE_INPUT; | |
5801 else | |
5802 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5803 #endif | |
5804 cmodein |= ENABLE_WINDOW_INPUT; | |
5805 SetConsoleMode(g_hConIn, cmodein); | |
5806 | |
5807 redraw_later_clear(); | |
5808 g_fTermcapMode = TRUE; | |
5809 } | |
5810 | |
5811 | |
5812 /* | |
5813 * End termcap mode | |
5814 */ | |
5815 static void | |
5816 termcap_mode_end(void) | |
5817 { | |
5818 DWORD cmodein; | |
5819 ConsoleBuffer *cb; | |
5820 COORD coord; | |
5821 DWORD dwDummy; | |
5822 | |
5823 if (!g_fTermcapMode) | |
5824 return; | |
5825 | |
5826 SaveConsoleBuffer(&g_cbTermcap); | |
5827 | |
5828 GetConsoleMode(g_hConIn, &cmodein); | |
5829 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5830 SetConsoleMode(g_hConIn, cmodein); | |
5831 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5832 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5833 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5834 #else |
7 | 5835 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5836 #endif |
7 | 5837 RestoreConsoleBuffer(cb, p_rs); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5838 reset_console_color_rgb(); |
7 | 5839 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5840 | |
5841 if (p_rs || exiting) | |
5842 { | |
5843 /* | |
5844 * Clear anything that happens to be on the current line. | |
5845 */ | |
5846 coord.X = 0; | |
5847 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5848 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5849 cb->Info.dwSize.X, coord, &dwDummy); | |
5850 /* | |
5851 * The following is just for aesthetics. If we are exiting without | |
5852 * restoring the screen, then we want to have a prompt string | |
5853 * appear at the bottom line. However, the command interpreter | |
5854 * seems to always advance the cursor one line before displaying | |
5855 * the prompt string, which causes the screen to scroll. To | |
5856 * counter this, move the cursor up one line before exiting. | |
5857 */ | |
5858 if (exiting && !p_rs) | |
5859 coord.Y--; | |
5860 /* | |
5861 * Position the cursor at the leftmost column of the desired row. | |
5862 */ | |
5863 SetConsoleCursorPosition(g_hConOut, coord); | |
5864 } | |
5865 | |
5866 g_fTermcapMode = FALSE; | |
5867 } | |
5868 #endif /* FEAT_GUI_W32 */ | |
5869 | |
5870 | |
5871 #ifdef FEAT_GUI_W32 | |
5872 void | |
5873 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
|
5874 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
|
5875 int len UNUSED) |
7 | 5876 { |
5877 /* never used */ | |
5878 } | |
5879 | |
5880 #else | |
5881 | |
5882 /* | |
5883 * clear `n' chars, starting from `coord' | |
5884 */ | |
5885 static void | |
5886 clear_chars( | |
5887 COORD coord, | |
5888 DWORD n) | |
5889 { | |
5890 DWORD dwDummy; | |
5891 | |
5892 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy); | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5893 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5894 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
|
5895 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, &dwDummy); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5896 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
|
5897 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5898 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
|
5899 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
|
5900 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
|
5901 } |
7 | 5902 } |
5903 | |
5904 | |
5905 /* | |
5906 * Clear the screen | |
5907 */ | |
5908 static void | |
5909 clear_screen(void) | |
5910 { | |
5911 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
|
5912 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5913 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5914 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
|
5915 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5916 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5917 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
|
5918 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
|
5919 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
|
5920 } |
7 | 5921 } |
5922 | |
5923 | |
5924 /* | |
5925 * Clear to end of display | |
5926 */ | |
5927 static void | |
5928 clear_to_end_of_display(void) | |
5929 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5930 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
|
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 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
|
5933 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5934 * 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
|
5935 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5936 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5937 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
|
5938 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
|
5939 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
|
5940 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5941 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
|
5942 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
|
5943 } |
7 | 5944 } |
5945 | |
5946 | |
5947 /* | |
5948 * Clear to end of line | |
5949 */ | |
5950 static void | |
5951 clear_to_end_of_line(void) | |
5952 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5953 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
|
5954 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5955 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
|
5956 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
|
5957 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5958 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5959 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
|
5960 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
|
5961 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
|
5962 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5963 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
|
5964 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
|
5965 } |
7 | 5966 } |
5967 | |
5968 | |
5969 /* | |
5970 * Scroll the scroll region up by `cLines' lines | |
5971 */ | |
5972 static void | |
26 | 5973 scroll(unsigned cLines) |
7 | 5974 { |
5975 COORD oldcoord = g_coord; | |
5976 | |
5977 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5978 delete_lines(cLines); | |
5979 | |
5980 g_coord = oldcoord; | |
5981 } | |
5982 | |
5983 | |
5984 /* | |
5985 * Set the scroll region | |
5986 */ | |
5987 static void | |
5988 set_scroll_region( | |
5989 unsigned left, | |
5990 unsigned top, | |
5991 unsigned right, | |
5992 unsigned bottom) | |
5993 { | |
5994 if (left >= right | |
5995 || top >= bottom | |
5996 || right > (unsigned) Columns - 1 | |
5997 || bottom > (unsigned) Rows - 1) | |
5998 return; | |
5999 | |
6000 g_srScrollRegion.Left = left; | |
6001 g_srScrollRegion.Top = top; | |
6002 g_srScrollRegion.Right = right; | |
6003 g_srScrollRegion.Bottom = bottom; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6004 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6005 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
|
6006 vtp_printf("\033[%d;%dr", top + 1, bottom + 1); |
7 | 6007 } |
6008 | |
6009 | |
6010 /* | |
6011 * Insert `cLines' lines at the current cursor position | |
6012 */ | |
6013 static void | |
26 | 6014 insert_lines(unsigned cLines) |
7 | 6015 { |
6016 SMALL_RECT source; | |
6017 COORD dest; | |
6018 CHAR_INFO fill; | |
6019 | |
6020 dest.X = 0; | |
6021 dest.Y = g_coord.Y + cLines; | |
6022 | |
6023 source.Left = 0; | |
6024 source.Top = g_coord.Y; | |
6025 source.Right = g_srScrollRegion.Right; | |
6026 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
6027 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6028 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
|
6029 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6030 fill.Char.AsciiChar = ' '; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6031 fill.Attributes = 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
|
6032 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6033 ScrollConsoleScreenBuffer(g_hConOut, &source, NULL, dest, &fill); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6034 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6035 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6036 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6037 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
|
6038 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6039 gotoxy(1, source.Top + 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6040 vtp_printf("\033[%dT", cLines); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6041 } |
7 | 6042 |
6043 /* Here we have to deal with a win32 console flake: If the scroll | |
6044 * region looks like abc and we scroll c to a and fill with d we get | |
6045 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
6046 * vim expects cdd consistently... So we have to deal with that | |
6047 * here... (this also occurs scrolling the same way in the other | |
6048 * direction). */ | |
6049 | |
6050 if (source.Bottom < dest.Y) | |
6051 { | |
6052 COORD coord; | |
6053 | |
6054 coord.X = 0; | |
6055 coord.Y = source.Bottom; | |
6056 clear_chars(coord, Columns * (dest.Y - source.Bottom)); | |
6057 } | |
6058 } | |
6059 | |
6060 | |
6061 /* | |
6062 * Delete `cLines' lines at the current cursor position | |
6063 */ | |
6064 static void | |
26 | 6065 delete_lines(unsigned cLines) |
7 | 6066 { |
6067 SMALL_RECT source; | |
6068 COORD dest; | |
6069 CHAR_INFO fill; | |
6070 int nb; | |
6071 | |
6072 dest.X = 0; | |
6073 dest.Y = g_coord.Y; | |
6074 | |
6075 source.Left = 0; | |
6076 source.Top = g_coord.Y + cLines; | |
6077 source.Right = g_srScrollRegion.Right; | |
6078 source.Bottom = g_srScrollRegion.Bottom; | |
6079 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6080 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
|
6081 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6082 fill.Char.AsciiChar = ' '; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6083 fill.Attributes = 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
|
6084 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6085 ScrollConsoleScreenBuffer(g_hConOut, &source, NULL, dest, &fill); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6086 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6087 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6088 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6089 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
|
6090 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6091 gotoxy(1, source.Top + 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6092 vtp_printf("\033[%dS", cLines); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6093 } |
7 | 6094 |
6095 /* Here we have to deal with a win32 console flake: If the scroll | |
6096 * region looks like abc and we scroll c to a and fill with d we get | |
6097 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
6098 * vim expects cdd consistently... So we have to deal with that | |
6099 * here... (this also occurs scrolling the same way in the other | |
6100 * direction). */ | |
6101 | |
6102 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
6103 | |
6104 if (nb < source.Top) | |
6105 { | |
6106 COORD coord; | |
6107 | |
6108 coord.X = 0; | |
6109 coord.Y = nb; | |
6110 clear_chars(coord, Columns * (source.Top - nb)); | |
6111 } | |
6112 } | |
6113 | |
6114 | |
6115 /* | |
6116 * Set the cursor position | |
6117 */ | |
6118 static void | |
6119 gotoxy( | |
6120 unsigned x, | |
6121 unsigned y) | |
6122 { | |
6123 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
6124 return; | |
6125 | |
6126 /* external cursor coords are 1-based; internal are 0-based */ | |
6127 g_coord.X = x - 1; | |
6128 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
|
6129 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6130 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
|
6131 SetConsoleCursorPosition(g_hConOut, g_coord); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6132 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6133 vtp_printf("\033[%d;%dH", y, x); |
7 | 6134 } |
6135 | |
6136 | |
6137 /* | |
6138 * Set the current text attribute = (foreground | background) | |
6139 * See ../doc/os_win32.txt for the numbers. | |
6140 */ | |
6141 static void | |
26 | 6142 textattr(WORD wAttr) |
7 | 6143 { |
6710 | 6144 g_attrCurrent = wAttr & 0xff; |
7 | 6145 |
6146 SetConsoleTextAttribute(g_hConOut, wAttr); | |
6147 } | |
6148 | |
6149 | |
6150 static void | |
26 | 6151 textcolor(WORD wAttr) |
7 | 6152 { |
6710 | 6153 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 6154 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6155 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
|
6156 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
|
6157 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6158 vtp_sgr_bulk(wAttr); |
7 | 6159 } |
6160 | |
6161 | |
6162 static void | |
26 | 6163 textbackground(WORD wAttr) |
7 | 6164 { |
6710 | 6165 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 6166 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6167 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
|
6168 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
|
6169 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6170 vtp_sgr_bulk(wAttr); |
7 | 6171 } |
6172 | |
6173 | |
6174 /* | |
6175 * restore the default text attribute (whatever we started with) | |
6176 */ | |
6177 static void | |
26 | 6178 normvideo(void) |
7 | 6179 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6180 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
|
6181 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
|
6182 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6183 vtp_sgr_bulk(0); |
7 | 6184 } |
6185 | |
6186 | |
6187 static WORD g_attrPreStandout = 0; | |
6188 | |
6189 /* | |
6190 * Make the text standout, by brightening it | |
6191 */ | |
6192 static void | |
6193 standout(void) | |
6194 { | |
6195 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
|
6196 |
7 | 6197 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
6198 } | |
6199 | |
6200 | |
6201 /* | |
6202 * Turn off standout mode | |
6203 */ | |
6204 static void | |
26 | 6205 standend(void) |
7 | 6206 { |
6207 if (g_attrPreStandout) | |
6208 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
|
6209 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6210 g_attrPreStandout = 0; |
7 | 6211 } |
6212 | |
6213 | |
6214 /* | |
1199 | 6215 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 6216 */ |
6217 void | |
26 | 6218 mch_set_normal_colors(void) |
7 | 6219 { |
6220 char_u *p; | |
6221 int n; | |
6222 | |
6223 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
6224 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
|
6225 if ( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6226 #ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6227 !p_tgc && |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6228 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6229 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 6230 { |
6231 p = T_ME + 2; | |
6232 n = getdigits(&p); | |
6233 if (*p == 'm' && n > 0) | |
6234 { | |
6235 cterm_normal_fg_color = (n & 0xf) + 1; | |
6236 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
6237 } | |
6238 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6239 #ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6240 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
|
6241 cterm_normal_bg_gui_color = INVALCOLOR; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6242 #endif |
7 | 6243 } |
6244 | |
6245 | |
6246 /* | |
6247 * visual bell: flash the screen | |
6248 */ | |
6249 static void | |
26 | 6250 visual_bell(void) |
7 | 6251 { |
6252 COORD coordOrigin = {0, 0}; | |
6253 WORD attrFlash = ~g_attrCurrent & 0xff; | |
6254 | |
6255 DWORD dwDummy; | |
6256 LPWORD oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD)); | |
6257 | |
6258 if (oldattrs == NULL) | |
6259 return; | |
6260 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
6261 coordOrigin, &dwDummy); | |
6262 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
6263 coordOrigin, &dwDummy); | |
6264 | |
6265 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
|
6266 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
|
6267 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 6268 coordOrigin, &dwDummy); |
6269 vim_free(oldattrs); | |
6270 } | |
6271 | |
6272 | |
6273 /* | |
6274 * Make the cursor visible or invisible | |
6275 */ | |
6276 static void | |
26 | 6277 cursor_visible(BOOL fVisible) |
7 | 6278 { |
6279 s_cursor_visible = fVisible; | |
6280 #ifdef MCH_CURSOR_SHAPE | |
6281 mch_update_cursor(); | |
6282 #endif | |
6283 } | |
6284 | |
6285 | |
6286 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6287 * 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
|
6288 * Returns the number of bytes actually written (at least one). |
7 | 6289 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6290 static DWORD |
7 | 6291 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6292 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6293 DWORD cbToWrite) |
7 | 6294 { |
6295 COORD coord = g_coord; | |
6296 DWORD written; | |
6297 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6298 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6299 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6300 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6301 static WCHAR *unicodebuf = NULL; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6302 static int unibuflen = 0; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6303 int length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6304 DWORD n, cchwritten, cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6305 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6306 length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pchBuf, cbToWrite, 0, 0); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6307 if (unicodebuf == NULL || length > unibuflen) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6308 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6309 vim_free(unicodebuf); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6310 unicodebuf = (WCHAR *)lalloc(length * sizeof(WCHAR), FALSE); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6311 unibuflen = length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6312 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6313 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pchBuf, cbToWrite, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6314 unicodebuf, unibuflen); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6315 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6316 cells = mb_string2cells(pchBuf, cbToWrite); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6317 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6318 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
|
6319 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6320 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6321 coord, &written); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6322 /* When writing fails or didn't write a single character, pretend one |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6323 * character was written, otherwise we get stuck. */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6324 if (WriteConsoleOutputCharacterW(g_hConOut, unicodebuf, length, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6325 coord, &cchwritten) == 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6326 || cchwritten == 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6327 cchwritten = 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6328 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6329 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6330 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6331 if (WriteConsoleW(g_hConOut, unicodebuf, length, &cchwritten, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6332 NULL) == 0 || cchwritten == 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6333 cchwritten = 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6334 } |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6335 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6336 if (cchwritten == length) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6337 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6338 written = cbToWrite; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6339 g_coord.X += (SHORT)cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6340 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6341 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6342 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6343 char_u *p = pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6344 for (n = 0; n < cchwritten; n++) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11071
diff
changeset
|
6345 MB_CPTR_ADV(p); |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6346 written = p - pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6347 g_coord.X += (SHORT)mb_string2cells(pchBuf, written); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6348 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6349 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6350 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6351 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6352 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6353 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
|
6354 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6355 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cbToWrite, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6356 coord, &written); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6357 /* When writing fails or didn't write a single character, pretend one |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6358 * character was written, otherwise we get stuck. */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6359 if (WriteConsoleOutputCharacter(g_hConOut, (LPCSTR)pchBuf, cbToWrite, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6360 coord, &written) == 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6361 || written == 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6362 written = 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6363 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6364 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6365 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6366 if (WriteConsole(g_hConOut, (LPCSTR)pchBuf, cbToWrite, &written, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6367 NULL) == 0 || written == 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6368 written = 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6369 } |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6370 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6371 g_coord.X += (SHORT) written; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6372 } |
7 | 6373 |
6374 while (g_coord.X > g_srScrollRegion.Right) | |
6375 { | |
6376 g_coord.X -= (SHORT) Columns; | |
6377 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6378 g_coord.Y++; | |
6379 } | |
6380 | |
6381 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6382 | |
6383 return written; | |
6384 } | |
6385 | |
6386 | |
6387 /* | |
6388 * mch_write(): write the output buffer to the screen, translating ESC | |
6389 * sequences into calls to console output routines. | |
6390 */ | |
6391 void | |
6392 mch_write( | |
6393 char_u *s, | |
6394 int len) | |
6395 { | |
6396 s[len] = NUL; | |
6397 | |
6398 if (!term_console) | |
6399 { | |
6400 write(1, s, (unsigned)len); | |
6401 return; | |
6402 } | |
6403 | |
6404 /* translate ESC | sequences into faked bios calls */ | |
6405 while (len--) | |
6406 { | |
6407 /* optimization: use one single write_chars for runs of text, | |
6408 * rather than once per character It ain't curses, but it helps. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6409 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 6410 |
6411 if (p_wd) | |
6412 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6413 WaitForChar(p_wd, FALSE); |
7 | 6414 if (prefix != 0) |
6415 prefix = 1; | |
6416 } | |
6417 | |
6418 if (prefix != 0) | |
6419 { | |
6420 DWORD nWritten; | |
6421 | |
6422 nWritten = write_chars(s, prefix); | |
6423 #ifdef MCH_WRITE_DUMP | |
6424 if (fdDump) | |
6425 { | |
6426 fputc('>', fdDump); | |
6427 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6428 fputs("<\n", fdDump); | |
6429 } | |
6430 #endif | |
6431 len -= (nWritten - 1); | |
6432 s += nWritten; | |
6433 } | |
6434 else if (s[0] == '\n') | |
6435 { | |
6436 /* \n, newline: go to the beginning of the next line or scroll */ | |
6437 if (g_coord.Y == g_srScrollRegion.Bottom) | |
6438 { | |
6439 scroll(1); | |
6440 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6441 } | |
6442 else | |
6443 { | |
6444 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6445 } | |
6446 #ifdef MCH_WRITE_DUMP | |
6447 if (fdDump) | |
6448 fputs("\\n\n", fdDump); | |
6449 #endif | |
6450 s++; | |
6451 } | |
6452 else if (s[0] == '\r') | |
6453 { | |
6454 /* \r, carriage return: go to beginning of line */ | |
6455 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
6456 #ifdef MCH_WRITE_DUMP | |
6457 if (fdDump) | |
6458 fputs("\\r\n", fdDump); | |
6459 #endif | |
6460 s++; | |
6461 } | |
6462 else if (s[0] == '\b') | |
6463 { | |
6464 /* \b, backspace: move cursor one position left */ | |
6465 if (g_coord.X > g_srScrollRegion.Left) | |
6466 g_coord.X--; | |
6467 else if (g_coord.Y > g_srScrollRegion.Top) | |
6468 { | |
6469 g_coord.X = g_srScrollRegion.Right; | |
6470 g_coord.Y--; | |
6471 } | |
6472 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6473 #ifdef MCH_WRITE_DUMP | |
6474 if (fdDump) | |
6475 fputs("\\b\n", fdDump); | |
6476 #endif | |
6477 s++; | |
6478 } | |
6479 else if (s[0] == '\a') | |
6480 { | |
6481 /* \a, bell */ | |
6482 MessageBeep(0xFFFFFFFF); | |
6483 #ifdef MCH_WRITE_DUMP | |
6484 if (fdDump) | |
6485 fputs("\\a\n", fdDump); | |
6486 #endif | |
6487 s++; | |
6488 } | |
6489 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6490 { | |
6491 #ifdef MCH_WRITE_DUMP | |
24 | 6492 char_u *old_s = s; |
7 | 6493 #endif |
24 | 6494 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
|
6495 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
7 | 6496 |
6497 switch (s[2]) | |
6498 { | |
6499 case '0': case '1': case '2': case '3': case '4': | |
6500 case '5': case '6': case '7': case '8': case '9': | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6501 p = s + 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6502 do |
7 | 6503 { |
6504 ++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
|
6505 args[argc] = getdigits(&p); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6506 argc += (argc < 15) ? 1 : 0; |
7 | 6507 if (p > s + len) |
6508 break; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6509 } while (*p == ';'); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6510 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6511 if (p > s + len) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6512 break; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6513 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6514 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
|
6515 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
|
6516 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
|
6517 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6518 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
|
6519 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6520 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
|
6521 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6522 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
|
6523 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
|
6524 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6525 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
|
6526 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6527 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
|
6528 vtp_sgr_bulks(argc, args); |
7 | 6529 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6530 else if (argc == 2 && *p == 'H') |
7 | 6531 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6532 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
|
6533 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6534 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
|
6535 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6536 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
|
6537 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6538 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
|
6539 { |
7 | 6540 gotoxy(g_coord.X + 1, |
6541 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6542 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6543 else if (argc == 1 && *p == 'b') |
7 | 6544 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6545 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
|
6546 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6547 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
|
6548 { |
7 | 6549 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6550 g_coord.Y + 1); | |
6551 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6552 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
|
6553 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6554 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
|
6555 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6556 else if (argc == 1 && *p == 'H') |
7 | 6557 { |
6558 gotoxy(1, arg1); | |
6559 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6560 else if (argc == 1 && *p == 'L') |
7 | 6561 { |
6562 insert_lines(arg1); | |
6563 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6564 else if (argc == 1 && *p == 'M') |
7 | 6565 { |
6566 delete_lines(arg1); | |
6567 } | |
6568 | |
835 | 6569 len -= (int)(p - s); |
7 | 6570 s = p + 1; |
6571 break; | |
6572 | |
6573 case 'A': | |
6574 gotoxy(g_coord.X + 1, | |
6575 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6576 goto got3; | |
6577 | |
6578 case 'B': | |
6579 visual_bell(); | |
6580 goto got3; | |
6581 | |
6582 case 'C': | |
6583 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6584 g_coord.Y + 1); | |
6585 goto got3; | |
6586 | |
6587 case 'E': | |
6588 termcap_mode_end(); | |
6589 goto got3; | |
6590 | |
6591 case 'F': | |
6592 standout(); | |
6593 goto got3; | |
6594 | |
6595 case 'f': | |
6596 standend(); | |
6597 goto got3; | |
6598 | |
6599 case 'H': | |
6600 gotoxy(1, 1); | |
6601 goto got3; | |
6602 | |
6603 case 'j': | |
6604 clear_to_end_of_display(); | |
6605 goto got3; | |
6606 | |
6607 case 'J': | |
6608 clear_screen(); | |
6609 goto got3; | |
6610 | |
6611 case 'K': | |
6612 clear_to_end_of_line(); | |
6613 goto got3; | |
6614 | |
6615 case 'L': | |
6616 insert_lines(1); | |
6617 goto got3; | |
6618 | |
6619 case 'M': | |
6620 delete_lines(1); | |
6621 goto got3; | |
6622 | |
6623 case 'S': | |
6624 termcap_mode_start(); | |
6625 goto got3; | |
6626 | |
6627 case 'V': | |
6628 cursor_visible(TRUE); | |
6629 goto got3; | |
6630 | |
6631 case 'v': | |
6632 cursor_visible(FALSE); | |
6633 goto got3; | |
6634 | |
6635 got3: | |
6636 s += 3; | |
6637 len -= 2; | |
6638 } | |
6639 | |
6640 #ifdef MCH_WRITE_DUMP | |
6641 if (fdDump) | |
6642 { | |
6643 fputs("ESC | ", fdDump); | |
6644 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6645 fputc('\n', fdDump); | |
6646 } | |
6647 #endif | |
6648 } | |
6649 else | |
6650 { | |
6651 /* Write a single character */ | |
6652 DWORD nWritten; | |
6653 | |
6654 nWritten = write_chars(s, 1); | |
6655 #ifdef MCH_WRITE_DUMP | |
6656 if (fdDump) | |
6657 { | |
6658 fputc('>', fdDump); | |
6659 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6660 fputs("<\n", fdDump); | |
6661 } | |
6662 #endif | |
6663 | |
6664 len -= (nWritten - 1); | |
6665 s += nWritten; | |
6666 } | |
6667 } | |
6668 | |
6669 #ifdef MCH_WRITE_DUMP | |
6670 if (fdDump) | |
6671 fflush(fdDump); | |
6672 #endif | |
6673 } | |
6674 | |
6675 #endif /* FEAT_GUI_W32 */ | |
6676 | |
6677 | |
6678 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6679 * Delay for "msec" milliseconds. |
7 | 6680 */ |
6681 void | |
6682 mch_delay( | |
6683 long msec, | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
6684 int ignoreinput UNUSED) |
7 | 6685 { |
6686 #ifdef FEAT_GUI_W32 | |
6687 Sleep((int)msec); /* never wait for input */ | |
14 | 6688 #else /* Console */ |
7 | 6689 if (ignoreinput) |
14 | 6690 # ifdef FEAT_MZSCHEME |
6691 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6692 { | |
6693 int towait = p_mzq; | |
6694 | |
6695 /* if msec is large enough, wait by portions in p_mzq */ | |
6696 while (msec > 0) | |
6697 { | |
6698 mzvim_check_threads(); | |
6699 if (msec < towait) | |
6700 towait = msec; | |
6701 Sleep(towait); | |
6702 msec -= towait; | |
6703 } | |
6704 } | |
6705 else | |
6706 # endif | |
6707 Sleep((int)msec); | |
7 | 6708 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6709 WaitForChar(msec, FALSE); |
7 | 6710 #endif |
6711 } | |
6712 | |
6713 | |
6714 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6715 * 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
|
6716 * This can also remove a symbolic link like Unix. |
7 | 6717 * Return 0 for success, -1 for failure. |
6718 */ | |
6719 int | |
6720 mch_remove(char_u *name) | |
6721 { | |
6722 #ifdef FEAT_MBYTE | |
6723 WCHAR *wn = NULL; | |
6724 int n; | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6725 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6726 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6727 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6728 * 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
|
6729 * 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
|
6730 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6731 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
|
6732 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6733 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6734 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6735 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6736 #ifdef FEAT_MBYTE |
7 | 6737 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6738 { | |
1752 | 6739 wn = enc_to_utf16(name, NULL); |
7 | 6740 if (wn != NULL) |
6741 { | |
6742 n = DeleteFileW(wn) ? 0 : -1; | |
6743 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6744 return n; |
7 | 6745 } |
6746 } | |
6747 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6748 return DeleteFile((LPCSTR)name) ? 0 : -1; |
7 | 6749 } |
6750 | |
6751 | |
6752 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6753 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6754 */ |
6755 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6756 mch_breakcheck(int force) |
7 | 6757 { |
6758 #ifndef FEAT_GUI_W32 /* never used */ | |
6759 if (g_fCtrlCPressed || g_fCBrkPressed) | |
6760 { | |
12066
8ad282dee649
patch 8.0.0913: MS-Windows: CTRL-C kills shell in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12050
diff
changeset
|
6761 ctrl_break_was_pressed = g_fCBrkPressed; |
7 | 6762 g_fCtrlCPressed = g_fCBrkPressed = FALSE; |
6763 got_int = TRUE; | |
6764 } | |
6765 #endif | |
6766 } | |
6767 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6768 /* physical RAM to leave for the OS */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6769 #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
|
6770 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6771 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6772 * 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
|
6773 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6774 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
|
6775 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
|
6776 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6777 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6778 |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6779 PlatformId(); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6780 /* Need to use GlobalMemoryStatusEx() when there is more memory than |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6781 * what fits in 32 bits. But it's not always available. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6782 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6783 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6784 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6785 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6786 /* Process address space fits in physical RAM, use all of it. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6787 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
|
6788 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6789 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
|
6790 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6791 /* Catch old NT box or perverse hardware setup. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6792 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
|
6793 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6794 /* Use physical RAM less reserve for OS + data. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6795 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
|
6796 } |
7 | 6797 |
6798 #ifdef FEAT_MBYTE | |
6799 /* | |
6800 * Same code as below, but with wide functions and no comments. | |
6801 * Return 0 for success, non-zero for failure. | |
6802 */ | |
6803 int | |
6804 mch_wrename(WCHAR *wold, WCHAR *wnew) | |
6805 { | |
6806 WCHAR *p; | |
6807 int i; | |
6808 WCHAR szTempFile[_MAX_PATH + 1]; | |
6809 WCHAR szNewPath[_MAX_PATH + 1]; | |
6810 HANDLE hf; | |
6811 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6812 p = wold; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6813 for (i = 0; wold[i] != NUL; ++i) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6814 if ((wold[i] == '/' || wold[i] == '\\' || wold[i] == ':') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6815 && wold[i + 1] != 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6816 p = wold + i + 1; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6817 if ((int)(wold + i - p) < 8 || p[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6818 return (MoveFileW(wold, wnew) == 0); |
7 | 6819 |
6820 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) | |
6821 return -1; | |
6822 *p = NUL; | |
6823 | |
6824 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) | |
6825 return -2; | |
6826 | |
6827 if (!DeleteFileW(szTempFile)) | |
6828 return -3; | |
6829 | |
6830 if (!MoveFileW(wold, szTempFile)) | |
6831 return -4; | |
6832 | |
6833 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6834 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6835 return -5; | |
6836 if (!CloseHandle(hf)) | |
6837 return -6; | |
6838 | |
6839 if (!MoveFileW(szTempFile, wnew)) | |
6840 { | |
6841 (void)MoveFileW(szTempFile, wold); | |
6842 return -7; | |
6843 } | |
6844 | |
6845 DeleteFileW(szTempFile); | |
6846 | |
6847 if (!DeleteFileW(wold)) | |
6848 return -8; | |
6849 | |
6850 return 0; | |
6851 } | |
6852 #endif | |
6853 | |
6854 | |
6855 /* | |
6856 * mch_rename() works around a bug in rename (aka MoveFile) in | |
6857 * Windows 95: rename("foo.bar", "foo.bar~") will generate a | |
6858 * file whose short file name is "FOO.BAR" (its long file name will | |
6859 * be correct: "foo.bar~"). Because a file can be accessed by | |
6860 * either its SFN or its LFN, "foo.bar" has effectively been | |
6861 * renamed to "foo.bar", which is not at all what was wanted. This | |
6862 * seems to happen only when renaming files with three-character | |
6863 * extensions by appending a suffix that does not include ".". | |
6864 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6865 * | |
6866 * There is another problem, which isn't really a bug but isn't right either: | |
6867 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6868 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6869 * service pack 6. Doesn't seem to happen on Windows 98. | |
6870 * | |
6871 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6872 * Should probably set errno appropriately when errors occur. | |
6873 */ | |
6874 int | |
6875 mch_rename( | |
6876 const char *pszOldFile, | |
6877 const char *pszNewFile) | |
6878 { | |
6879 char szTempFile[_MAX_PATH+1]; | |
6880 char szNewPath[_MAX_PATH+1]; | |
6881 char *pszFilePart; | |
6882 HANDLE hf; | |
6883 #ifdef FEAT_MBYTE | |
6884 WCHAR *wold = NULL; | |
6885 WCHAR *wnew = NULL; | |
6886 int retval = -1; | |
6887 | |
6888 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
6889 { | |
1752 | 6890 wold = enc_to_utf16((char_u *)pszOldFile, NULL); |
6891 wnew = enc_to_utf16((char_u *)pszNewFile, NULL); | |
7 | 6892 if (wold != NULL && wnew != NULL) |
6893 retval = mch_wrename(wold, wnew); | |
6894 vim_free(wold); | |
6895 vim_free(wnew); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6896 return retval; |
7 | 6897 } |
6898 #endif | |
6899 | |
6900 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6901 * No need to play tricks unless the file name contains a "~" as the |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6902 * seventh character. |
7 | 6903 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6904 pszFilePart = (char *)gettail((char_u *)pszOldFile); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6905 if (STRLEN(pszFilePart) < 8 || pszFilePart[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6906 return rename(pszOldFile, pszNewFile); |
7 | 6907 |
6908 /* Get base path of new file name. Undocumented feature: If pszNewFile is | |
6909 * a directory, no error is returned and pszFilePart will be NULL. */ | |
6910 if (GetFullPathName(pszNewFile, _MAX_PATH, szNewPath, &pszFilePart) == 0 | |
6911 || pszFilePart == NULL) | |
6912 return -1; | |
6913 *pszFilePart = NUL; | |
6914 | |
6915 /* Get (and create) a unique temporary file name in directory of new file */ | |
6916 if (GetTempFileName(szNewPath, "VIM", 0, szTempFile) == 0) | |
6917 return -2; | |
6918 | |
6919 /* blow the temp file away */ | |
6920 if (!DeleteFile(szTempFile)) | |
6921 return -3; | |
6922 | |
6923 /* rename old file to the temp file */ | |
6924 if (!MoveFile(pszOldFile, szTempFile)) | |
6925 return -4; | |
6926 | |
6927 /* now create an empty file called pszOldFile; this prevents the operating | |
6928 * system using pszOldFile as an alias (SFN) if we're renaming within the | |
6929 * same directory. For example, we're editing a file called | |
6930 * filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt | |
6931 * to filena~1.txt~ (i.e., we're making a backup while writing it), the | |
6932 * SFN for filena~1.txt~ will be filena~1.txt, by default, which will | |
39 | 6933 * cause all sorts of problems later in buf_write(). So, we create an |
6934 * empty file called filena~1.txt and the system will have to find some | |
6935 * other SFN for filena~1.txt~, such as filena~2.txt | |
7 | 6936 */ |
6937 if ((hf = CreateFile(pszOldFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6938 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6939 return -5; | |
6940 if (!CloseHandle(hf)) | |
6941 return -6; | |
6942 | |
6943 /* rename the temp file to the new file */ | |
6944 if (!MoveFile(szTempFile, pszNewFile)) | |
6945 { | |
6946 /* Renaming failed. Rename the file back to its old name, so that it | |
6947 * looks like nothing happened. */ | |
6948 (void)MoveFile(szTempFile, pszOldFile); | |
6949 | |
6950 return -7; | |
6951 } | |
6952 | |
6953 /* Seems to be left around on Novell filesystems */ | |
6954 DeleteFile(szTempFile); | |
6955 | |
6956 /* finally, remove the empty old file */ | |
6957 if (!DeleteFile(pszOldFile)) | |
6958 return -8; | |
6959 | |
6960 return 0; /* success */ | |
6961 } | |
6962 | |
6963 /* | |
6964 * Get the default shell for the current hardware platform | |
6965 */ | |
6966 char * | |
26 | 6967 default_shell(void) |
7 | 6968 { |
6969 PlatformId(); | |
6970 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6971 return "cmd.exe"; |
7 | 6972 } |
6973 | |
6974 /* | |
6975 * mch_access() extends access() to do more detailed check on network drives. | |
6976 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6977 */ | |
6978 int | |
6979 mch_access(char *n, int p) | |
6980 { | |
6981 HANDLE hFile; | |
6982 int retval = -1; /* default: fail */ | |
6983 #ifdef FEAT_MBYTE | |
6984 WCHAR *wn = NULL; | |
6985 | |
6986 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6987 wn = enc_to_utf16((char_u *)n, NULL); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6988 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6989 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6990 if (mch_isdir((char_u *)n)) |
7 | 6991 { |
6992 char TempName[_MAX_PATH + 16] = ""; | |
6993 #ifdef FEAT_MBYTE | |
6994 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6995 #endif | |
6996 | |
6997 if (p & R_OK) | |
6998 { | |
6999 /* Read check is performed by seeing if we can do a find file on | |
7000 * the directory for any file. */ | |
7001 #ifdef FEAT_MBYTE | |
7002 if (wn != NULL) | |
7003 { | |
7004 int i; | |
7005 WIN32_FIND_DATAW d; | |
7006 | |
7007 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) | |
7008 TempNameW[i] = wn[i]; | |
7009 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/') | |
7010 TempNameW[i++] = '\\'; | |
7011 TempNameW[i++] = '*'; | |
7012 TempNameW[i++] = 0; | |
7013 | |
7014 hFile = FindFirstFileW(TempNameW, &d); | |
7015 if (hFile == INVALID_HANDLE_VALUE) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7016 goto getout; |
7 | 7017 else |
7018 (void)FindClose(hFile); | |
7019 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7020 else |
7 | 7021 #endif |
7022 { | |
7023 char *pch; | |
7024 WIN32_FIND_DATA d; | |
7025 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7026 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH); |
7 | 7027 pch = TempName + STRLEN(TempName) - 1; |
7028 if (*pch != '\\' && *pch != '/') | |
7029 *++pch = '\\'; | |
7030 *++pch = '*'; | |
7031 *++pch = NUL; | |
7032 | |
7033 hFile = FindFirstFile(TempName, &d); | |
7034 if (hFile == INVALID_HANDLE_VALUE) | |
7035 goto getout; | |
7036 (void)FindClose(hFile); | |
7037 } | |
7038 } | |
7039 | |
7040 if (p & W_OK) | |
7041 { | |
7042 /* Trying to create a temporary file in the directory should catch | |
7043 * directories on read-only network shares. However, in | |
7044 * directories whose ACL allows writes but denies deletes will end | |
7045 * up keeping the temporary file :-(. */ | |
7046 #ifdef FEAT_MBYTE | |
7047 if (wn != NULL) | |
7048 { | |
7049 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7050 goto getout; |
7 | 7051 else |
7052 DeleteFileW(TempNameW); | |
7053 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7054 else |
7 | 7055 #endif |
7056 { | |
7057 if (!GetTempFileName(n, "VIM", 0, TempName)) | |
7058 goto getout; | |
7059 mch_remove((char_u *)TempName); | |
7060 } | |
7061 } | |
7062 } | |
7063 else | |
7064 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7065 // 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
|
7066 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
|
7067 |
7 | 7068 /* Trying to open the file for the required access does ACL, read-only |
7069 * 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
|
7070 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
|
7071 | ((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
|
7072 |
7 | 7073 #ifdef FEAT_MBYTE |
7074 if (wn != NULL) | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7075 hFile = CreateFileW(wn, access_mode, share_mode, |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7076 NULL, OPEN_EXISTING, 0, NULL); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7077 else |
7 | 7078 #endif |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7079 hFile = CreateFile(n, access_mode, share_mode, |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7080 NULL, OPEN_EXISTING, 0, NULL); |
7 | 7081 if (hFile == INVALID_HANDLE_VALUE) |
7082 goto getout; | |
7083 CloseHandle(hFile); | |
7084 } | |
7085 | |
7086 retval = 0; /* success */ | |
7087 getout: | |
7088 #ifdef FEAT_MBYTE | |
7089 vim_free(wn); | |
7090 #endif | |
7091 return retval; | |
7092 } | |
7093 | |
7094 #if defined(FEAT_MBYTE) || defined(PROTO) | |
7095 /* | |
1752 | 7096 * Version of open() that may use UTF-16 file name. |
7 | 7097 */ |
7098 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7099 mch_open(const char *name, int flags, int mode) |
7 | 7100 { |
39 | 7101 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */ |
7102 # ifndef __BORLANDC__ | |
7 | 7103 WCHAR *wn; |
7104 int f; | |
7105 | |
39 | 7106 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 7107 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7108 wn = enc_to_utf16((char_u *)name, NULL); |
7 | 7109 if (wn != NULL) |
7110 { | |
7111 f = _wopen(wn, flags, mode); | |
7112 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7113 return f; |
7 | 7114 } |
7115 } | |
39 | 7116 # endif |
7 | 7117 |
6345 | 7118 /* open() can open a file which name is longer than _MAX_PATH bytes |
7119 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
7120 * causes unexpected error in another part. We make it an error explicitly | |
7121 * here. */ | |
7122 if (strlen(name) >= _MAX_PATH) | |
7123 return -1; | |
7124 | |
7 | 7125 return open(name, flags, mode); |
7126 } | |
7127 | |
7128 /* | |
1752 | 7129 * Version of fopen() that may use UTF-16 file name. |
7 | 7130 */ |
7131 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7132 mch_fopen(const char *name, const char *mode) |
7 | 7133 { |
7134 WCHAR *wn, *wm; | |
7135 FILE *f = NULL; | |
7136 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7137 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 7138 { |
1686 | 7139 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 7140 /* Work around an annoying assertion in the Microsoft debug CRT |
7141 * when mode's text/binary setting doesn't match _get_fmode(). */ | |
7142 char newMode = mode[strlen(mode) - 1]; | |
7143 int oldMode = 0; | |
7144 | |
7145 _get_fmode(&oldMode); | |
7146 if (newMode == 't') | |
7147 _set_fmode(_O_TEXT); | |
7148 else if (newMode == 'b') | |
7149 _set_fmode(_O_BINARY); | |
7150 # endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7151 wn = enc_to_utf16((char_u *)name, NULL); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7152 wm = enc_to_utf16((char_u *)mode, NULL); |
7 | 7153 if (wn != NULL && wm != NULL) |
7154 f = _wfopen(wn, wm); | |
7155 vim_free(wn); | |
7156 vim_free(wm); | |
1569 | 7157 |
1686 | 7158 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 7159 _set_fmode(oldMode); |
7160 # endif | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7161 return f; |
7 | 7162 } |
7163 | |
6345 | 7164 /* fopen() can open a file which name is longer than _MAX_PATH bytes |
7165 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
7166 * causes unexpected error in another part. We make it an error explicitly | |
7167 * here. */ | |
7168 if (strlen(name) >= _MAX_PATH) | |
7169 return NULL; | |
7170 | |
7 | 7171 return fopen(name, mode); |
7172 } | |
7173 #endif | |
7174 | |
7175 #ifdef FEAT_MBYTE | |
7176 /* | |
7177 * SUB STREAM (aka info stream) handling: | |
7178 * | |
7179 * NTFS can have sub streams for each file. Normal contents of file is | |
7180 * stored in the main stream, and extra contents (author information and | |
7181 * title and so on) can be stored in sub stream. After Windows 2000, user | |
7182 * can access and store those informations in sub streams via explorer's | |
7183 * property menuitem in right click menu. Those informations in sub streams | |
7184 * were lost when copying only the main stream. So we have to copy sub | |
7185 * streams. | |
7186 * | |
7187 * Incomplete explanation: | |
7188 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
7189 * More useful info and an example: | |
7190 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
7191 */ | |
7192 | |
7193 /* | |
7194 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
7195 * and write to stream "substream" of file "to". | |
7196 * Errors are ignored. | |
7197 */ | |
7198 static void | |
7199 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
7200 { | |
7201 HANDLE hTo; | |
7202 WCHAR *to_name; | |
7203 | |
7204 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
7205 wcscpy(to_name, to); | |
7206 wcscat(to_name, substream); | |
7207 | |
7208 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
7209 FILE_ATTRIBUTE_NORMAL, NULL); | |
7210 if (hTo != INVALID_HANDLE_VALUE) | |
7211 { | |
7212 long done; | |
7213 DWORD todo; | |
7214 DWORD readcnt, written; | |
7215 char buf[4096]; | |
7216 | |
7217 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
7218 for (done = 0; done < len; done += written) | |
7219 { | |
7220 /* (size_t) cast for Borland C 5.5 */ | |
835 | 7221 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
7222 : (size_t)(len - done)); | |
7 | 7223 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
7224 FALSE, FALSE, context) | |
7225 || readcnt != todo | |
7226 || !WriteFile(hTo, buf, todo, &written, NULL) | |
7227 || written != todo) | |
7228 break; | |
7229 } | |
7230 CloseHandle(hTo); | |
7231 } | |
7232 | |
7233 free(to_name); | |
7234 } | |
7235 | |
7236 /* | |
7237 * Copy info streams from file "from" to file "to". | |
7238 */ | |
7239 static void | |
7240 copy_infostreams(char_u *from, char_u *to) | |
7241 { | |
7242 WCHAR *fromw; | |
7243 WCHAR *tow; | |
7244 HANDLE sh; | |
7245 WIN32_STREAM_ID sid; | |
7246 int headersize; | |
7247 WCHAR streamname[_MAX_PATH]; | |
7248 DWORD readcount; | |
7249 void *context = NULL; | |
7250 DWORD lo, hi; | |
7251 int len; | |
7252 | |
7253 /* Convert the file names to wide characters. */ | |
1752 | 7254 fromw = enc_to_utf16(from, NULL); |
7255 tow = enc_to_utf16(to, NULL); | |
7 | 7256 if (fromw != NULL && tow != NULL) |
7257 { | |
7258 /* Open the file for reading. */ | |
7259 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
7260 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
7261 if (sh != INVALID_HANDLE_VALUE) | |
7262 { | |
7263 /* Use BackupRead() to find the info streams. Repeat until we | |
7264 * have done them all.*/ | |
7265 for (;;) | |
7266 { | |
7267 /* Get the header to find the length of the stream name. If | |
7268 * the "readcount" is zero we have done all info streams. */ | |
7269 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 7270 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 7271 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
7272 &readcount, FALSE, FALSE, &context) | |
7273 || readcount == 0) | |
7274 break; | |
7275 | |
7276 /* We only deal with streams that have a name. The normal | |
7277 * file data appears to be without a name, even though docs | |
7278 * suggest it is called "::$DATA". */ | |
7279 if (sid.dwStreamNameSize > 0) | |
7280 { | |
7281 /* Read the stream name. */ | |
7282 if (!BackupRead(sh, (LPBYTE)streamname, | |
7283 sid.dwStreamNameSize, | |
7284 &readcount, FALSE, FALSE, &context)) | |
7285 break; | |
7286 | |
7287 /* Copy an info stream with a name ":anything:$DATA". | |
7288 * Skip "::$DATA", it has no stream name (examples suggest | |
7289 * it might be used for the normal file contents). | |
7290 * Note that BackupRead() counts bytes, but the name is in | |
7291 * wide characters. */ | |
7292 len = readcount / sizeof(WCHAR); | |
7293 streamname[len] = 0; | |
7294 if (len > 7 && wcsicmp(streamname + len - 6, | |
7295 L":$DATA") == 0) | |
7296 { | |
7297 streamname[len - 6] = 0; | |
7298 copy_substream(sh, &context, tow, streamname, | |
10 | 7299 (long)sid.Size.u.LowPart); |
7 | 7300 } |
7301 } | |
7302 | |
7303 /* Advance to the next stream. We might try seeking too far, | |
7304 * but BackupSeek() doesn't skip over stream borders, thus | |
7305 * that's OK. */ | |
323 | 7306 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 7307 &lo, &hi, &context); |
7308 } | |
7309 | |
7310 /* Clear the context. */ | |
7311 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
7312 | |
7313 CloseHandle(sh); | |
7314 } | |
7315 } | |
7316 vim_free(fromw); | |
7317 vim_free(tow); | |
7318 } | |
7319 #endif | |
7320 | |
7321 /* | |
7322 * Copy file attributes from file "from" to file "to". | |
7323 * For Windows NT and later we copy info streams. | |
7324 * Always returns zero, errors are ignored. | |
7325 */ | |
7326 int | |
7327 mch_copy_file_attribute(char_u *from, char_u *to) | |
7328 { | |
7329 #ifdef FEAT_MBYTE | |
7330 /* File streams only work on Windows NT and later. */ | |
7331 PlatformId(); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7332 copy_infostreams(from, to); |
7 | 7333 #endif |
7334 return 0; | |
7335 } | |
7336 | |
7337 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
7338 /* | |
7339 * Recreate a destroyed stack guard page in win32. | |
7340 * Written by Benjamin Peterson. | |
7341 */ | |
7342 | |
7343 /* These magic numbers are from the MS header files */ | |
7344 #define MIN_STACK_WINNT 2 | |
7345 | |
7346 /* | |
7347 * This function does the same thing as _resetstkoflw(), which is only | |
7348 * available in DevStudio .net and later. | |
7349 * Returns 0 for failure, 1 for success. | |
7350 */ | |
7351 int | |
7352 myresetstkoflw(void) | |
7353 { | |
7354 BYTE *pStackPtr; | |
7355 BYTE *pGuardPage; | |
7356 BYTE *pStackBase; | |
7357 BYTE *pLowestPossiblePage; | |
7358 MEMORY_BASIC_INFORMATION mbi; | |
7359 SYSTEM_INFO si; | |
7360 DWORD nPageSize; | |
7361 DWORD dummy; | |
7362 | |
7363 PlatformId(); | |
7364 | |
7365 /* We need to know the system page size. */ | |
7366 GetSystemInfo(&si); | |
7367 nPageSize = si.dwPageSize; | |
7368 | |
7369 /* ...and the current stack pointer */ | |
7370 pStackPtr = (BYTE*)_alloca(1); | |
7371 | |
7372 /* ...and the base of the stack. */ | |
7373 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
7374 return 0; | |
7375 pStackBase = (BYTE*)mbi.AllocationBase; | |
7376 | |
7377 /* ...and the page thats min_stack_req pages away from stack base; this is | |
7378 * the lowest page we could use. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7379 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7380 |
7 | 7381 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7382 /* We want the first committed page in the stack Start at the stack |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7383 * base and move forward through memory until we find a committed block. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7384 */ |
7 | 7385 BYTE *pBlock = pStackBase; |
7386 | |
406 | 7387 for (;;) |
7 | 7388 { |
7389 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
7390 return 0; | |
7391 | |
7392 pBlock += mbi.RegionSize; | |
7393 | |
7394 if (mbi.State & MEM_COMMIT) | |
7395 break; | |
7396 } | |
7397 | |
7398 /* mbi now describes the first committed block in the stack. */ | |
7399 if (mbi.Protect & PAGE_GUARD) | |
7400 return 1; | |
7401 | |
7402 /* decide where the guard page should start */ | |
7403 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
7404 pGuardPage = pLowestPossiblePage; | |
7405 else | |
7406 pGuardPage = (BYTE*)mbi.BaseAddress; | |
7407 | |
7408 /* allocate the guard page */ | |
7409 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
7410 return 0; | |
7411 | |
7412 /* apply the guard attribute to the page */ | |
7413 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
7414 &dummy)) | |
7415 return 0; | |
7416 } | |
7417 | |
7418 return 1; | |
7419 } | |
7420 #endif | |
26 | 7421 |
7422 | |
7423 #if defined(FEAT_MBYTE) || defined(PROTO) | |
7424 /* | |
7425 * The command line arguments in UCS2 | |
7426 */ | |
344 | 7427 static int nArgsW = 0; |
26 | 7428 static LPWSTR *ArglistW = NULL; |
7429 static int global_argc = 0; | |
7430 static char **global_argv; | |
7431 | |
7432 static int used_file_argc = 0; /* last argument in global_argv[] used | |
7433 for the argument list. */ | |
7434 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
7435 command line arguments added to | |
7436 the argument list */ | |
7437 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
7438 static int used_file_literal = FALSE; /* take file names literally */ | |
7439 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 7440 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 7441 static int used_alist_count = 0; |
7442 | |
7443 | |
7444 /* | |
7445 * Get the command line arguments. Unicode version. | |
7446 * Returns argc. Zero when something fails. | |
7447 */ | |
7448 int | |
7449 get_cmd_argsW(char ***argvp) | |
7450 { | |
7451 char **argv = NULL; | |
7452 int argc = 0; | |
7453 int i; | |
7454 | |
6193 | 7455 free_cmd_argsW(); |
26 | 7456 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7457 if (ArglistW != NULL) | |
7458 { | |
7459 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7460 if (argv != NULL) | |
7461 { | |
7462 argc = nArgsW; | |
7463 argv[argc] = NULL; | |
7464 for (i = 0; i < argc; ++i) | |
7465 { | |
7466 int len; | |
7467 | |
7468 /* Convert each Unicode argument to the current codepage. */ | |
7469 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 7470 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7471 (LPSTR *)&argv[i], &len, 0, 0); |
7472 if (argv[i] == NULL) | |
7473 { | |
7474 /* Out of memory, clear everything. */ | |
7475 while (i > 0) | |
7476 free(argv[--i]); | |
7477 free(argv); | |
5529 | 7478 argv = NULL; |
26 | 7479 argc = 0; |
7480 } | |
7481 } | |
7482 } | |
7483 } | |
7484 | |
7485 global_argc = argc; | |
7486 global_argv = argv; | |
7487 if (argc > 0) | |
6193 | 7488 { |
7489 if (used_file_indexes != NULL) | |
7490 free(used_file_indexes); | |
26 | 7491 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7492 } |
26 | 7493 |
7494 if (argvp != NULL) | |
7495 *argvp = argv; | |
7496 return argc; | |
7497 } | |
7498 | |
7499 void | |
7500 free_cmd_argsW(void) | |
7501 { | |
7502 if (ArglistW != NULL) | |
7503 { | |
7504 GlobalFree(ArglistW); | |
7505 ArglistW = NULL; | |
7506 } | |
7507 } | |
7508 | |
7509 /* | |
7510 * Remember "name" is an argument that was added to the argument list. | |
7511 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7512 * is called. | |
7513 */ | |
7514 void | |
819 | 7515 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7516 { |
7517 int i; | |
7518 | |
7519 if (used_file_indexes == NULL) | |
7520 return; | |
7521 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7522 if (STRCMP(global_argv[i], name) == 0) | |
7523 { | |
7524 used_file_argc = i; | |
7525 used_file_indexes[used_file_count++] = i; | |
7526 break; | |
7527 } | |
7528 used_file_literal = literal; | |
7529 used_file_full_path = full_path; | |
819 | 7530 used_file_diff_mode = diff_mode; |
26 | 7531 } |
7532 | |
7533 /* | |
7534 * Remember the length of the argument list as it was. If it changes then we | |
7535 * leave it alone when 'encoding' is set. | |
7536 */ | |
7537 void | |
7538 set_alist_count(void) | |
7539 { | |
7540 used_alist_count = GARGCOUNT; | |
7541 } | |
7542 | |
7543 /* | |
7544 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
7545 * has been changed while starting up. Use the UCS-2 command line arguments | |
7546 * and convert them to 'encoding'. | |
7547 */ | |
7548 void | |
7549 fix_arg_enc(void) | |
7550 { | |
7551 int i; | |
7552 int idx; | |
7553 char_u *str; | |
41 | 7554 int *fnum_list; |
26 | 7555 |
7556 /* Safety checks: | |
7557 * - if argument count differs between the wide and non-wide argument | |
7558 * list, something must be wrong. | |
7559 * - the file name arguments must have been located. | |
7560 * - the length of the argument list wasn't changed by the user. | |
7561 */ | |
344 | 7562 if (global_argc != nArgsW |
26 | 7563 || ArglistW == NULL |
7564 || used_file_indexes == NULL | |
7565 || used_file_count == 0 | |
7566 || used_alist_count != GARGCOUNT) | |
7567 return; | |
7568 | |
41 | 7569 /* Remember the buffer numbers for the arguments. */ |
7570 fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT); | |
7571 if (fnum_list == NULL) | |
7572 return; /* out of memory */ | |
7573 for (i = 0; i < GARGCOUNT; ++i) | |
7574 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7575 | |
26 | 7576 /* Clear the argument list. Make room for the new arguments. */ |
7577 alist_clear(&global_alist); | |
7578 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 7579 return; /* out of memory */ |
26 | 7580 |
7581 for (i = 0; i < used_file_count; ++i) | |
7582 { | |
7583 idx = used_file_indexes[i]; | |
1752 | 7584 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7585 if (str != NULL) |
41 | 7586 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7587 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
|
7588 |
819 | 7589 #ifdef FEAT_DIFF |
7590 /* When using diff mode may need to concatenate file name to | |
7591 * directory name. Just like it's done in main(). */ | |
7592 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
7593 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7594 { | |
7595 char_u *r; | |
7596 | |
7597 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7598 if (r != NULL) | |
7599 { | |
7600 vim_free(str); | |
7601 str = r; | |
7602 } | |
7603 } | |
7604 #endif | |
41 | 7605 /* Re-use the old buffer by renaming it. When not using literal |
7606 * names it's done by alist_expand() below. */ | |
7607 if (used_file_literal) | |
7608 buf_set_name(fnum_list[i], str); | |
7609 | |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7610 /* Check backtick literal. backtick literal is already expanded in |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7611 * main.c, so this part add str as literal. */ |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7612 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
|
7613 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7614 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
|
7615 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7616 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
|
7617 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7618 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7619 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7620 } |
26 | 7621 } |
7622 | |
7623 if (!used_file_literal) | |
7624 { | |
7625 /* Now expand wildcards in the arguments. */ | |
7626 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
7627 * filename characters but are excluded from 'isfname' to make | |
13433
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7628 * "gf" work on a file name in parenthesis (e.g.: see vim.h). |
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7629 * Also, unset wildignore to not be influenced by this option. |
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7630 * The arguments specified in command-line should be kept even if |
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7631 * encoding options were changed. */ |
26 | 7632 do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); |
13433
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7633 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); |
41 | 7634 alist_expand(fnum_list, used_alist_count); |
26 | 7635 do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF"); |
13433
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7636 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); |
26 | 7637 } |
7638 | |
7639 /* If wildcard expansion failed, we are editing the first file of the | |
7640 * arglist and there is no file name: Edit the first argument now. */ | |
7641 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
7642 { | |
7643 do_cmdline_cmd((char_u *)":rewind"); | |
7644 if (GARGCOUNT == 1 && used_file_full_path) | |
13170
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
12990
diff
changeset
|
7645 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); |
26 | 7646 } |
41 | 7647 |
7648 set_alist_count(); | |
26 | 7649 } |
7650 #endif | |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7651 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7652 int |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7653 mch_setenv(char *var, char *value, int x) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7654 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7655 char_u *envbuf; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7656 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7657 envbuf = alloc((unsigned)(STRLEN(var) + STRLEN(value) + 2)); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7658 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
|
7659 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
|
7660 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7661 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
|
7662 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7663 #ifdef FEAT_MBYTE |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7664 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7665 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7666 WCHAR *p = enc_to_utf16(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
|
7667 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7668 vim_free(envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7669 if (p == NULL) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7670 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
|
7671 _wputenv(p); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7672 # ifdef libintl_wputenv |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7673 libintl_wputenv(p); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7674 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7675 /* Unlike Un*x systems, we can free the string for _wputenv(). */ |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7676 vim_free(p); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7677 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7678 else |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7679 #endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7680 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7681 _putenv((char *)envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7682 # ifdef libintl_putenv |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7683 libintl_putenv((char *)envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7684 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7685 /* Unlike Un*x systems, we can free the string for _putenv(). */ |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7686 vim_free(envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7687 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7688 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7689 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
|
7690 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7691 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7692 #ifndef FEAT_GUI_W32 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7693 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7694 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7695 * 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
|
7696 * 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
|
7697 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7698 # define VTP_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 15063) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7699 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7700 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
|
7701 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
|
7702 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7703 DWORD ver, mode; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7704 HMODULE hKerneldll; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7705 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7706 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7707 COLORREF fg, bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7708 # 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
|
7709 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7710 ver = get_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
|
7711 vtp_working = (ver >= VTP_FIRST_SUPPORT_BUILD) ? 1 : 0; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7712 GetConsoleMode(g_hConOut, &mode); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7713 mode |= (ENABLE_PROCESSED_OUTPUT | 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
|
7714 if (SetConsoleMode(g_hConOut, mode) == 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7715 vtp_working = 0; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7716 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7717 /* Use functions supported from Vista */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7718 hKerneldll = GetModuleHandle("kernel32.dll"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7719 if (hKerneldll != NULL) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7720 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7721 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7722 (PfnGetConsoleScreenBufferInfoEx)GetProcAddress( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7723 hKerneldll, "GetConsoleScreenBufferInfoEx"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7724 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7725 (PfnSetConsoleScreenBufferInfoEx)GetProcAddress( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7726 hKerneldll, "SetConsoleScreenBufferInfoEx"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7727 if (pGetConsoleScreenBufferInfoEx != NULL |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7728 && pSetConsoleScreenBufferInfoEx != NULL) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7729 has_csbiex = TRUE; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7730 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7731 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7732 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
|
7733 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7734 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7735 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
|
7736 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg]; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7737 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7738 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7739 bg = (COLORREF)csbi.ColorTable[g_color_index_bg]; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7740 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
|
7741 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7742 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
|
7743 default_console_color_bg = bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7744 default_console_color_fg = fg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7745 #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
|
7746 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7747 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
|
7748 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7749 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7750 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
|
7751 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
|
7752 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7753 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
|
7754 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7755 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7756 static int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7757 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
|
7758 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
|
7759 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7760 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7761 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
|
7762 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
|
7763 DWORD result; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7764 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7765 va_start(list, format); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7766 vim_vsnprintf((char *)buf, 100, (char *)format, list); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7767 va_end(list); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7768 WriteConsoleA(g_hConOut, buf, (DWORD)STRLEN(buf), &result, NULL); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7769 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
|
7770 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7771 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7772 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
|
7773 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
|
7774 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
|
7775 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7776 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
|
7777 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7778 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
|
7779 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
|
7780 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7781 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7782 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
|
7783 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
|
7784 int argc, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7785 int *args |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7786 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7787 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7788 /* 2('\033[') + 4('255.') * 16 + NUL */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7789 char_u buf[2 + (4 * 16) + 1]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7790 char_u *p; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7791 int i; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7792 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7793 p = buf; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7794 *p++ = '\033'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7795 *p++ = '['; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7796 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7797 for (i = 0; i < argc; ++i) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7798 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7799 p += vim_snprintf((char *)p, 4, "%d", args[i] & 0xff); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7800 *p++ = ';'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7801 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7802 p--; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7803 *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
|
7804 *p = NUL; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7805 vtp_printf((char *)buf); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7806 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7807 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7808 # 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
|
7809 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
|
7810 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7811 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
|
7812 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
7813 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
|
7814 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7815 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
|
7816 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
|
7817 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7818 # 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
|
7819 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7820 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
|
7821 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
|
7822 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7823 # ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7824 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7825 int id; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7826 guicolor_T fg = INVALCOLOR; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7827 guicolor_T bg = INVALCOLOR; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7828 int ctermfg; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7829 int ctermbg; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7830 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7831 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
|
7832 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7833 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7834 id = syn_name2id((char_u *)"Normal"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7835 if (id > 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7836 syn_id2colors(id, &fg, &bg); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7837 if (fg == INVALCOLOR) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7838 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7839 ctermfg = -1; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7840 if (id > 0) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7841 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7842 fg = ctermfg != -1 ? ctermtoxterm(ctermfg) : default_console_color_fg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7843 cterm_normal_fg_gui_color = fg; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7844 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7845 if (bg == INVALCOLOR) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7846 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7847 ctermbg = -1; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7848 if (id > 0) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7849 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7850 bg = ctermbg != -1 ? ctermtoxterm(ctermbg) : default_console_color_bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7851 cterm_normal_bg_gui_color = bg; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7852 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7853 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
|
7854 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
|
7855 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7856 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
|
7857 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7858 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7859 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7860 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
|
7861 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
|
7862 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
|
7863 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
|
7864 csbi.ColorTable[g_color_index_fg] = (COLORREF)fg; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7865 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7866 pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7867 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7868 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7869 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7870 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
|
7871 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
|
7872 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7873 # ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7874 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7875 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7876 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
|
7877 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7878 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7879 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7880 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
|
7881 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
|
7882 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
|
7883 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
|
7884 csbi.ColorTable[g_color_index_fg] = (COLORREF)save_console_fg_rgb; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7885 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7886 pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7887 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7888 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7889 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7890 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7891 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
|
7892 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7893 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
|
7894 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
|
7895 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7896 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
|
7897 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7898 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7899 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7900 has_vtp_working(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7901 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7902 return vtp_working; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7903 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7904 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7905 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7906 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
|
7907 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7908 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
|
7909 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7910 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7911 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7912 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
|
7913 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7914 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
|
7915 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7916 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7917 #endif |