Mercurial > vim
annotate src/os_win32.c @ 13628:b59806681b98 v8.0.1686
patch 8.0.1686: Python does not work when configuring with specific dir
commit https://github.com/vim/vim/commit/d088240b96bc8b2bdba9242dcb9e3d36f1e16c48
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 10 18:13:05 2018 +0200
patch 8.0.1686: Python does not work when configuring with specific dir
Problem: Python does not work when configuring with specific dir. (Rajdeep)
Solution: Do define PYTHON_HOME and PYTHON3_HOME in configure if the Python
config dir was specified.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 10 Apr 2018 18:15:07 +0200 |
parents | cc7dc249e371 |
children | d0d8125ba692 |
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 termcap_mode_start(void); | |
172 static void termcap_mode_end(void); | |
173 static void clear_chars(COORD coord, DWORD n); | |
174 static void clear_screen(void); | |
175 static void clear_to_end_of_display(void); | |
176 static void clear_to_end_of_line(void); | |
177 static void scroll(unsigned cLines); | |
178 static void set_scroll_region(unsigned left, unsigned top, | |
179 unsigned right, unsigned bottom); | |
180 static void insert_lines(unsigned cLines); | |
181 static void delete_lines(unsigned cLines); | |
182 static void gotoxy(unsigned x, unsigned y); | |
183 static void normvideo(void); | |
184 static void textattr(WORD wAttr); | |
185 static void textcolor(WORD wAttr); | |
186 static void textbackground(WORD wAttr); | |
187 static void standout(void); | |
188 static void standend(void); | |
189 static void visual_bell(void); | |
190 static void cursor_visible(BOOL fVisible); | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
191 static DWORD write_chars(char_u *pchBuf, DWORD cbToWrite); |
7 | 192 static void create_conin(void); |
193 static int s_cursor_visible = TRUE; | |
194 static int did_create_conin = FALSE; | |
195 #else | |
196 static int s_dont_use_vimrun = TRUE; | |
197 static int need_vimrun_warning = FALSE; | |
198 static char *vimrun_path = "vimrun "; | |
199 #endif | |
200 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
201 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
202 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
|
203 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
204 |
7 | 205 #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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
213 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
|
214 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
|
215 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
216 # 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
|
217 # define USE_VTP (vtp_working && 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
|
218 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
219 # 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
|
220 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
221 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
222 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
|
223 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
|
224 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
225 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
226 /* 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
|
227 #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
|
228 # 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
|
229 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
230 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
231 #ifndef FEAT_GUI_W32 |
7 | 232 static int suppress_winsize = 1; /* don't fiddle with console */ |
233 #endif | |
234 | |
2612 | 235 static char_u *exe_path = NULL; |
236 | |
5633 | 237 static BOOL win8_or_later = FALSE; |
238 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
239 #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
|
240 /* 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
|
241 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
|
242 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 } 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
259 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
260 * 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
|
261 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
262 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
|
263 # 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
|
264 (((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
|
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 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
|
267 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
|
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 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
|
270 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
|
271 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
|
272 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
|
273 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
274 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
|
275 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
|
276 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
277 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
278 (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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
284 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
|
285 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
286 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
287 |
5580 | 288 /* |
289 * Version of ReadConsoleInput() that works with IME. | |
5590 | 290 * Works around problems on Windows 8. |
5580 | 291 */ |
292 static BOOL | |
293 read_console_input( | |
5590 | 294 HANDLE hInput, |
295 INPUT_RECORD *lpBuffer, | |
296 DWORD nLength, | |
297 LPDWORD lpEvents) | |
5580 | 298 { |
299 enum | |
300 { | |
5590 | 301 IRSIZE = 10 |
5580 | 302 }; |
5590 | 303 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 304 static DWORD s_dwIndex = 0; |
305 static DWORD s_dwMax = 0; | |
5590 | 306 DWORD dwEvents; |
5635 | 307 int head; |
308 int tail; | |
309 int i; | |
5580 | 310 |
6981 | 311 if (nLength == -2) |
312 return (s_dwMax > 0) ? TRUE : FALSE; | |
313 | |
5633 | 314 if (!win8_or_later) |
315 { | |
316 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
317 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
318 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 319 } |
320 | |
5580 | 321 if (s_dwMax == 0) |
322 { | |
5590 | 323 if (nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
324 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
325 if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents)) |
5590 | 326 return FALSE; |
5580 | 327 s_dwIndex = 0; |
5590 | 328 s_dwMax = dwEvents; |
329 if (dwEvents == 0) | |
5580 | 330 { |
5590 | 331 *lpEvents = 0; |
332 return TRUE; | |
5580 | 333 } |
5635 | 334 |
335 if (s_dwMax > 1) | |
336 { | |
337 head = 0; | |
338 tail = s_dwMax - 1; | |
339 while (head != tail) | |
340 { | |
341 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
342 && s_irCache[head + 1].EventType | |
343 == WINDOW_BUFFER_SIZE_EVENT) | |
344 { | |
345 /* Remove duplicate event to avoid flicker. */ | |
346 for (i = head; i < tail; ++i) | |
347 s_irCache[i] = s_irCache[i + 1]; | |
348 --tail; | |
349 continue; | |
350 } | |
351 head++; | |
352 } | |
353 s_dwMax = tail + 1; | |
354 } | |
5580 | 355 } |
5635 | 356 |
5590 | 357 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 358 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 359 s_dwMax = 0; |
5590 | 360 *lpEvents = 1; |
5580 | 361 return TRUE; |
362 } | |
363 | |
364 /* | |
365 * Version of PeekConsoleInput() that works with IME. | |
366 */ | |
367 static BOOL | |
368 peek_console_input( | |
5590 | 369 HANDLE hInput, |
370 INPUT_RECORD *lpBuffer, | |
371 DWORD nLength, | |
372 LPDWORD lpEvents) | |
5580 | 373 { |
5590 | 374 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 375 } |
376 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
377 # ifdef FEAT_CLIENTSERVER |
6981 | 378 static DWORD |
379 msg_wait_for_multiple_objects( | |
380 DWORD nCount, | |
381 LPHANDLE pHandles, | |
382 BOOL fWaitAll, | |
383 DWORD dwMilliseconds, | |
384 DWORD dwWakeMask) | |
385 { | |
386 if (read_console_input(NULL, NULL, -2, NULL)) | |
387 return WAIT_OBJECT_0; | |
388 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
389 dwMilliseconds, dwWakeMask); | |
390 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
391 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
392 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
393 # ifndef FEAT_CLIENTSERVER |
6981 | 394 static DWORD |
395 wait_for_single_object( | |
396 HANDLE hHandle, | |
397 DWORD dwMilliseconds) | |
398 { | |
399 if (read_console_input(NULL, NULL, -2, NULL)) | |
400 return WAIT_OBJECT_0; | |
401 return WaitForSingleObject(hHandle, dwMilliseconds); | |
402 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
403 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
404 #endif |
6981 | 405 |
7 | 406 static void |
407 get_exe_name(void) | |
408 { | |
2630 | 409 /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned |
410 * as the maximum length that works (plus a NUL byte). */ | |
411 #define MAX_ENV_PATH_LEN 8192 | |
412 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 413 char_u *p; |
7 | 414 |
415 if (exe_name == NULL) | |
416 { | |
417 /* store the name of the executable, may be used for $VIM */ | |
2630 | 418 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 419 if (*temp != NUL) |
420 exe_name = FullName_save((char_u *)temp, FALSE); | |
421 } | |
819 | 422 |
2612 | 423 if (exe_path == NULL && exe_name != NULL) |
819 | 424 { |
2615 | 425 exe_path = vim_strnsave(exe_name, |
426 (int)(gettail_sep(exe_name) - exe_name)); | |
2612 | 427 if (exe_path != NULL) |
819 | 428 { |
2612 | 429 /* Append our starting directory to $PATH, so that when doing |
430 * "!xxd" it's found in our starting directory. Needed because | |
431 * SearchPath() also looks there. */ | |
432 p = mch_getenv("PATH"); | |
2630 | 433 if (p == NULL |
434 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 435 { |
2630 | 436 if (p == NULL || *p == NUL) |
437 temp[0] = NUL; | |
438 else | |
439 { | |
440 STRCPY(temp, p); | |
441 STRCAT(temp, ";"); | |
442 } | |
2612 | 443 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
444 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 445 } |
819 | 446 } |
447 } | |
7 | 448 } |
449 | |
2612 | 450 /* |
3361 | 451 * Unescape characters in "p" that appear in "escaped". |
452 */ | |
453 static void | |
454 unescape_shellxquote(char_u *p, char_u *escaped) | |
455 { | |
3386 | 456 int l = (int)STRLEN(p); |
3361 | 457 int n; |
458 | |
459 while (*p != NUL) | |
460 { | |
461 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
462 mch_memmove(p, p + 1, l--); | |
463 #ifdef FEAT_MBYTE | |
464 n = (*mb_ptr2len)(p); | |
465 #else | |
466 n = 1; | |
467 #endif | |
468 p += n; | |
469 l -= n; | |
470 } | |
471 } | |
472 | |
473 /* | |
2612 | 474 * Load library "name". |
475 */ | |
476 HINSTANCE | |
477 vimLoadLib(char *name) | |
478 { | |
3902 | 479 HINSTANCE dll = NULL; |
3889 | 480 |
481 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call | |
482 * vimLoadLib() recursively, which causes a stack overflow. */ | |
2612 | 483 if (exe_path == NULL) |
484 get_exe_name(); | |
3902 | 485 if (exe_path != NULL) |
2612 | 486 { |
3902 | 487 WCHAR old_dirw[MAXPATHL]; |
488 | |
489 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
490 { | |
491 /* Change directory to where the executable is, both to make | |
492 * sure we find a .dll there and to avoid looking for a .dll | |
493 * in the current directory. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
494 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 495 dll = LoadLibrary(name); |
496 SetCurrentDirectoryW(old_dirw); | |
497 return dll; | |
498 } | |
2612 | 499 } |
500 return dll; | |
501 } | |
502 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
503 #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
|
504 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
505 * 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
|
506 * 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
|
507 * 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
|
508 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
509 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
|
510 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
|
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 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
520 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
|
521 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 + 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
|
527 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
528 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
|
529 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
530 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
|
531 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
532 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
|
533 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
|
534 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
|
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 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
|
537 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
538 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
|
539 + (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
|
540 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
|
541 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
542 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
|
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 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
|
545 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
|
546 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
|
547 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
|
548 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
549 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
|
550 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
551 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
552 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
553 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
554 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
|
555 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
556 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
557 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
558 * 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
|
559 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
560 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
561 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
|
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 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
|
564 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
565 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
|
566 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
|
567 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
|
568 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
569 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
570 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
571 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
572 * Get the 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
|
573 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
574 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
575 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
|
576 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
577 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
|
578 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
579 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
580 |
7 | 581 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
582 # ifndef GETTEXT_DLL | |
583 # define GETTEXT_DLL "libintl.dll" | |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
584 # define GETTEXT_DLL_ALT "libintl-8.dll" |
7 | 585 # endif |
3622 | 586 /* Dummy functions */ |
36 | 587 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
|
588 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 589 static char *null_libintl_textdomain(const char *); |
590 static char *null_libintl_bindtextdomain(const char *, const char *); | |
591 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
|
592 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
|
593 static int null_libintl_wputenv(const wchar_t *); |
7 | 594 |
2612 | 595 static HINSTANCE hLibintlDLL = NULL; |
36 | 596 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
|
597 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
|
598 = null_libintl_ngettext; |
36 | 599 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
600 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 601 = null_libintl_bindtextdomain; |
36 | 602 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
603 = 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
|
604 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
|
605 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 606 |
607 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
608 dyn_libintl_init(void) |
7 | 609 { |
610 int i; | |
611 static struct | |
612 { | |
613 char *name; | |
614 FARPROC *ptr; | |
615 } libintl_entry[] = | |
616 { | |
617 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
618 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 619 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
620 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
621 {NULL, NULL} | |
622 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
623 HINSTANCE hmsvcrt; |
7 | 624 |
625 /* No need to initialize twice. */ | |
626 if (hLibintlDLL) | |
627 return 1; | |
628 /* Load gettext library (libintl.dll) */ | |
7784
29d4ee3f009a
commit https://github.com/vim/vim/commit/923e43b837ca4c8edb7998743f142823eaeaf588
Christian Brabandt <cb@256bit.org>
parents:
7734
diff
changeset
|
629 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
630 #ifdef GETTEXT_DLL_ALT |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
631 if (!hLibintlDLL) |
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
632 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
633 #endif |
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
634 if (!hLibintlDLL) |
7 | 635 { |
2612 | 636 if (p_verbose > 0) |
7 | 637 { |
2612 | 638 verbose_enter(); |
639 EMSG2(_(e_loadlib), GETTEXT_DLL); | |
640 verbose_leave(); | |
7 | 641 } |
2612 | 642 return 0; |
7 | 643 } |
644 for (i = 0; libintl_entry[i].name != NULL | |
645 && libintl_entry[i].ptr != NULL; ++i) | |
646 { | |
647 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
648 libintl_entry[i].name)) == NULL) | |
649 { | |
650 dyn_libintl_end(); | |
651 if (p_verbose > 0) | |
292 | 652 { |
653 verbose_enter(); | |
7 | 654 EMSG2(_(e_loadfunc), libintl_entry[i].name); |
292 | 655 verbose_leave(); |
656 } | |
7 | 657 return 0; |
658 } | |
659 } | |
36 | 660 |
661 /* The bind_textdomain_codeset() function is optional. */ | |
323 | 662 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 663 "bind_textdomain_codeset"); |
664 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
665 dyn_libintl_bind_textdomain_codeset = | |
666 null_libintl_bind_textdomain_codeset; | |
667 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
668 /* _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
|
669 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
|
670 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
|
671 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
672 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
|
673 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
|
674 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 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
|
679 |
7 | 680 return 1; |
681 } | |
682 | |
683 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
684 dyn_libintl_end(void) |
7 | 685 { |
686 if (hLibintlDLL) | |
687 FreeLibrary(hLibintlDLL); | |
688 hLibintlDLL = NULL; | |
689 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
|
690 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 691 dyn_libintl_textdomain = null_libintl_textdomain; |
692 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 693 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
|
694 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
|
695 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 696 } |
697 | |
698 static char * | |
26 | 699 null_libintl_gettext(const char *msgid) |
7 | 700 { |
701 return (char*)msgid; | |
702 } | |
703 | |
704 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
705 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
706 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
707 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
708 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
709 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
710 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
|
711 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
712 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
713 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
|
714 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
|
715 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
|
716 const char *dirname UNUSED) |
7 | 717 { |
718 return NULL; | |
719 } | |
720 | |
721 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
|
722 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
|
723 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
|
724 const char *codeset UNUSED) |
36 | 725 { |
726 return NULL; | |
727 } | |
728 | |
729 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
|
730 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 731 { |
732 return NULL; | |
733 } | |
734 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
735 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
|
736 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
|
737 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
738 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
|
739 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
740 |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
741 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
|
742 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
|
743 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
744 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
|
745 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
746 |
7 | 747 #endif /* DYNAMIC_GETTEXT */ |
748 | |
749 /* This symbol is not defined in older versions of the SDK or Visual C++ */ | |
750 | |
751 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
752 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
753 #endif | |
754 | |
755 DWORD g_PlatformId; | |
756 | |
757 #ifdef HAVE_ACL | |
3927 | 758 # ifndef PROTO |
759 # include <aclapi.h> | |
760 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
761 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
762 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
763 # endif |
7 | 764 #endif |
765 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
766 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
767 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
768 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
769 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
770 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
771 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
772 { |
5590 | 773 BOOL bResult; |
774 LUID luid; | |
775 HANDLE hToken; | |
776 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
777 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
778 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
779 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
780 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
781 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
782 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
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 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
785 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
786 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
787 |
6047 | 788 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
789 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
790 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
791 SE_PRIVILEGE_ENABLED : 0; |
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 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
794 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
795 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
796 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
797 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
798 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
799 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
800 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
801 |
7 | 802 /* |
803 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
804 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
805 */ | |
806 void | |
807 PlatformId(void) | |
808 { | |
809 static int done = FALSE; | |
810 | |
811 if (!done) | |
812 { | |
813 OSVERSIONINFO ovi; | |
814 | |
815 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
816 GetVersionEx(&ovi); | |
817 | |
818 g_PlatformId = ovi.dwPlatformId; | |
819 | |
5633 | 820 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
821 || ovi.dwMajorVersion > 6) | |
822 win8_or_later = TRUE; | |
823 | |
7 | 824 #ifdef HAVE_ACL |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
825 /* 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
|
826 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 827 #endif |
828 done = TRUE; | |
829 } | |
830 } | |
831 | |
832 #ifndef FEAT_GUI_W32 | |
833 | |
834 #define SHIFT (SHIFT_PRESSED) | |
835 #define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) | |
836 #define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) | |
837 #define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) | |
838 | |
839 | |
840 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. | |
841 * We map function keys to their ANSI terminal equivalents, as produced | |
842 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any | |
843 * ANSI key with a value >= '\300' is nonstandard, but provided anyway | |
844 * so that the user can have access to all SHIFT-, CTRL-, and ALT- | |
845 * combinations of function/arrow/etc keys. | |
846 */ | |
847 | |
297 | 848 static const struct |
7 | 849 { |
850 WORD wVirtKey; | |
851 BOOL fAnsiKey; | |
852 int chAlone; | |
853 int chShift; | |
854 int chCtrl; | |
855 int chAlt; | |
856 } VirtKeyMap[] = | |
857 { | |
858 | |
859 /* Key ANSI alone shift ctrl alt */ | |
860 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, | |
861 | |
862 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
863 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
864 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
865 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
866 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
867 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
868 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
869 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
870 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
871 { VK_F10, TRUE, 'D', ']', 'g', 'q', }, | |
872 { VK_F11, TRUE, '\205', '\207', '\211', '\213', }, | |
873 { VK_F12, TRUE, '\206', '\210', '\212', '\214', }, | |
874 | |
875 { VK_HOME, TRUE, 'G', '\302', 'w', '\303', }, | |
876 { VK_UP, TRUE, 'H', '\304', '\305', '\306', }, | |
877 { VK_PRIOR, TRUE, 'I', '\307', '\204', '\310', }, /*PgUp*/ | |
878 { VK_LEFT, TRUE, 'K', '\311', 's', '\312', }, | |
879 { VK_RIGHT, TRUE, 'M', '\313', 't', '\314', }, | |
880 { VK_END, TRUE, 'O', '\315', 'u', '\316', }, | |
881 { VK_DOWN, TRUE, 'P', '\317', '\320', '\321', }, | |
882 { VK_NEXT, TRUE, 'Q', '\322', 'v', '\323', }, /*PgDn*/ | |
883 { VK_INSERT,TRUE, 'R', '\324', '\325', '\326', }, | |
884 { VK_DELETE,TRUE, 'S', '\327', '\330', '\331', }, | |
885 | |
886 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, /*PrtScrn*/ | |
887 | |
888 #if 0 | |
889 /* Most people don't have F13-F20, but what the hell... */ | |
890 { VK_F13, TRUE, '\332', '\333', '\334', '\335', }, | |
891 { VK_F14, TRUE, '\336', '\337', '\340', '\341', }, | |
892 { VK_F15, TRUE, '\342', '\343', '\344', '\345', }, | |
893 { VK_F16, TRUE, '\346', '\347', '\350', '\351', }, | |
894 { VK_F17, TRUE, '\352', '\353', '\354', '\355', }, | |
895 { VK_F18, TRUE, '\356', '\357', '\360', '\361', }, | |
896 { VK_F19, TRUE, '\362', '\363', '\364', '\365', }, | |
897 { VK_F20, TRUE, '\366', '\367', '\370', '\371', }, | |
898 #endif | |
899 { VK_ADD, TRUE, 'N', 'N', 'N', 'N', }, /* keyp '+' */ | |
900 { VK_SUBTRACT, TRUE,'J', 'J', 'J', 'J', }, /* keyp '-' */ | |
901 /* { VK_DIVIDE, TRUE,'N', 'N', 'N', 'N', }, keyp '/' */ | |
902 { VK_MULTIPLY, TRUE,'7', '7', '7', '7', }, /* keyp '*' */ | |
903 | |
904 { VK_NUMPAD0,TRUE, '\332', '\333', '\334', '\335', }, | |
905 { VK_NUMPAD1,TRUE, '\336', '\337', '\340', '\341', }, | |
906 { VK_NUMPAD2,TRUE, '\342', '\343', '\344', '\345', }, | |
907 { VK_NUMPAD3,TRUE, '\346', '\347', '\350', '\351', }, | |
908 { VK_NUMPAD4,TRUE, '\352', '\353', '\354', '\355', }, | |
909 { VK_NUMPAD5,TRUE, '\356', '\357', '\360', '\361', }, | |
910 { VK_NUMPAD6,TRUE, '\362', '\363', '\364', '\365', }, | |
911 { VK_NUMPAD7,TRUE, '\366', '\367', '\370', '\371', }, | |
912 { VK_NUMPAD8,TRUE, '\372', '\373', '\374', '\375', }, | |
913 /* Sorry, out of number space! <negri>*/ | |
914 { VK_NUMPAD9,TRUE, '\376', '\377', '\377', '\367', }, | |
915 | |
916 }; | |
917 | |
918 | |
919 #ifdef _MSC_VER | |
920 // The ToAscii bug destroys several registers. Need to turn off optimization | |
921 // or the GetConsoleKeyboardLayoutName hack will fail in non-debug versions | |
797 | 922 # pragma warning(push) |
923 # pragma warning(disable: 4748) | |
7 | 924 # pragma optimize("", off) |
925 #endif | |
926 | |
927 #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
|
928 # define UChar UnicodeChar |
7 | 929 #else |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
930 # define UChar uChar.UnicodeChar |
7 | 931 #endif |
932 | |
933 /* The return code indicates key code size. */ | |
934 static int | |
935 #ifdef __BORLANDC__ | |
936 __stdcall | |
937 #endif | |
938 win32_kbd_patch_key( | |
26 | 939 KEY_EVENT_RECORD *pker) |
7 | 940 { |
941 UINT uMods = pker->dwControlKeyState; | |
942 static int s_iIsDead = 0; | |
943 static WORD awAnsiCode[2]; | |
944 static BYTE abKeystate[256]; | |
945 | |
946 | |
947 if (s_iIsDead == 2) | |
948 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
949 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 950 s_iIsDead = 0; |
951 return 1; | |
952 } | |
953 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
954 if (pker->UChar != 0) |
7 | 955 return 1; |
956 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
957 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 958 |
959 /* Clear any pending dead keys */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
960 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 961 |
962 if (uMods & SHIFT_PRESSED) | |
963 abKeystate[VK_SHIFT] = 0x80; | |
964 if (uMods & CAPSLOCK_ON) | |
965 abKeystate[VK_CAPITAL] = 1; | |
966 | |
967 if ((uMods & ALT_GR) == ALT_GR) | |
968 { | |
969 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
970 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
971 } | |
972 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
973 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
|
974 abKeystate, awAnsiCode, 2, 0); |
7 | 975 |
976 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
977 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 978 |
979 return s_iIsDead; | |
980 } | |
981 | |
982 #ifdef _MSC_VER | |
983 /* MUST switch optimization on again here, otherwise a call to | |
984 * decode_key_event() may crash (e.g. when hitting caps-lock) */ | |
985 # pragma optimize("", on) | |
797 | 986 # pragma warning(pop) |
7 | 987 |
988 # if (_MSC_VER < 1100) | |
989 /* MUST turn off global optimisation for this next function, or | |
990 * pressing ctrl-minus in insert mode crashes Vim when built with | |
991 * VC4.1. -- negri. */ | |
992 # pragma optimize("g", off) | |
993 # endif | |
994 #endif | |
995 | |
996 static BOOL g_fJustGotFocus = FALSE; | |
997 | |
998 /* | |
999 * Decode a KEY_EVENT into one or two keystrokes | |
1000 */ | |
1001 static BOOL | |
1002 decode_key_event( | |
1003 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1004 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1005 WCHAR *pch2, |
7 | 1006 int *pmodifiers, |
1007 BOOL fDoPost) | |
1008 { | |
1009 int i; | |
1010 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
1011 | |
1012 *pch = *pch2 = NUL; | |
1013 g_fJustGotFocus = FALSE; | |
1014 | |
1015 /* ignore key up events */ | |
1016 if (!pker->bKeyDown) | |
1017 return FALSE; | |
1018 | |
1019 /* ignore some keystrokes */ | |
1020 switch (pker->wVirtualKeyCode) | |
1021 { | |
1022 /* modifiers */ | |
1023 case VK_SHIFT: | |
1024 case VK_CONTROL: | |
1025 case VK_MENU: /* Alt key */ | |
1026 return FALSE; | |
1027 | |
1028 default: | |
1029 break; | |
1030 } | |
1031 | |
1032 /* special cases */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1033 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 1034 { |
1035 /* Ctrl-6 is Ctrl-^ */ | |
1036 if (pker->wVirtualKeyCode == '6') | |
1037 { | |
1038 *pch = Ctrl_HAT; | |
1039 return TRUE; | |
1040 } | |
1041 /* Ctrl-2 is Ctrl-@ */ | |
1042 else if (pker->wVirtualKeyCode == '2') | |
1043 { | |
1044 *pch = NUL; | |
1045 return TRUE; | |
1046 } | |
1047 /* Ctrl-- is Ctrl-_ */ | |
1048 else if (pker->wVirtualKeyCode == 0xBD) | |
1049 { | |
1050 *pch = Ctrl__; | |
1051 return TRUE; | |
1052 } | |
1053 } | |
1054 | |
1055 /* Shift-TAB */ | |
1056 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) | |
1057 { | |
1058 *pch = K_NUL; | |
1059 *pch2 = '\017'; | |
1060 return TRUE; | |
1061 } | |
1062 | |
1063 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
1064 { | |
1065 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1066 { | |
1067 if (nModifs == 0) | |
1068 *pch = VirtKeyMap[i].chAlone; | |
1069 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1070 *pch = VirtKeyMap[i].chShift; | |
1071 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1072 *pch = VirtKeyMap[i].chCtrl; | |
1073 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1074 *pch = VirtKeyMap[i].chAlt; | |
1075 | |
1076 if (*pch != 0) | |
1077 { | |
1078 if (VirtKeyMap[i].fAnsiKey) | |
1079 { | |
1080 *pch2 = *pch; | |
1081 *pch = K_NUL; | |
1082 } | |
1083 | |
1084 return TRUE; | |
1085 } | |
1086 } | |
1087 } | |
1088 | |
1089 i = win32_kbd_patch_key(pker); | |
1090 | |
1091 if (i < 0) | |
1092 *pch = NUL; | |
1093 else | |
1094 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1095 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1096 |
1097 if (pmodifiers != NULL) | |
1098 { | |
1099 /* Pass on the ALT key as a modifier, but only when not combined | |
1100 * with CTRL (which is ALTGR). */ | |
1101 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) | |
1102 *pmodifiers |= MOD_MASK_ALT; | |
1103 | |
1104 /* Pass on SHIFT only for special keys, because we don't know when | |
1105 * it's already included with the character. */ | |
1106 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) | |
1107 *pmodifiers |= MOD_MASK_SHIFT; | |
1108 | |
1109 /* Pass on CTRL only for non-special keys, because we don't know | |
1110 * when it's already included with the character. And not when | |
1111 * combined with ALT (which is ALTGR). */ | |
1112 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 | |
1113 && *pch >= 0x20 && *pch < 0x80) | |
1114 *pmodifiers |= MOD_MASK_CTRL; | |
1115 } | |
1116 } | |
1117 | |
1118 return (*pch != NUL); | |
1119 } | |
1120 | |
1121 #ifdef _MSC_VER | |
1122 # pragma optimize("", on) | |
1123 #endif | |
1124 | |
1125 #endif /* FEAT_GUI_W32 */ | |
1126 | |
1127 | |
1128 #ifdef FEAT_MOUSE | |
1129 | |
1130 /* | |
1131 * For the GUI the mouse handling is in gui_w32.c. | |
1132 */ | |
1133 # ifdef FEAT_GUI_W32 | |
1134 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
|
1135 mch_setmouse(int on UNUSED) |
7 | 1136 { |
1137 } | |
1138 # else | |
1139 static int g_fMouseAvail = FALSE; /* mouse present */ | |
1140 static int g_fMouseActive = FALSE; /* mouse enabled */ | |
1141 static int g_nMouseClick = -1; /* mouse status */ | |
1142 static int g_xMouse; /* mouse x coordinate */ | |
1143 static int g_yMouse; /* mouse y coordinate */ | |
1144 | |
1145 /* | |
1146 * Enable or disable mouse input | |
1147 */ | |
1148 void | |
26 | 1149 mch_setmouse(int on) |
7 | 1150 { |
1151 DWORD cmodein; | |
1152 | |
1153 if (!g_fMouseAvail) | |
1154 return; | |
1155 | |
1156 g_fMouseActive = on; | |
1157 GetConsoleMode(g_hConIn, &cmodein); | |
1158 | |
1159 if (g_fMouseActive) | |
1160 cmodein |= ENABLE_MOUSE_INPUT; | |
1161 else | |
1162 cmodein &= ~ENABLE_MOUSE_INPUT; | |
1163 | |
1164 SetConsoleMode(g_hConIn, cmodein); | |
1165 } | |
1166 | |
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
|
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 #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
|
1169 /* |
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 * 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
|
1171 */ |
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 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
|
1173 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
|
1174 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1175 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
|
1176 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1177 #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
|
1178 |
7 | 1179 /* |
1180 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1181 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1182 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1183 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1184 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1185 * and we return the mouse position in g_xMouse and g_yMouse. | |
1186 * | |
1187 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1188 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1189 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1190 * | |
1191 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1192 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1193 * | |
1194 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1195 * moves, even if it stays within the same character cell. We ignore | |
1196 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1197 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1198 * we're only interested in MOUSE_DRAG). | |
1199 * | |
1200 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1201 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1202 * In practice, it's almost impossible to click both at the same time, | |
1203 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1204 * in such cases, if the user is clicking quickly. | |
1205 */ | |
1206 static BOOL | |
1207 decode_mouse_event( | |
26 | 1208 MOUSE_EVENT_RECORD *pmer) |
7 | 1209 { |
1210 static int s_nOldButton = -1; | |
1211 static int s_nOldMouseClick = -1; | |
1212 static int s_xOldMouse = -1; | |
1213 static int s_yOldMouse = -1; | |
1214 static linenr_T s_old_topline = 0; | |
1215 #ifdef FEAT_DIFF | |
1216 static int s_old_topfill = 0; | |
1217 #endif | |
1218 static int s_cClicks = 1; | |
1219 static BOOL s_fReleased = TRUE; | |
1220 static DWORD s_dwLastClickTime = 0; | |
1221 static BOOL s_fNextIsMiddle = FALSE; | |
1222 | |
1223 static DWORD cButtons = 0; /* number of buttons supported */ | |
1224 | |
1225 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1226 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1227 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1228 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1229 | |
1230 int nButton; | |
1231 | |
1232 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1233 cButtons = 2; | |
1234 | |
1235 if (!g_fMouseAvail || !g_fMouseActive) | |
1236 { | |
1237 g_nMouseClick = -1; | |
1238 return FALSE; | |
1239 } | |
1240 | |
1241 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ | |
1242 if (g_fJustGotFocus) | |
1243 { | |
1244 g_fJustGotFocus = FALSE; | |
1245 return FALSE; | |
1246 } | |
1247 | |
1248 /* unprocessed mouse click? */ | |
1249 if (g_nMouseClick != -1) | |
1250 return TRUE; | |
1251 | |
1252 nButton = -1; | |
1253 g_xMouse = pmer->dwMousePosition.X; | |
1254 g_yMouse = pmer->dwMousePosition.Y; | |
1255 | |
1256 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1257 { | |
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
|
1258 /* Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these |
7 | 1259 * events even when the mouse moves only within a char cell.) */ |
1260 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) | |
1261 return FALSE; | |
1262 } | |
1263 | |
1264 /* If no buttons are pressed... */ | |
1265 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) | |
1266 { | |
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 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
|
1268 |
7 | 1269 /* If the last thing returned was MOUSE_RELEASE, ignore this */ |
1270 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
|
1271 { |
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 #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
|
1273 /* 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
|
1274 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
|
1275 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
|
1276 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
|
1277 #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
|
1278 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
|
1279 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1280 |
7 | 1281 s_fReleased = TRUE; |
1282 } | |
1283 else /* one or more buttons pressed */ | |
1284 { | |
1285 /* on a 2-button mouse, hold down left and right buttons | |
1286 * simultaneously to get MIDDLE. */ | |
1287 | |
1288 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1289 { | |
1290 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1291 | |
1292 /* if either left or right button only is pressed, see if the | |
4352 | 1293 * next mouse event has both of them pressed */ |
7 | 1294 if (dwLR == LEFT || dwLR == RIGHT) |
1295 { | |
1296 for (;;) | |
1297 { | |
1298 /* wait a short time for next input event */ | |
1299 if (WaitForSingleObject(g_hConIn, p_mouset / 3) | |
1300 != WAIT_OBJECT_0) | |
1301 break; | |
1302 else | |
1303 { | |
1304 DWORD cRecords = 0; | |
1305 INPUT_RECORD ir; | |
1306 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1307 | |
5580 | 1308 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1309 |
1310 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1311 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1312 break; | |
1313 else | |
1314 { | |
1315 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1316 { | |
5580 | 1317 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1318 |
1319 return decode_mouse_event(pmer2); | |
1320 } | |
1321 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1322 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1323 { | |
1324 /* throw away spurious mouse move */ | |
5580 | 1325 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1326 |
1327 /* are there any more mouse events in queue? */ | |
5580 | 1328 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1329 |
1330 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1331 break; | |
1332 } | |
1333 else | |
1334 break; | |
1335 } | |
1336 } | |
1337 } | |
1338 } | |
1339 } | |
1340 | |
1341 if (s_fNextIsMiddle) | |
1342 { | |
1343 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1344 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1345 s_fNextIsMiddle = FALSE; | |
1346 } | |
1347 else if (cButtons == 2 && | |
1348 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1349 { | |
1350 nButton = MOUSE_MIDDLE; | |
1351 | |
1352 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1353 { | |
1354 s_fNextIsMiddle = TRUE; | |
1355 nButton = MOUSE_RELEASE; | |
1356 } | |
1357 } | |
1358 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1359 nButton = MOUSE_LEFT; | |
1360 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1361 nButton = MOUSE_MIDDLE; | |
1362 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1363 nButton = MOUSE_RIGHT; | |
1364 | |
1365 if (! s_fReleased && ! s_fNextIsMiddle | |
1366 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1367 return FALSE; | |
1368 | |
1369 s_fReleased = s_fNextIsMiddle; | |
1370 } | |
1371 | |
1372 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1373 { | |
1374 /* button pressed or released, without mouse moving */ | |
1375 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1376 { | |
1377 DWORD dwCurrentTime = GetTickCount(); | |
1378 | |
1379 if (s_xOldMouse != g_xMouse | |
1380 || s_yOldMouse != g_yMouse | |
1381 || s_nOldButton != nButton | |
1382 || s_old_topline != curwin->w_topline | |
1383 #ifdef FEAT_DIFF | |
1384 || s_old_topfill != curwin->w_topfill | |
1385 #endif | |
1386 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) | |
1387 { | |
1388 s_cClicks = 1; | |
1389 } | |
1390 else if (++s_cClicks > 4) | |
1391 { | |
1392 s_cClicks = 1; | |
1393 } | |
1394 | |
1395 s_dwLastClickTime = dwCurrentTime; | |
1396 } | |
1397 } | |
1398 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1399 { | |
1400 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1401 nButton = MOUSE_DRAG; | |
1402 | |
1403 s_cClicks = 1; | |
1404 } | |
1405 | |
1406 if (nButton == -1) | |
1407 return FALSE; | |
1408 | |
1409 if (nButton != MOUSE_RELEASE) | |
1410 s_nOldButton = nButton; | |
1411 | |
1412 g_nMouseClick = nButton; | |
1413 | |
1414 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1415 g_nMouseClick |= MOUSE_SHIFT; | |
1416 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1417 g_nMouseClick |= MOUSE_CTRL; | |
1418 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1419 g_nMouseClick |= MOUSE_ALT; | |
1420 | |
1421 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1422 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1423 | |
1424 /* only pass on interesting (i.e., different) mouse events */ | |
1425 if (s_xOldMouse == g_xMouse | |
1426 && s_yOldMouse == g_yMouse | |
1427 && s_nOldMouseClick == g_nMouseClick) | |
1428 { | |
1429 g_nMouseClick = -1; | |
1430 return FALSE; | |
1431 } | |
1432 | |
1433 s_xOldMouse = g_xMouse; | |
1434 s_yOldMouse = g_yMouse; | |
1435 s_old_topline = curwin->w_topline; | |
1436 #ifdef FEAT_DIFF | |
1437 s_old_topfill = curwin->w_topfill; | |
1438 #endif | |
1439 s_nOldMouseClick = g_nMouseClick; | |
1440 | |
1441 return TRUE; | |
1442 } | |
1443 | |
1444 # endif /* FEAT_GUI_W32 */ | |
1445 #endif /* FEAT_MOUSE */ | |
1446 | |
1447 | |
1448 #ifdef MCH_CURSOR_SHAPE | |
1449 /* | |
1450 * Set the shape of the cursor. | |
1451 * 'thickness' can be from 1 (thin) to 99 (block) | |
1452 */ | |
1453 static void | |
1454 mch_set_cursor_shape(int thickness) | |
1455 { | |
1456 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1457 ConsoleCursorInfo.dwSize = thickness; | |
1458 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1459 | |
1460 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1461 if (s_cursor_visible) | |
1462 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1463 } | |
1464 | |
1465 void | |
1466 mch_update_cursor(void) | |
1467 { | |
1468 int idx; | |
1469 int thickness; | |
1470 | |
1471 /* | |
1472 * How the cursor is drawn depends on the current mode. | |
1473 */ | |
1474 idx = get_shape_idx(FALSE); | |
1475 | |
1476 if (shape_table[idx].shape == SHAPE_BLOCK) | |
1477 thickness = 99; /* 100 doesn't work on W95 */ | |
1478 else | |
1479 thickness = shape_table[idx].percentage; | |
1480 mch_set_cursor_shape(thickness); | |
1481 } | |
1482 #endif | |
1483 | |
1484 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1485 /* | |
1486 * Handle FOCUS_EVENT. | |
1487 */ | |
1488 static void | |
1489 handle_focus_event(INPUT_RECORD ir) | |
1490 { | |
1491 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1492 ui_focus_change((int)g_fJustGotFocus); | |
1493 } | |
1494 | |
1495 /* | |
1496 * Wait until console input from keyboard or mouse is available, | |
1497 * 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
|
1498 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1499 * Return TRUE if something is available FALSE if not. |
1500 */ | |
1501 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1502 WaitForChar(long msec, int ignore_input) |
7 | 1503 { |
1504 DWORD dwNow = 0, dwEndTime = 0; | |
1505 INPUT_RECORD ir; | |
1506 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1507 WCHAR ch, ch2; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1508 #ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1509 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
|
1510 #endif |
7 | 1511 |
1512 if (msec > 0) | |
1513 /* Wait until the specified time has elapsed. */ | |
1514 dwEndTime = GetTickCount() + msec; | |
1515 else if (msec < 0) | |
1516 /* Wait forever. */ | |
1517 dwEndTime = INFINITE; | |
1518 | |
1519 /* We need to loop until the end of the time period, because | |
1520 * we might get multiple unusable mouse events in that time. | |
1521 */ | |
1522 for (;;) | |
1523 { | |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1524 #ifdef MESSAGE_QUEUE |
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1525 parse_queued_messages(); |
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1526 #endif |
14 | 1527 #ifdef FEAT_MZSCHEME |
1528 mzvim_check_threads(); | |
1529 #endif | |
7 | 1530 #ifdef FEAT_CLIENTSERVER |
1531 serverProcessPendingMessages(); | |
1532 #endif | |
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 { | |
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
|
1918 if (c == K_NUL && (ch2 & 0xff00) != 0) |
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 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1920 /* fAnsiKey with modifier keys */ |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1921 typeahead[typeaheadlen + n] = (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
|
1922 n++; |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1923 } |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1924 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
|
1925 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1926 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
|
1927 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
|
1928 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
|
1929 } |
6047 | 1930 } |
1931 | |
7 | 1932 /* Use the ALT key to set the 8th bit of the character |
1933 * when it's one byte, the 8th bit isn't set yet and not | |
1934 * using a double-byte encoding (would become a lead | |
1935 * byte). */ | |
1936 if ((modifiers & MOD_MASK_ALT) | |
1937 && n == 1 | |
1938 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1939 #ifdef FEAT_MBYTE | |
1940 && !enc_dbcs | |
1941 #endif | |
1942 ) | |
1943 { | |
1443 | 1944 #ifdef FEAT_MBYTE |
1945 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, | |
1946 typeahead + typeaheadlen); | |
1947 #else | |
7 | 1948 typeahead[typeaheadlen] |= 0x80; |
1443 | 1949 #endif |
7 | 1950 modifiers &= ~MOD_MASK_ALT; |
1951 } | |
1952 | |
1953 if (modifiers != 0) | |
1954 { | |
1955 /* Prepend modifiers to the character. */ | |
1956 mch_memmove(typeahead + typeaheadlen + 3, | |
1957 typeahead + typeaheadlen, n); | |
1958 typeahead[typeaheadlen++] = K_SPECIAL; | |
1959 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
1960 typeahead[typeaheadlen++] = modifiers; | |
1961 } | |
1962 | |
1963 typeaheadlen += n; | |
1964 | |
1965 #ifdef MCH_WRITE_DUMP | |
1966 if (fdDump) | |
1967 fputc(c, fdDump); | |
1968 #endif | |
1969 } | |
1970 } | |
1971 } | |
1972 | |
1973 #ifdef MCH_WRITE_DUMP | |
1974 if (fdDump) | |
1975 { | |
1976 fputs("]\n", fdDump); | |
1977 fflush(fdDump); | |
1978 } | |
1979 #endif | |
1980 | |
1981 theend: | |
1982 /* Move typeahead to "buf", as much as fits. */ | |
1983 len = 0; | |
1984 while (len < maxlen && typeaheadlen > 0) | |
1985 { | |
1986 buf[len++] = typeahead[0]; | |
1987 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
1988 } | |
1989 return len; | |
1990 | |
1991 #else /* FEAT_GUI_W32 */ | |
1992 return 0; | |
1993 #endif /* FEAT_GUI_W32 */ | |
1994 } | |
1995 | |
3927 | 1996 #ifndef PROTO |
1997 # ifndef __MINGW32__ | |
1998 # include <shellapi.h> /* required for FindExecutable() */ | |
1999 # endif | |
7 | 2000 #endif |
2001 | |
9 | 2002 /* |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2003 * If "use_path" is 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
|
2004 * 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
|
2005 * 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
|
2006 * the allocated memory. |
10 | 2007 * TODO: Should somehow check if it's really executable. |
9 | 2008 */ |
7 | 2009 static int |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2010 executable_exists(char *name, char_u **path, int use_path) |
7 | 2011 { |
9 | 2012 char *dum; |
2013 char fname[_MAX_PATH]; | |
6185 | 2014 char *curpath, *newpath; |
2015 long n; | |
9 | 2016 |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2017 if (!use_path) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2018 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2019 if (mch_getperm((char_u *)name) != -1 && !mch_isdir((char_u *)name)) |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2020 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2021 if (path != NULL) |
11060
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2022 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2023 if (mch_isFullName((char_u *)name)) |
11060
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2024 *path = vim_strsave((char_u *)name); |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2025 else |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2026 *path = FullName_save((char_u *)name, FALSE); |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2027 } |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2028 return TRUE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2029 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2030 return FALSE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2031 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2032 |
9 | 2033 #ifdef FEAT_MBYTE |
2034 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
7 | 2035 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2036 WCHAR *p = enc_to_utf16((char_u *)name, NULL); |
9 | 2037 WCHAR fnamew[_MAX_PATH]; |
2038 WCHAR *dumw; | |
6185 | 2039 WCHAR *wcurpath, *wnewpath; |
9 | 2040 |
2041 if (p != NULL) | |
2042 { | |
6185 | 2043 wcurpath = _wgetenv(L"PATH"); |
2044 wnewpath = (WCHAR*)alloc((unsigned)(wcslen(wcurpath) + 3) | |
2045 * sizeof(WCHAR)); | |
2046 if (wnewpath == NULL) | |
2047 return FALSE; | |
2048 wcscpy(wnewpath, L".;"); | |
2049 wcscat(wnewpath, wcurpath); | |
2050 n = (long)SearchPathW(wnewpath, p, NULL, _MAX_PATH, fnamew, &dumw); | |
2051 vim_free(wnewpath); | |
9 | 2052 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2053 if (n == 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2054 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2055 if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2056 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2057 if (path != NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2058 *path = utf16_to_enc(fnamew, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2059 return TRUE; |
9 | 2060 } |
7 | 2061 } |
9 | 2062 #endif |
6185 | 2063 |
2064 curpath = getenv("PATH"); | |
2065 newpath = (char*)alloc((unsigned)(STRLEN(curpath) + 3)); | |
2066 if (newpath == NULL) | |
2067 return FALSE; | |
2068 STRCPY(newpath, ".;"); | |
2069 STRCAT(newpath, curpath); | |
2070 n = (long)SearchPath(newpath, name, NULL, _MAX_PATH, fname, &dum); | |
2071 vim_free(newpath); | |
2072 if (n == 0) | |
9 | 2073 return FALSE; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2074 if (mch_isdir((char_u *)fname)) |
9 | 2075 return FALSE; |
5782 | 2076 if (path != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2077 *path = vim_strsave((char_u *)fname); |
9 | 2078 return TRUE; |
7 | 2079 } |
2080 | |
2584 | 2081 #if ((defined(__MINGW32__) || defined (__CYGWIN32__)) && \ |
2935 | 2082 __MSVCRT_VERSION__ >= 0x800) || (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 2083 /* |
2084 * Bad parameter handler. | |
2085 * | |
2086 * Certain MS CRT functions will intentionally crash when passed invalid | |
2087 * parameters to highlight possible security holes. Setting this function as | |
2088 * the bad parameter handler will prevent the crash. | |
2089 * | |
2090 * In debug builds the parameters contain CRT information that might help track | |
2091 * down the source of a problem, but in non-debug builds the arguments are all | |
2092 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
2093 * worth allowing these to make debugging of issues easier. | |
2094 */ | |
2095 static void | |
2096 bad_param_handler(const wchar_t *expression, | |
2097 const wchar_t *function, | |
2098 const wchar_t *file, | |
2099 unsigned int line, | |
2100 uintptr_t pReserved) | |
2101 { | |
2102 } | |
2103 | |
2104 # define SET_INVALID_PARAM_HANDLER \ | |
2105 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2106 #else | |
2107 # define SET_INVALID_PARAM_HANDLER | |
2108 #endif | |
2109 | |
7 | 2110 #ifdef FEAT_GUI_W32 |
2111 | |
2112 /* | |
2113 * GUI version of mch_init(). | |
2114 */ | |
2115 void | |
26 | 2116 mch_init(void) |
7 | 2117 { |
2118 #ifndef __MINGW32__ | |
2119 extern int _fmode; | |
2120 #endif | |
2121 | |
2584 | 2122 /* Silently handle invalid parameters to CRT functions */ |
2123 SET_INVALID_PARAM_HANDLER; | |
2124 | |
7 | 2125 /* Let critical errors result in a failure, not in a dialog box. Required |
2126 * for the timestamp test to work on removed floppies. */ | |
2127 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2128 | |
2129 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2130 | |
2131 /* Specify window size. Is there a place to get the default from? */ | |
2132 Rows = 25; | |
2133 Columns = 80; | |
2134 | |
2135 /* Look for 'vimrun' */ | |
2136 { | |
2137 char_u vimrun_location[_MAX_PATH + 4]; | |
2138 | |
2139 /* First try in same directory as gvim.exe */ | |
2140 STRCPY(vimrun_location, exe_name); | |
2141 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2142 if (mch_getperm(vimrun_location) >= 0) | |
2143 { | |
2144 if (*skiptowhite(vimrun_location) != NUL) | |
2145 { | |
2146 /* Enclose path with white space in double quotes. */ | |
2147 mch_memmove(vimrun_location + 1, vimrun_location, | |
2148 STRLEN(vimrun_location) + 1); | |
2149 *vimrun_location = '"'; | |
2150 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2151 } | |
2152 else | |
2153 STRCPY(gettail(vimrun_location), "vimrun "); | |
2154 | |
2155 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2156 s_dont_use_vimrun = FALSE; | |
2157 } | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2158 else if (executable_exists("vimrun.exe", NULL, TRUE)) |
7 | 2159 s_dont_use_vimrun = FALSE; |
2160 | |
2161 /* Don't give the warning for a missing vimrun.exe right now, but only | |
2162 * when vimrun was supposed to be used. Don't bother people that do | |
2163 * not need vimrun.exe. */ | |
2164 if (s_dont_use_vimrun) | |
2165 need_vimrun_warning = TRUE; | |
2166 } | |
2167 | |
2168 /* | |
2169 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2170 * Otherwise the default "findstr /n" is used. | |
2171 */ | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2172 if (!executable_exists("findstr.exe", NULL, TRUE)) |
7 | 2173 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
2174 | |
2175 #ifdef FEAT_CLIPBOARD | |
4168 | 2176 win_clip_init(); |
7 | 2177 #endif |
2178 } | |
2179 | |
2180 | |
2181 #else /* FEAT_GUI_W32 */ | |
2182 | |
2183 #define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) | |
2184 #define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) | |
2185 | |
2186 /* | |
2187 * ClearConsoleBuffer() | |
2188 * Description: | |
2189 * Clears the entire contents of the console screen buffer, using the | |
2190 * specified attribute. | |
2191 * Returns: | |
2192 * TRUE on success | |
2193 */ | |
2194 static BOOL | |
2195 ClearConsoleBuffer(WORD wAttribute) | |
2196 { | |
2197 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2198 COORD coord; | |
2199 DWORD NumCells, dummy; | |
2200 | |
2201 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2202 return FALSE; | |
2203 | |
2204 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2205 coord.X = 0; | |
2206 coord.Y = 0; | |
2207 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2208 coord, &dummy)) | |
2209 { | |
2210 return FALSE; | |
2211 } | |
2212 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2213 coord, &dummy)) | |
2214 { | |
2215 return FALSE; | |
2216 } | |
2217 | |
2218 return TRUE; | |
2219 } | |
2220 | |
2221 /* | |
2222 * FitConsoleWindow() | |
2223 * Description: | |
2224 * Checks if the console window will fit within given buffer dimensions. | |
2225 * Also, if requested, will shrink the window to fit. | |
2226 * Returns: | |
2227 * TRUE on success | |
2228 */ | |
2229 static BOOL | |
2230 FitConsoleWindow( | |
2231 COORD dwBufferSize, | |
2232 BOOL WantAdjust) | |
2233 { | |
2234 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2235 COORD dwWindowSize; | |
2236 BOOL NeedAdjust = FALSE; | |
2237 | |
2238 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2239 { | |
2240 /* | |
2241 * A buffer resize will fail if the current console window does | |
2242 * not lie completely within that buffer. To avoid this, we might | |
2243 * have to move and possibly shrink the window. | |
2244 */ | |
2245 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2246 { | |
2247 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2248 if (dwWindowSize.X > dwBufferSize.X) | |
2249 dwWindowSize.X = dwBufferSize.X; | |
2250 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2251 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2252 NeedAdjust = TRUE; | |
2253 } | |
2254 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2255 { | |
2256 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2257 if (dwWindowSize.Y > dwBufferSize.Y) | |
2258 dwWindowSize.Y = dwBufferSize.Y; | |
2259 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2260 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2261 NeedAdjust = TRUE; | |
2262 } | |
2263 if (NeedAdjust && WantAdjust) | |
2264 { | |
2265 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2266 return FALSE; | |
2267 } | |
2268 return TRUE; | |
2269 } | |
2270 | |
2271 return FALSE; | |
2272 } | |
2273 | |
2274 typedef struct ConsoleBufferStruct | |
2275 { | |
26 | 2276 BOOL IsValid; |
2277 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2278 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2279 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
|
2280 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
|
2281 int NumRegions; |
7 | 2282 } ConsoleBuffer; |
2283 | |
2284 /* | |
2285 * SaveConsoleBuffer() | |
2286 * Description: | |
2287 * Saves important information about the console buffer, including the | |
2288 * actual buffer contents. The saved information is suitable for later | |
2289 * restoration by RestoreConsoleBuffer(). | |
2290 * Returns: | |
2291 * TRUE if all information was saved; FALSE otherwise | |
2292 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2293 */ | |
2294 static BOOL | |
2295 SaveConsoleBuffer( | |
2296 ConsoleBuffer *cb) | |
2297 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2298 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2299 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2300 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2301 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
|
2302 int i, numregions; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2303 |
7 | 2304 if (cb == NULL) |
2305 return FALSE; | |
2306 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2307 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2308 { |
2309 cb->IsValid = FALSE; | |
2310 return FALSE; | |
2311 } | |
2312 cb->IsValid = TRUE; | |
2313 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2314 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2315 * 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
|
2316 * 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
|
2317 * 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
|
2318 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2319 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2320 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
|
2321 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
|
2322 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2323 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
|
2324 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
|
2325 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
|
2326 vim_free(cb->Buffer); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2327 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
|
2328 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2329 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2330 } |
7 | 2331 |
2332 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2333 * 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
|
2334 * 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
|
2335 * 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
|
2336 * 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
|
2337 * 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
|
2338 * 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
|
2339 * height of each chunk will be (12000 / width). |
7 | 2340 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2341 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2342 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2343 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
|
2344 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
|
2345 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2346 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
|
2347 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
|
2348 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2349 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
|
2350 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
|
2351 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
|
2352 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
|
2353 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2354 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
|
2355 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
|
2356 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2357 } |
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 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr) |
7 | 2360 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2361 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2362 * 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
|
2363 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2364 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2365 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2366 * 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
|
2367 * 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
|
2368 * 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
|
2369 * 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
|
2370 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2371 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2372 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
|
2373 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
|
2374 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2375 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2376 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2377 &ReadRegion)) /* region to save */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2378 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2379 VIM_CLEAR(cb->Buffer); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2380 VIM_CLEAR(cb->Regions); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2381 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2382 } |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2383 cb->Regions[i] = ReadRegion; |
7 | 2384 } |
2385 | |
2386 return TRUE; | |
2387 } | |
2388 | |
2389 /* | |
2390 * RestoreConsoleBuffer() | |
2391 * Description: | |
2392 * Restores important information about the console buffer, including the | |
2393 * actual buffer contents, if desired. The information to restore is in | |
2394 * the same format used by SaveConsoleBuffer(). | |
2395 * Returns: | |
2396 * TRUE on success | |
2397 */ | |
2398 static BOOL | |
2399 RestoreConsoleBuffer( | |
26 | 2400 ConsoleBuffer *cb, |
2401 BOOL RestoreScreen) | |
7 | 2402 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2403 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2404 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
|
2405 int i; |
7 | 2406 |
2407 if (cb == NULL || !cb->IsValid) | |
2408 return FALSE; | |
2409 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2410 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2411 * 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
|
2412 * 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
|
2413 * 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
|
2414 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2415 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2416 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2417 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2418 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2419 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
|
2420 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2421 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
|
2422 return FALSE; |
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 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2425 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2426 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2427 * 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
|
2428 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2429 return TRUE; |
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 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2432 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
|
2433 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2434 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
|
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 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2438 * Restore the screen buffer contents. |
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 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2441 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2442 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
|
2443 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2444 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
|
2445 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
|
2446 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
|
2447 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
|
2448 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
|
2449 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
|
2450 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
|
2451 &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
|
2452 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2453 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
|
2454 } |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2455 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2456 } |
7 | 2457 |
2458 return TRUE; | |
2459 } | |
2460 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2461 #define FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2462 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2463 static ConsoleBuffer g_cbOrig = { 0 }; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2464 #endif |
7 | 2465 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2466 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2467 | |
2468 #ifdef FEAT_TITLE | |
2469 #ifdef __BORLANDC__ | |
2470 typedef HWND (__stdcall *GETCONSOLEWINDOWPROC)(VOID); | |
2471 #else | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2472 typedef HWND (WINAPI *GETCONSOLEWINDOWPROC)(VOID); |
7 | 2473 #endif |
2474 char g_szOrigTitle[256] = { 0 }; | |
2475 HWND g_hWnd = NULL; /* also used in os_mswin.c */ | |
2476 static HICON g_hOrigIconSmall = NULL; | |
2477 static HICON g_hOrigIcon = NULL; | |
2478 static HICON g_hVimIcon = NULL; | |
2479 static BOOL g_fCanChangeIcon = FALSE; | |
2480 | |
2481 /* ICON* are not defined in VC++ 4.0 */ | |
2482 #ifndef ICON_SMALL | |
2483 #define ICON_SMALL 0 | |
2484 #endif | |
2485 #ifndef ICON_BIG | |
2486 #define ICON_BIG 1 | |
2487 #endif | |
2488 /* | |
2489 * GetConsoleIcon() | |
2490 * Description: | |
2491 * Attempts to retrieve the small icon and/or the big icon currently in | |
2492 * use by a given window. | |
2493 * Returns: | |
2494 * TRUE on success | |
2495 */ | |
2496 static BOOL | |
2497 GetConsoleIcon( | |
26 | 2498 HWND hWnd, |
2499 HICON *phIconSmall, | |
2500 HICON *phIcon) | |
7 | 2501 { |
2502 if (hWnd == NULL) | |
2503 return FALSE; | |
2504 | |
2505 if (phIconSmall != NULL) | |
26 | 2506 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2507 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2508 if (phIcon != NULL) |
26 | 2509 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2510 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2511 return TRUE; |
2512 } | |
2513 | |
2514 /* | |
2515 * SetConsoleIcon() | |
2516 * Description: | |
2517 * Attempts to change the small icon and/or the big icon currently in | |
2518 * use by a given window. | |
2519 * Returns: | |
2520 * TRUE on success | |
2521 */ | |
2522 static BOOL | |
2523 SetConsoleIcon( | |
26 | 2524 HWND hWnd, |
2525 HICON hIconSmall, | |
2526 HICON hIcon) | |
7 | 2527 { |
2528 if (hWnd == NULL) | |
2529 return FALSE; | |
2530 | |
2531 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2532 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2533 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2534 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2535 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2536 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2537 return TRUE; |
2538 } | |
2539 | |
2540 /* | |
2541 * SaveConsoleTitleAndIcon() | |
2542 * Description: | |
2543 * Saves the current console window title in g_szOrigTitle, for later | |
2544 * restoration. Also, attempts to obtain a handle to the console window, | |
2545 * and use it to save the small and big icons currently in use by the | |
2546 * console window. This is not always possible on some versions of Windows; | |
2547 * nor is it possible when running Vim remotely using Telnet (since the | |
2548 * console window the user sees is owned by a remote process). | |
2549 */ | |
2550 static void | |
2551 SaveConsoleTitleAndIcon(void) | |
2552 { | |
2553 /* Save the original title. */ | |
2554 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) | |
2555 return; | |
2556 | |
2557 /* | |
2558 * Obtain a handle to the console window using GetConsoleWindow() from | |
2559 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2560 * This function only exists on NT-based Windows, starting with Windows | |
2561 * 2000. On older operating systems, we can't change the window icon | |
2562 * anyway. | |
2563 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2564 g_hWnd = GetConsoleWindow(); |
7 | 2565 if (g_hWnd == NULL) |
2566 return; | |
2567 | |
2568 /* Save the original console window icon. */ | |
2569 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); | |
2570 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2571 return; | |
2572 | |
2573 /* Extract the first icon contained in the Vim executable. */ | |
6249 | 2574 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
|
2575 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2576 if (g_hVimIcon != NULL) |
2577 g_fCanChangeIcon = TRUE; | |
2578 } | |
2579 #endif | |
2580 | |
2581 static int g_fWindInitCalled = FALSE; | |
2582 static int g_fTermcapMode = FALSE; | |
2583 static CONSOLE_CURSOR_INFO g_cci; | |
2584 static DWORD g_cmodein = 0; | |
2585 static DWORD g_cmodeout = 0; | |
2586 | |
2587 /* | |
2588 * non-GUI version of mch_init(). | |
2589 */ | |
2590 void | |
26 | 2591 mch_init(void) |
7 | 2592 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2593 #ifndef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2594 CONSOLE_SCREEN_BUFFER_INFO csbi; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2595 #endif |
7 | 2596 #ifndef __MINGW32__ |
2597 extern int _fmode; | |
2598 #endif | |
2599 | |
2584 | 2600 /* Silently handle invalid parameters to CRT functions */ |
2601 SET_INVALID_PARAM_HANDLER; | |
2602 | |
7 | 2603 /* Let critical errors result in a failure, not in a dialog box. Required |
2604 * for the timestamp test to work on removed floppies. */ | |
2605 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2606 | |
2607 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2608 out_flush(); | |
2609 | |
2610 /* Obtain handles for the standard Console I/O devices */ | |
2611 if (read_cmd_fd == 0) | |
2612 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2613 else | |
2614 create_conin(); | |
2615 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
|
2616 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2617 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2618 /* 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
|
2619 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2620 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
|
2621 #else |
7 | 2622 /* Get current text attributes */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2623 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2624 g_attrCurrent = g_attrDefault = csbi.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2625 #endif |
7 | 2626 if (cterm_normal_fg_color == 0) |
2627 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2628 if (cterm_normal_bg_color == 0) | |
2629 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2630 | |
2631 /* set termcap codes to current text attributes */ | |
2632 update_tcap(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
|
2633 swap_tcap(); |
7 | 2634 |
2635 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2636 GetConsoleMode(g_hConIn, &g_cmodein); | |
2637 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2638 | |
2639 #ifdef FEAT_TITLE | |
2640 SaveConsoleTitleAndIcon(); | |
2641 /* | |
2642 * Set both the small and big icons of the console window to Vim's icon. | |
2643 * Note that Vim presently only has one size of icon (32x32), but it | |
2644 * automatically gets scaled down to 16x16 when setting the small icon. | |
2645 */ | |
2646 if (g_fCanChangeIcon) | |
2647 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2648 #endif | |
2649 | |
2650 ui_get_shellsize(); | |
2651 | |
2652 #ifdef MCH_WRITE_DUMP | |
2653 fdDump = fopen("dump", "wt"); | |
2654 | |
2655 if (fdDump) | |
2656 { | |
2657 time_t t; | |
2658 | |
2659 time(&t); | |
2660 fputs(ctime(&t), fdDump); | |
2661 fflush(fdDump); | |
2662 } | |
2663 #endif | |
2664 | |
2665 g_fWindInitCalled = TRUE; | |
2666 | |
2667 #ifdef FEAT_MOUSE | |
2668 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2669 #endif | |
2670 | |
2671 #ifdef FEAT_CLIPBOARD | |
4168 | 2672 win_clip_init(); |
7 | 2673 #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
|
2674 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2675 vtp_init(); |
7 | 2676 } |
2677 | |
2678 /* | |
2679 * non-GUI version of mch_exit(). | |
2680 * Shut down and exit with status `r' | |
2681 * Careful: mch_exit() may be called before mch_init()! | |
2682 */ | |
2683 void | |
2684 mch_exit(int r) | |
2685 { | |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2686 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
|
2687 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2688 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
|
2689 |
7 | 2690 stoptermcap(); |
2691 if (g_fWindInitCalled) | |
2692 settmode(TMODE_COOK); | |
2693 | |
2694 ml_close_all(TRUE); /* remove all memfiles */ | |
2695 | |
2696 if (g_fWindInitCalled) | |
2697 { | |
2698 #ifdef FEAT_TITLE | |
2699 mch_restore_title(3); | |
2700 /* | |
2701 * Restore both the small and big icons of the console window to | |
2702 * what they were at startup. Don't do this when the window is | |
2703 * closed, Vim would hang here. | |
2704 */ | |
2705 if (g_fCanChangeIcon && !g_fForceExit) | |
2706 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
2707 #endif | |
2708 | |
2709 #ifdef MCH_WRITE_DUMP | |
2710 if (fdDump) | |
2711 { | |
2712 time_t t; | |
2713 | |
2714 time(&t); | |
2715 fputs(ctime(&t), fdDump); | |
2716 fclose(fdDump); | |
2717 } | |
2718 fdDump = NULL; | |
2719 #endif | |
2720 } | |
2721 | |
2722 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2723 SetConsoleMode(g_hConIn, g_cmodein); | |
2724 SetConsoleMode(g_hConOut, g_cmodeout); | |
2725 | |
2726 #ifdef DYNAMIC_GETTEXT | |
2727 dyn_libintl_end(); | |
2728 #endif | |
2729 | |
2730 exit(r); | |
2731 } | |
2732 #endif /* !FEAT_GUI_W32 */ | |
2733 | |
2734 /* | |
2735 * Do we have an interactive window? | |
2736 */ | |
2737 int | |
2738 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
|
2739 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
|
2740 char **argv UNUSED) |
7 | 2741 { |
2742 get_exe_name(); | |
2743 | |
2744 #ifdef FEAT_GUI_W32 | |
2745 return OK; /* GUI always has a tty */ | |
2746 #else | |
2747 if (isatty(1)) | |
2748 return OK; | |
2749 return FAIL; | |
2750 #endif | |
2751 } | |
2752 | |
2753 | |
5326 | 2754 #ifdef FEAT_MBYTE |
2755 /* | |
2756 * fname_casew(): Wide version of fname_case(). Set the case of the file name, | |
2757 * if it already exists. When "len" is > 0, also expand short to long | |
2758 * filenames. | |
2759 * Return FAIL if wide functions are not available, OK otherwise. | |
2760 * NOTE: much of this is identical to fname_case(), keep in sync! | |
2761 */ | |
2762 static int | |
2763 fname_casew( | |
2764 WCHAR *name, | |
2765 int len) | |
2766 { | |
2767 WCHAR szTrueName[_MAX_PATH + 2]; | |
2768 WCHAR szTrueNameTemp[_MAX_PATH + 2]; | |
2769 WCHAR *ptrue, *ptruePrev; | |
2770 WCHAR *porig, *porigPrev; | |
2771 int flen; | |
2772 WIN32_FIND_DATAW fb; | |
5529 | 2773 HANDLE hFind = INVALID_HANDLE_VALUE; |
5326 | 2774 int c; |
2775 int slen; | |
2776 | |
2777 flen = (int)wcslen(name); | |
2778 if (flen > _MAX_PATH) | |
2779 return OK; | |
2780 | |
2781 /* slash_adjust(name) not needed, already adjusted by fname_case(). */ | |
2782 | |
2783 /* Build the new name in szTrueName[] one component at a time. */ | |
2784 porig = name; | |
2785 ptrue = szTrueName; | |
2786 | |
2787 if (iswalpha(porig[0]) && porig[1] == L':') | |
2788 { | |
2789 /* copy leading drive letter */ | |
2790 *ptrue++ = *porig++; | |
2791 *ptrue++ = *porig++; | |
2792 } | |
5529 | 2793 *ptrue = NUL; /* in case nothing follows */ |
5326 | 2794 |
2795 while (*porig != NUL) | |
2796 { | |
2797 /* copy \ characters */ | |
2798 while (*porig == psepc) | |
2799 *ptrue++ = *porig++; | |
2800 | |
2801 ptruePrev = ptrue; | |
2802 porigPrev = porig; | |
2803 while (*porig != NUL && *porig != psepc) | |
2804 { | |
2805 *ptrue++ = *porig++; | |
2806 } | |
2807 *ptrue = NUL; | |
2808 | |
2809 /* To avoid a slow failure append "\*" when searching a directory, | |
2810 * server or network share. */ | |
2811 wcscpy(szTrueNameTemp, szTrueName); | |
2812 slen = (int)wcslen(szTrueNameTemp); | |
2813 if (*porig == psepc && slen + 2 < _MAX_PATH) | |
2814 wcscpy(szTrueNameTemp + slen, L"\\*"); | |
2815 | |
2816 /* Skip "", "." and "..". */ | |
2817 if (ptrue > ptruePrev | |
2818 && (ptruePrev[0] != L'.' | |
2819 || (ptruePrev[1] != NUL | |
2820 && (ptruePrev[1] != L'.' || ptruePrev[2] != NUL))) | |
2821 && (hFind = FindFirstFileW(szTrueNameTemp, &fb)) | |
2822 != INVALID_HANDLE_VALUE) | |
2823 { | |
2824 c = *porig; | |
2825 *porig = NUL; | |
2826 | |
2827 /* Only use the match when it's the same name (ignoring case) or | |
2828 * expansion is allowed and there is a match with the short name | |
2829 * and there is enough room. */ | |
2830 if (_wcsicoll(porigPrev, fb.cFileName) == 0 | |
2831 || (len > 0 | |
2832 && (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0 | |
2833 && (int)(ptruePrev - szTrueName) | |
2834 + (int)wcslen(fb.cFileName) < len))) | |
2835 { | |
2836 wcscpy(ptruePrev, fb.cFileName); | |
2837 | |
2838 /* Look for exact match and prefer it if found. Must be a | |
2839 * long name, otherwise there would be only one match. */ | |
2840 while (FindNextFileW(hFind, &fb)) | |
2841 { | |
2842 if (*fb.cAlternateFileName != NUL | |
2843 && (wcscoll(porigPrev, fb.cFileName) == 0 | |
2844 || (len > 0 | |
2845 && (_wcsicoll(porigPrev, | |
2846 fb.cAlternateFileName) == 0 | |
2847 && (int)(ptruePrev - szTrueName) | |
2848 + (int)wcslen(fb.cFileName) < len)))) | |
2849 { | |
2850 wcscpy(ptruePrev, fb.cFileName); | |
2851 break; | |
2852 } | |
2853 } | |
2854 } | |
2855 FindClose(hFind); | |
2856 *porig = c; | |
2857 ptrue = ptruePrev + wcslen(ptruePrev); | |
2858 } | |
2859 } | |
2860 | |
2861 wcscpy(name, szTrueName); | |
2862 return OK; | |
2863 } | |
2864 #endif | |
2865 | |
7 | 2866 /* |
2867 * fname_case(): Set the case of the file name, if it already exists. | |
2868 * When "len" is > 0, also expand short to long filenames. | |
5326 | 2869 * NOTE: much of this is identical to fname_casew(), keep in sync! |
7 | 2870 */ |
2871 void | |
2872 fname_case( | |
2873 char_u *name, | |
2874 int len) | |
2875 { | |
2876 char szTrueName[_MAX_PATH + 2]; | |
2604 | 2877 char szTrueNameTemp[_MAX_PATH + 2]; |
7 | 2878 char *ptrue, *ptruePrev; |
2879 char *porig, *porigPrev; | |
2880 int flen; | |
2881 WIN32_FIND_DATA fb; | |
2882 HANDLE hFind; | |
2883 int c; | |
2604 | 2884 int slen; |
7 | 2885 |
434 | 2886 flen = (int)STRLEN(name); |
5326 | 2887 if (flen == 0) |
7 | 2888 return; |
2889 | |
2890 slash_adjust(name); | |
2891 | |
5326 | 2892 #ifdef FEAT_MBYTE |
2893 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2894 { | |
2895 WCHAR *p = enc_to_utf16(name, NULL); | |
2896 | |
2897 if (p != NULL) | |
2898 { | |
2899 char_u *q; | |
6262 | 2900 WCHAR buf[_MAX_PATH + 1]; |
2901 | |
2902 wcsncpy(buf, p, _MAX_PATH); | |
2903 buf[_MAX_PATH] = L'\0'; | |
5326 | 2904 vim_free(p); |
2905 | |
2906 if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK) | |
2907 { | |
2908 q = utf16_to_enc(buf, NULL); | |
2909 if (q != NULL) | |
2910 { | |
2911 vim_strncpy(name, q, (len > 0) ? len - 1 : flen); | |
2912 vim_free(q); | |
2913 return; | |
2914 } | |
2915 } | |
2916 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2917 return; |
5326 | 2918 } |
2919 #endif | |
2920 | |
2921 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH. | |
2922 * So we should check this after calling wide function. */ | |
2923 if (flen > _MAX_PATH) | |
2924 return; | |
2925 | |
7 | 2926 /* 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
|
2927 porig = (char *)name; |
7 | 2928 ptrue = szTrueName; |
2929 | |
2930 if (isalpha(porig[0]) && porig[1] == ':') | |
2931 { | |
2932 /* copy leading drive letter */ | |
2933 *ptrue++ = *porig++; | |
2934 *ptrue++ = *porig++; | |
2935 } | |
5529 | 2936 *ptrue = NUL; /* in case nothing follows */ |
7 | 2937 |
2938 while (*porig != NUL) | |
2939 { | |
2940 /* copy \ characters */ | |
2941 while (*porig == psepc) | |
2942 *ptrue++ = *porig++; | |
2943 | |
2944 ptruePrev = ptrue; | |
2945 porigPrev = porig; | |
2946 while (*porig != NUL && *porig != psepc) | |
2947 { | |
2948 #ifdef FEAT_MBYTE | |
2949 int l; | |
2950 | |
2951 if (enc_dbcs) | |
2952 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2953 l = (*mb_ptr2len)((char_u *)porig); |
7 | 2954 while (--l >= 0) |
2955 *ptrue++ = *porig++; | |
2956 } | |
2957 else | |
2958 #endif | |
2959 *ptrue++ = *porig++; | |
2960 } | |
2961 *ptrue = NUL; | |
2962 | |
2604 | 2963 /* To avoid a slow failure append "\*" when searching a directory, |
2964 * server or network share. */ | |
2965 STRCPY(szTrueNameTemp, szTrueName); | |
2615 | 2966 slen = (int)strlen(szTrueNameTemp); |
2604 | 2967 if (*porig == psepc && slen + 2 < _MAX_PATH) |
2968 STRCPY(szTrueNameTemp + slen, "\\*"); | |
2969 | |
7 | 2970 /* Skip "", "." and "..". */ |
2971 if (ptrue > ptruePrev | |
2972 && (ptruePrev[0] != '.' | |
2973 || (ptruePrev[1] != NUL | |
2974 && (ptruePrev[1] != '.' || ptruePrev[2] != NUL))) | |
2604 | 2975 && (hFind = FindFirstFile(szTrueNameTemp, &fb)) |
7 | 2976 != INVALID_HANDLE_VALUE) |
2977 { | |
2978 c = *porig; | |
2979 *porig = NUL; | |
2980 | |
2981 /* Only use the match when it's the same name (ignoring case) or | |
2982 * expansion is allowed and there is a match with the short name | |
2983 * and there is enough room. */ | |
2984 if (_stricoll(porigPrev, fb.cFileName) == 0 | |
2985 || (len > 0 | |
2986 && (_stricoll(porigPrev, fb.cAlternateFileName) == 0 | |
2987 && (int)(ptruePrev - szTrueName) | |
2988 + (int)strlen(fb.cFileName) < len))) | |
2989 { | |
2990 STRCPY(ptruePrev, fb.cFileName); | |
2991 | |
2992 /* Look for exact match and prefer it if found. Must be a | |
2993 * long name, otherwise there would be only one match. */ | |
2994 while (FindNextFile(hFind, &fb)) | |
2995 { | |
2996 if (*fb.cAlternateFileName != NUL | |
2997 && (strcoll(porigPrev, fb.cFileName) == 0 | |
2998 || (len > 0 | |
2999 && (_stricoll(porigPrev, | |
3000 fb.cAlternateFileName) == 0 | |
3001 && (int)(ptruePrev - szTrueName) | |
3002 + (int)strlen(fb.cFileName) < len)))) | |
3003 { | |
3004 STRCPY(ptruePrev, fb.cFileName); | |
3005 break; | |
3006 } | |
3007 } | |
3008 } | |
3009 FindClose(hFind); | |
3010 *porig = c; | |
3011 ptrue = ptruePrev + strlen(ptruePrev); | |
3012 } | |
3013 } | |
3014 | |
3015 STRCPY(name, szTrueName); | |
3016 } | |
3017 | |
3018 | |
3019 /* | |
3020 * Insert user name in s[len]. | |
3021 */ | |
3022 int | |
3023 mch_get_user_name( | |
26 | 3024 char_u *s, |
3025 int len) | |
7 | 3026 { |
1414 | 3027 char szUserName[256 + 1]; /* UNLEN is 256 */ |
7 | 3028 DWORD cch = sizeof szUserName; |
3029 | |
5549 | 3030 #ifdef FEAT_MBYTE |
3031 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3032 { | |
3033 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ | |
3034 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); | |
3035 | |
3036 if (GetUserNameW(wszUserName, &wcch)) | |
3037 { | |
3038 char_u *p = utf16_to_enc(wszUserName, NULL); | |
3039 | |
3040 if (p != NULL) | |
3041 { | |
3042 vim_strncpy(s, p, len - 1); | |
3043 vim_free(p); | |
3044 return OK; | |
3045 } | |
3046 } | |
3047 } | |
3048 #endif | |
7 | 3049 if (GetUserName(szUserName, &cch)) |
3050 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3051 vim_strncpy(s, (char_u *)szUserName, len - 1); |
7 | 3052 return OK; |
3053 } | |
3054 s[0] = NUL; | |
3055 return FAIL; | |
3056 } | |
3057 | |
3058 | |
3059 /* | |
3060 * Insert host name in s[len]. | |
3061 */ | |
3062 void | |
3063 mch_get_host_name( | |
3064 char_u *s, | |
3065 int len) | |
3066 { | |
3067 DWORD cch = len; | |
3068 | |
5551 | 3069 #ifdef FEAT_MBYTE |
3070 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3071 { | |
3072 WCHAR wszHostName[256 + 1]; | |
3073 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); | |
3074 | |
3075 if (GetComputerNameW(wszHostName, &wcch)) | |
3076 { | |
3077 char_u *p = utf16_to_enc(wszHostName, NULL); | |
3078 | |
3079 if (p != NULL) | |
3080 { | |
3081 vim_strncpy(s, p, len - 1); | |
3082 vim_free(p); | |
3083 return; | |
3084 } | |
3085 } | |
3086 } | |
3087 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3088 if (!GetComputerName((LPSTR)s, &cch)) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3089 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1); |
7 | 3090 } |
3091 | |
3092 | |
3093 /* | |
3094 * return process ID | |
3095 */ | |
3096 long | |
26 | 3097 mch_get_pid(void) |
7 | 3098 { |
3099 return (long)GetCurrentProcessId(); | |
3100 } | |
3101 | |
3102 | |
3103 /* | |
3104 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
3105 * Return OK for success, FAIL for failure. | |
3106 */ | |
3107 int | |
3108 mch_dirname( | |
3109 char_u *buf, | |
3110 int len) | |
3111 { | |
3112 /* | |
3113 * Originally this was: | |
3114 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
3115 * But the Win32s known bug list says that getcwd() doesn't work | |
3116 * so use the Win32 system call instead. <Negri> | |
3117 */ | |
3118 #ifdef FEAT_MBYTE | |
3119 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3120 { | |
3121 WCHAR wbuf[_MAX_PATH + 1]; | |
3122 | |
3123 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) | |
3124 { | |
1752 | 3125 char_u *p = utf16_to_enc(wbuf, NULL); |
7 | 3126 |
3127 if (p != NULL) | |
3128 { | |
417 | 3129 vim_strncpy(buf, p, len - 1); |
7 | 3130 vim_free(p); |
3131 return OK; | |
3132 } | |
3133 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3134 return FAIL; |
7 | 3135 } |
3136 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3137 return (GetCurrentDirectory(len, (LPSTR)buf) != 0 ? OK : FAIL); |
7 | 3138 } |
3139 | |
3140 /* | |
5494 | 3141 * Get file permissions for "name". |
3142 * Return mode_t or -1 for error. | |
7 | 3143 */ |
3144 long | |
26 | 3145 mch_getperm(char_u *name) |
7 | 3146 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
3147 stat_T st; |
5494 | 3148 int n; |
3149 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3150 n = mch_stat((char *)name, &st); |
5588 | 3151 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 3152 } |
3153 | |
3154 | |
3155 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3156 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3157 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3158 * Return FAIL for failure, OK otherwise. |
7 | 3159 */ |
3160 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3161 mch_setperm(char_u *name, long perm) |
7 | 3162 { |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3163 long n = -1; |
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3164 |
7 | 3165 #ifdef FEAT_MBYTE |
3166 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3167 { | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3168 WCHAR *p = enc_to_utf16(name, NULL); |
7 | 3169 |
3170 if (p != NULL) | |
3171 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3172 n = _wchmod(p, perm); |
7 | 3173 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3174 if (n == -1) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3175 return FAIL; |
7 | 3176 } |
3177 } | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3178 if (n == -1) |
7 | 3179 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3180 n = _chmod((const char *)name, perm); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3181 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3182 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3183 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3184 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3185 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3186 return OK; |
7 | 3187 } |
3188 | |
3189 /* | |
3190 * Set hidden flag for "name". | |
3191 */ | |
3192 void | |
3193 mch_hide(char_u *name) | |
3194 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3195 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3196 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3197 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3198 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3199 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3200 win32_setattrs(name, attrs); |
7 | 3201 } |
3202 | |
3203 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3204 * 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
|
3205 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3206 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3207 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3208 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3209 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3210 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3211 if (f == -1) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3212 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
|
3213 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3214 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3215 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3216 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3217 /* |
7 | 3218 * return TRUE if "name" is a directory |
3219 * return FALSE if "name" is not a directory or upon error | |
3220 */ | |
3221 int | |
3222 mch_isdir(char_u *name) | |
3223 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3224 int f = win32_getattrs(name); |
7 | 3225 |
3226 if (f == -1) | |
3227 return FALSE; /* file does not exist at all */ | |
3228 | |
3229 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3230 } | |
3231 | |
3232 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3233 * 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
|
3234 * 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
|
3235 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3236 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3237 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3238 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3239 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3240 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
|
3241 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3242 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3243 /* |
2803 | 3244 * Create directory "name". |
3245 * Return 0 on success, -1 on error. | |
3246 */ | |
3247 int | |
3248 mch_mkdir(char_u *name) | |
3249 { | |
3250 #ifdef FEAT_MBYTE | |
3251 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3252 { | |
3253 WCHAR *p; | |
3254 int retval; | |
3255 | |
3256 p = enc_to_utf16(name, NULL); | |
3257 if (p == NULL) | |
3258 return -1; | |
3259 retval = _wmkdir(p); | |
3260 vim_free(p); | |
3261 return retval; | |
3262 } | |
3263 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3264 return _mkdir((const char *)name); |
2803 | 3265 } |
3266 | |
3267 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3268 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3269 * 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
|
3270 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3271 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3272 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3273 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3274 #ifdef FEAT_MBYTE |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3275 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
|
3276 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3277 WCHAR *p; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3278 int retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3279 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3280 p = enc_to_utf16(name, NULL); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3281 if (p == NULL) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3282 return -1; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3283 retval = _wrmdir(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3284 vim_free(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3285 return retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3286 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3287 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3288 return _rmdir((const char *)name); |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3289 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3290 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3291 /* |
696 | 3292 * Return TRUE if file "fname" has more than one link. |
3293 */ | |
3294 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3295 mch_is_hard_link(char_u *fname) |
696 | 3296 { |
2793 | 3297 BY_HANDLE_FILE_INFORMATION info; |
3298 | |
3299 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3300 && info.nNumberOfLinks > 1; | |
3301 } | |
3302 | |
3303 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3304 * 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
|
3305 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3306 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3307 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3308 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3309 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3310 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3311 WIN32_FIND_DATAA findDataA; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3312 DWORD fileFlags = 0, reparseTag = 0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3313 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3314 WCHAR *wn = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3315 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3316 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3317 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
|
3318 wn = enc_to_utf16(name, NULL); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3319 if (wn != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3320 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3321 hFind = FindFirstFileW(wn, &findDataW); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3322 vim_free(wn); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3323 if (hFind != INVALID_HANDLE_VALUE) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3324 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3325 fileFlags = findDataW.dwFileAttributes; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3326 reparseTag = findDataW.dwReserved0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3327 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3328 } |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3329 else |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3330 #endif |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3331 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3332 hFind = FindFirstFile((LPCSTR)name, &findDataA); |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3333 if (hFind != INVALID_HANDLE_VALUE) |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3334 { |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3335 fileFlags = findDataA.dwFileAttributes; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3336 reparseTag = findDataA.dwReserved0; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3337 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3338 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3339 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3340 if (hFind != INVALID_HANDLE_VALUE) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3341 FindClose(hFind); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3342 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3343 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
|
3344 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3345 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3346 res = TRUE; |
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 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3349 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3350 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3351 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3352 * Return 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
|
3353 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3354 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3355 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3356 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3357 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3358 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
|
3359 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3360 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3361 } |
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 /* |
2793 | 3364 * Get the by-handle-file-information for "fname". |
3365 * Returns FILEINFO_OK when OK. | |
3366 * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
3367 * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
3368 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3369 */ | |
3370 int | |
3371 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3372 { | |
696 | 3373 HANDLE hFile; |
2793 | 3374 int res = FILEINFO_READ_FAIL; |
696 | 3375 #ifdef FEAT_MBYTE |
3376 WCHAR *wn = NULL; | |
3377 | |
3378 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2793 | 3379 { |
1752 | 3380 wn = enc_to_utf16(fname, NULL); |
2793 | 3381 if (wn == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3382 return FILEINFO_ENC_FAIL; |
2793 | 3383 } |
696 | 3384 if (wn != NULL) |
3385 { | |
3386 hFile = CreateFileW(wn, /* file name */ | |
3387 GENERIC_READ, /* access mode */ | |
2793 | 3388 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3389 NULL, /* security descriptor */ |
3390 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3391 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3392 NULL); /* handle to template file */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3393 vim_free(wn); |
696 | 3394 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3395 else |
696 | 3396 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3397 hFile = CreateFile((LPCSTR)fname, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3398 GENERIC_READ, /* access mode */ |
2793 | 3399 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3400 NULL, /* security descriptor */ |
3401 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3402 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3403 NULL); /* handle to template file */ |
3404 | |
3405 if (hFile != INVALID_HANDLE_VALUE) | |
3406 { | |
2793 | 3407 if (GetFileInformationByHandle(hFile, info) != 0) |
3408 res = FILEINFO_OK; | |
3409 else | |
3410 res = FILEINFO_INFO_FAIL; | |
696 | 3411 CloseHandle(hFile); |
3412 } | |
3413 | |
3414 return res; | |
3415 } | |
3416 | |
3417 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3418 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3419 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3420 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3421 */ |
5494 | 3422 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3423 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3424 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3425 int attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3426 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3427 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3428 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3429 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3430 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3431 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3432 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3433 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3434 attr = GetFileAttributesW(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3435 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3436 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3437 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3438 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3439 attr = GetFileAttributes((char *)name); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3440 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3441 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3442 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3443 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3444 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3445 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3446 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3447 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3448 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3449 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3450 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3451 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3452 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3453 int res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3454 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3455 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3456 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3457 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3458 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3459 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3460 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3461 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3462 res = SetFileAttributesW(p, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3463 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3464 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3465 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3466 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3467 res = SetFileAttributes((char *)name, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3468 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3469 return res ? 0 : -1; |
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 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3472 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3473 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3474 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3475 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3476 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3477 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3478 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3479 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3480 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3481 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3482 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3483 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3484 return win32_setattrs(name, attrs); |
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 /* |
7 | 3488 * Return TRUE if file or directory "name" is writable (not readonly). |
3489 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3490 * delete a file. Let's say this means it is writable. | |
3491 */ | |
3492 int | |
3493 mch_writable(char_u *name) | |
3494 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3495 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3496 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3497 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3498 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3499 } |
3500 | |
3501 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3502 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3503 * 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
|
3504 * 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
|
3505 * the allocated memory. |
7 | 3506 */ |
3507 int | |
6700 | 3508 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3509 { |
10 | 3510 char_u buf[_MAX_PATH]; |
835 | 3511 int len = (int)STRLEN(name); |
10 | 3512 char_u *p; |
3513 | |
3514 if (len >= _MAX_PATH) /* safety check */ | |
3515 return FALSE; | |
3516 | |
3517 /* If there already is an extension try using the name directly. Also do | |
3518 * this with a Unix-shell like 'shell'. */ | |
3519 if (vim_strchr(gettail(name), '.') != NULL | |
3520 || 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
|
3521 if (executable_exists((char *)name, path, use_path)) |
10 | 3522 return TRUE; |
3523 | |
3524 /* | |
3525 * Loop over all extensions in $PATHEXT. | |
3526 */ | |
417 | 3527 vim_strncpy(buf, name, _MAX_PATH - 1); |
10 | 3528 p = mch_getenv("PATHEXT"); |
3529 if (p == NULL) | |
3530 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3531 while (*p) | |
3532 { | |
3533 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3534 { | |
3535 /* A single "." means no extension is added. */ | |
3536 buf[len] = NUL; | |
3537 ++p; | |
3538 if (*p) | |
3539 ++p; | |
3540 } | |
3541 else | |
3542 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
|
3543 if (executable_exists((char *)buf, path, use_path)) |
10 | 3544 return TRUE; |
3545 } | |
3546 return FALSE; | |
7 | 3547 } |
3548 | |
3549 /* | |
3550 * Check what "name" is: | |
3551 * NODE_NORMAL: file or directory (or doesn't exist) | |
3552 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3553 * NODE_OTHER: non-writable things | |
3554 */ | |
3555 int | |
3556 mch_nodetype(char_u *name) | |
3557 { | |
3558 HANDLE hFile; | |
3559 int type; | |
5324 | 3560 #ifdef FEAT_MBYTE |
3561 WCHAR *wn = NULL; | |
3562 #endif | |
7 | 3563 |
1004 | 3564 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
3565 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE | |
3566 * here. */ | |
3567 if (STRNCMP(name, "\\\\.\\", 4) == 0) | |
3568 return NODE_WRITABLE; | |
3569 | |
5324 | 3570 #ifdef FEAT_MBYTE |
3571 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
|
3572 wn = enc_to_utf16(name, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3573 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3574 if (wn != NULL) |
5324 | 3575 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3576 hFile = CreateFileW(wn, /* file name */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3577 GENERIC_WRITE, /* access mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3578 0, /* share mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3579 NULL, /* security descriptor */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3580 OPEN_EXISTING, /* creation disposition */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3581 0, /* file attributes */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3582 NULL); /* handle to template file */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3583 vim_free(wn); |
5324 | 3584 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3585 else |
5324 | 3586 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3587 hFile = CreateFile((LPCSTR)name, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3588 GENERIC_WRITE, /* access mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3589 0, /* share mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3590 NULL, /* security descriptor */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3591 OPEN_EXISTING, /* creation disposition */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3592 0, /* file attributes */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3593 NULL); /* handle to template file */ |
5324 | 3594 |
7 | 3595 if (hFile == INVALID_HANDLE_VALUE) |
3596 return NODE_NORMAL; | |
3597 | |
3598 type = GetFileType(hFile); | |
3599 CloseHandle(hFile); | |
3600 if (type == FILE_TYPE_CHAR) | |
3601 return NODE_WRITABLE; | |
3602 if (type == FILE_TYPE_DISK) | |
3603 return NODE_NORMAL; | |
3604 return NODE_OTHER; | |
3605 } | |
3606 | |
3607 #ifdef HAVE_ACL | |
3608 struct my_acl | |
3609 { | |
3610 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3611 PSID pSidOwner; | |
3612 PSID pSidGroup; | |
3613 PACL pDacl; | |
3614 PACL pSacl; | |
3615 }; | |
3616 #endif | |
3617 | |
3618 /* | |
3619 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3620 * Return NULL if the ACL is not available for whatever reason. | |
3621 */ | |
3622 vim_acl_T | |
26 | 3623 mch_get_acl(char_u *fname) |
7 | 3624 { |
3625 #ifndef HAVE_ACL | |
3626 return (vim_acl_T)NULL; | |
3627 #else | |
3628 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3629 DWORD err; |
7 | 3630 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3631 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
|
3632 if (p != NULL) |
7 | 3633 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3634 # ifdef FEAT_MBYTE |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3635 WCHAR *wn = 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 (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
|
3638 wn = enc_to_utf16(fname, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3639 if (wn != NULL) |
7 | 3640 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3641 /* 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
|
3642 err = GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3643 wn, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3644 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3645 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3646 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3647 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3648 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3649 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3650 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3651 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3652 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3653 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3654 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3655 err == ERROR_PRIVILEGE_NOT_HELD) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3656 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3657 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3658 (void)GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3659 wn, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3660 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3661 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3662 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3663 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3664 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3665 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3666 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3667 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3668 if (p->pSecurityDescriptor == NULL) |
7 | 3669 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3670 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
|
3671 p = NULL; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3672 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3673 vim_free(wn); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3674 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3675 else |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3676 # endif |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3677 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3678 /* 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
|
3679 err = GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3680 (LPSTR)fname, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3681 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3682 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3683 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3684 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3685 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3686 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3687 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3688 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3689 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3690 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3691 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3692 err == ERROR_PRIVILEGE_NOT_HELD) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3693 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3694 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3695 (void)GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3696 (LPSTR)fname, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3697 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3698 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3699 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3700 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3701 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3702 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3703 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3704 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3705 if (p->pSecurityDescriptor == NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3706 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3707 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
|
3708 p = NULL; |
7 | 3709 } |
3710 } | |
3711 } | |
3712 | |
3713 return (vim_acl_T)p; | |
3714 #endif | |
3715 } | |
3716 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3717 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3718 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3719 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3720 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3721 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3722 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3723 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3724 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3725 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3726 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3727 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3728 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3729 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3730 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3731 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3732 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3733 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3734 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3735 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3736 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3737 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3738 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3739 |
7 | 3740 /* |
3741 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3742 * Errors are ignored. | |
3743 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3744 */ | |
3745 void | |
26 | 3746 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3747 { |
3748 #ifdef HAVE_ACL | |
3749 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
|
3750 SECURITY_INFORMATION sec_info = 0; |
7 | 3751 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3752 if (p != NULL) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3753 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3754 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3755 WCHAR *wn = NULL; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3756 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3757 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3758 /* Set security flags */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3759 if (p->pSidOwner) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3760 sec_info |= OWNER_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3761 if (p->pSidGroup) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3762 sec_info |= GROUP_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3763 if (p->pDacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3764 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3765 sec_info |= DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3766 /* Do not inherit its parent's DACL. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3767 * 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
|
3768 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3769 if (!is_acl_inherited(p->pDacl)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3770 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3771 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3772 if (p->pSacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3773 sec_info |= SACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3774 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3775 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3776 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3777 wn = enc_to_utf16(fname, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3778 if (wn != NULL) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3779 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3780 (void)SetNamedSecurityInfoW( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3781 wn, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3782 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3783 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3784 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3785 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3786 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3787 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3788 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3789 vim_free(wn); |
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 else |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3792 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3793 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3794 (void)SetNamedSecurityInfo( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3795 (LPSTR)fname, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3796 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3797 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3798 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3799 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3800 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3801 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3802 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3803 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3804 } |
7 | 3805 #endif |
3806 } | |
3807 | |
3808 void | |
26 | 3809 mch_free_acl(vim_acl_T acl) |
7 | 3810 { |
3811 #ifdef HAVE_ACL | |
3812 struct my_acl *p = (struct my_acl *)acl; | |
3813 | |
3814 if (p != NULL) | |
3815 { | |
3816 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3817 vim_free(p); | |
3818 } | |
3819 #endif | |
3820 } | |
3821 | |
3822 #ifndef FEAT_GUI_W32 | |
3823 | |
3824 /* | |
3825 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3826 */ | |
3827 static BOOL WINAPI | |
3828 handler_routine( | |
3829 DWORD dwCtrlType) | |
3830 { | |
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
|
3831 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
|
3832 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
|
3833 |
7 | 3834 switch (dwCtrlType) |
3835 { | |
3836 case CTRL_C_EVENT: | |
3837 if (ctrl_c_interrupts) | |
3838 g_fCtrlCPressed = TRUE; | |
3839 return TRUE; | |
3840 | |
3841 case CTRL_BREAK_EVENT: | |
3842 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
|
3843 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
|
3844 /* 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
|
3845 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
|
3846 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
|
3847 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
|
3848 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
|
3849 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
|
3850 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
|
3851 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
|
3852 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3853 return TRUE; |
3854 | |
3855 /* fatal events: shut down gracefully */ | |
3856 case CTRL_CLOSE_EVENT: | |
3857 case CTRL_LOGOFF_EVENT: | |
3858 case CTRL_SHUTDOWN_EVENT: | |
3859 windgoto((int)Rows - 1, 0); | |
3860 g_fForceExit = TRUE; | |
3861 | |
1569 | 3862 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3863 (dwCtrlType == CTRL_CLOSE_EVENT |
3864 ? _("close") | |
3865 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3866 ? _("logoff") | |
3867 : _("shutdown"))); | |
3868 #ifdef DEBUG | |
3869 OutputDebugString(IObuff); | |
3870 #endif | |
3871 | |
3872 preserve_exit(); /* output IObuff, preserve files and exit */ | |
3873 | |
3874 return TRUE; /* not reached */ | |
3875 | |
3876 default: | |
3877 return FALSE; | |
3878 } | |
3879 } | |
3880 | |
3881 | |
3882 /* | |
3883 * set the tty in (raw) ? "raw" : "cooked" mode | |
3884 */ | |
3885 void | |
26 | 3886 mch_settmode(int tmode) |
7 | 3887 { |
3888 DWORD cmodein; | |
3889 DWORD cmodeout; | |
3890 BOOL bEnableHandler; | |
3891 | |
3892 GetConsoleMode(g_hConIn, &cmodein); | |
3893 GetConsoleMode(g_hConOut, &cmodeout); | |
3894 if (tmode == TMODE_RAW) | |
3895 { | |
3896 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3897 ENABLE_ECHO_INPUT); | |
3898 #ifdef FEAT_MOUSE | |
3899 if (g_fMouseActive) | |
3900 cmodein |= ENABLE_MOUSE_INPUT; | |
3901 #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
|
3902 cmodeout &= ~( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3903 #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
|
3904 /* 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
|
3905 * VTP. */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3906 ((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
|
3907 #else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3908 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
|
3909 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3910 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3911 bEnableHandler = TRUE; |
3912 } | |
3913 else /* cooked */ | |
3914 { | |
3915 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3916 ENABLE_ECHO_INPUT); | |
3917 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3918 bEnableHandler = FALSE; | |
3919 } | |
3920 SetConsoleMode(g_hConIn, cmodein); | |
3921 SetConsoleMode(g_hConOut, cmodeout); | |
3922 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3923 | |
3924 #ifdef MCH_WRITE_DUMP | |
3925 if (fdDump) | |
3926 { | |
3927 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3928 tmode == TMODE_RAW ? "raw" : | |
3929 tmode == TMODE_COOK ? "cooked" : "normal", | |
3930 cmodein, cmodeout); | |
3931 fflush(fdDump); | |
3932 } | |
3933 #endif | |
3934 } | |
3935 | |
3936 | |
3937 /* | |
3938 * Get the size of the current window in `Rows' and `Columns' | |
3939 * Return OK when size could be determined, FAIL otherwise. | |
3940 */ | |
3941 int | |
26 | 3942 mch_get_shellsize(void) |
7 | 3943 { |
3944 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3945 | |
3946 if (!g_fTermcapMode && g_cbTermcap.IsValid) | |
3947 { | |
3948 /* | |
3949 * For some reason, we are trying to get the screen dimensions | |
3950 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3951 * variables are really intended to mean the size of Vim screen | |
3952 * while in termcap mode. | |
3953 */ | |
3954 Rows = g_cbTermcap.Info.dwSize.Y; | |
3955 Columns = g_cbTermcap.Info.dwSize.X; | |
3956 } | |
3957 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3958 { | |
3959 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3960 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3961 } | |
3962 else | |
3963 { | |
3964 Rows = 25; | |
3965 Columns = 80; | |
3966 } | |
3967 return OK; | |
3968 } | |
3969 | |
3970 /* | |
3971 * Set a console window to `xSize' * `ySize' | |
3972 */ | |
3973 static void | |
3974 ResizeConBufAndWindow( | |
26 | 3975 HANDLE hConsole, |
3976 int xSize, | |
3977 int ySize) | |
7 | 3978 { |
3979 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ | |
3980 SMALL_RECT srWindowRect; /* hold the new console size */ | |
3981 COORD coordScreen; | |
3982 | |
3983 #ifdef MCH_WRITE_DUMP | |
3984 if (fdDump) | |
3985 { | |
3986 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3987 fflush(fdDump); | |
3988 } | |
3989 #endif | |
3990 | |
3991 /* get the largest size we can size the console window to */ | |
3992 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
3993 | |
3994 /* define the new console window size and scroll position */ | |
3995 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
3996 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3997 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3998 | |
3999 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
4000 { | |
4001 int sx, sy; | |
4002 | |
4003 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
4004 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
4005 if (sy < ySize || sx < xSize) | |
4006 { | |
4007 /* | |
4008 * Increasing number of lines/columns, do buffer first. | |
4009 * Use the maximal size in x and y direction. | |
4010 */ | |
4011 if (sy < ySize) | |
4012 coordScreen.Y = ySize; | |
4013 else | |
4014 coordScreen.Y = sy; | |
4015 if (sx < xSize) | |
4016 coordScreen.X = xSize; | |
4017 else | |
4018 coordScreen.X = sx; | |
4019 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
4020 } | |
4021 } | |
4022 | |
4023 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &srWindowRect)) | |
4024 { | |
4025 #ifdef MCH_WRITE_DUMP | |
4026 if (fdDump) | |
4027 { | |
4028 fprintf(fdDump, "SetConsoleWindowInfo failed: %lx\n", | |
4029 GetLastError()); | |
4030 fflush(fdDump); | |
4031 } | |
4032 #endif | |
4033 } | |
4034 | |
4035 /* define the new console buffer size */ | |
4036 coordScreen.X = xSize; | |
4037 coordScreen.Y = ySize; | |
4038 | |
4039 if (!SetConsoleScreenBufferSize(hConsole, coordScreen)) | |
4040 { | |
4041 #ifdef MCH_WRITE_DUMP | |
4042 if (fdDump) | |
4043 { | |
4044 fprintf(fdDump, "SetConsoleScreenBufferSize failed: %lx\n", | |
4045 GetLastError()); | |
4046 fflush(fdDump); | |
4047 } | |
4048 #endif | |
4049 } | |
4050 } | |
4051 | |
4052 | |
4053 /* | |
4054 * Set the console window to `Rows' * `Columns' | |
4055 */ | |
4056 void | |
26 | 4057 mch_set_shellsize(void) |
7 | 4058 { |
4059 COORD coordScreen; | |
4060 | |
4061 /* Don't change window size while still starting up */ | |
4062 if (suppress_winsize != 0) | |
4063 { | |
4064 suppress_winsize = 2; | |
4065 return; | |
4066 } | |
4067 | |
4068 if (term_console) | |
4069 { | |
4070 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
4071 | |
4072 /* Clamp Rows and Columns to reasonable values */ | |
4073 if (Rows > coordScreen.Y) | |
4074 Rows = coordScreen.Y; | |
4075 if (Columns > coordScreen.X) | |
4076 Columns = coordScreen.X; | |
4077 | |
4078 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
4079 } | |
4080 } | |
4081 | |
4082 /* | |
4083 * Rows and/or Columns has changed. | |
4084 */ | |
4085 void | |
26 | 4086 mch_new_shellsize(void) |
7 | 4087 { |
4088 set_scroll_region(0, 0, Columns - 1, Rows - 1); | |
4089 } | |
4090 | |
4091 | |
4092 /* | |
4093 * Called when started up, to set the winsize that was delayed. | |
4094 */ | |
4095 void | |
26 | 4096 mch_set_winsize_now(void) |
7 | 4097 { |
4098 if (suppress_winsize == 2) | |
4099 { | |
4100 suppress_winsize = 0; | |
4101 mch_set_shellsize(); | |
4102 shell_resized(); | |
4103 } | |
4104 suppress_winsize = 0; | |
4105 } | |
4106 #endif /* FEAT_GUI_W32 */ | |
4107 | |
5547 | 4108 static BOOL |
4109 vim_create_process( | |
5556 | 4110 char *cmd, |
5569 | 4111 BOOL inherit_handles, |
5547 | 4112 DWORD flags, |
4113 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
|
4114 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
|
4115 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4116 char *cwd) |
5547 | 4117 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4118 #ifdef FEAT_MBYTE |
5547 | 4119 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
4120 { | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4121 BOOL ret; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4122 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
|
4123 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4124 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
|
4125 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
|
4126 goto fallback; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4127 if (cwd != NULL) |
5547 | 4128 { |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4129 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
|
4130 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
|
4131 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4132 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
|
4133 goto fallback; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4134 } |
5547 | 4135 } |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4136 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4137 ret = CreateProcessW( |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4138 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
|
4139 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
|
4140 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
|
4141 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
|
4142 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
|
4143 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
|
4144 env, /* Environment */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4145 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
|
4146 (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
|
4147 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
|
4148 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
|
4149 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
|
4150 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
|
4151 return ret; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4152 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4153 fallback: |
5547 | 4154 #endif |
4155 return CreateProcess( | |
4156 NULL, /* Executable name */ | |
4157 cmd, /* Command to execute */ | |
4158 NULL, /* Process security attributes */ | |
4159 NULL, /* Thread security attributes */ | |
4160 inherit_handles, /* Inherit handles */ | |
4161 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
|
4162 env, /* Environment */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4163 cwd, /* Current directory */ |
5547 | 4164 si, /* Startup information */ |
4165 pi); /* Process information */ | |
4166 } | |
7 | 4167 |
4168 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4169 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
|
4170 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
|
4171 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
|
4172 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
|
4173 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4174 #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
|
4175 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
|
4176 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4177 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
|
4178 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
|
4179 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4180 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
|
4181 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
|
4182 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
|
4183 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
|
4184 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4185 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4186 #endif |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4187 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
|
4188 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4189 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4190 |
7 | 4191 #if defined(FEAT_GUI_W32) || defined(PROTO) |
4192 | |
4193 /* | |
4194 * Specialised version of system() for Win32 GUI mode. | |
4195 * This version proceeds as follows: | |
4196 * 1. Create a console window for use by the subprocess | |
4197 * 2. Run the subprocess (it gets the allocated console by default) | |
4198 * 3. Wait for the subprocess to terminate and get its exit code | |
4199 * 4. Prompt the user to press a key to close the console window | |
4200 */ | |
4201 static int | |
2935 | 4202 mch_system_classic(char *cmd, int options) |
7 | 4203 { |
4204 STARTUPINFO si; | |
4205 PROCESS_INFORMATION pi; | |
4206 DWORD ret = 0; | |
4207 HWND hwnd = GetFocus(); | |
4208 | |
4209 si.cb = sizeof(si); | |
4210 si.lpReserved = NULL; | |
4211 si.lpDesktop = NULL; | |
4212 si.lpTitle = NULL; | |
4213 si.dwFlags = STARTF_USESHOWWINDOW; | |
4214 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4215 * It's nicer to run a filter command in a minimized window. |
2643 | 4216 * Don't activate the window to keep focus on Vim. |
7 | 4217 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4218 if (options & SHELL_DOOUT) |
2643 | 4219 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 4220 else |
4221 si.wShowWindow = SW_SHOWNORMAL; | |
4222 si.cbReserved2 = 0; | |
4223 si.lpReserved2 = NULL; | |
4224 | |
4225 /* Now, run the command */ | |
5547 | 4226 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
|
4227 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
|
4228 &si, &pi, NULL, NULL); |
7 | 4229 |
4230 /* Wait for the command to terminate before continuing */ | |
4231 { | |
4232 #ifdef FEAT_GUI | |
4233 int delay = 1; | |
4234 | |
4235 /* Keep updating the window while waiting for the shell to finish. */ | |
4236 for (;;) | |
4237 { | |
4238 MSG msg; | |
4239 | |
3010 | 4240 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 4241 { |
4242 TranslateMessage(&msg); | |
3010 | 4243 pDispatchMessage(&msg); |
3720 | 4244 delay = 1; |
4245 continue; | |
7 | 4246 } |
4247 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4248 break; | |
4249 | |
4250 /* We start waiting for a very short time and then increase it, so | |
4251 * that we respond quickly when the process is quick, and don't | |
4252 * consume too much overhead when it's slow. */ | |
4253 if (delay < 50) | |
4254 delay += 10; | |
4255 } | |
4256 #else | |
4257 WaitForSingleObject(pi.hProcess, INFINITE); | |
4258 #endif | |
4259 | |
4260 /* Get the command exit code */ | |
4261 GetExitCodeProcess(pi.hProcess, &ret); | |
4262 } | |
4263 | |
4264 /* Close the handles to the subprocess, so that it goes away */ | |
4265 CloseHandle(pi.hThread); | |
4266 CloseHandle(pi.hProcess); | |
4267 | |
4268 /* Try to get input focus back. Doesn't always work though. */ | |
4269 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
4270 | |
4271 return ret; | |
4272 } | |
2935 | 4273 |
4274 /* | |
4275 * Thread launched by the gui to send the current buffer data to the | |
4276 * process. This way avoid to hang up vim totally if the children | |
4277 * process take a long time to process the lines. | |
4278 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4279 static unsigned int __stdcall |
2935 | 4280 sub_process_writer(LPVOID param) |
4281 { | |
4282 HANDLE g_hChildStd_IN_Wr = param; | |
4283 linenr_T lnum = curbuf->b_op_start.lnum; | |
4284 DWORD len = 0; | |
4285 DWORD l; | |
4286 char_u *lp = ml_get(lnum); | |
4287 char_u *s; | |
4288 int written = 0; | |
4289 | |
4290 for (;;) | |
4291 { | |
4292 l = (DWORD)STRLEN(lp + written); | |
4293 if (l == 0) | |
4294 len = 0; | |
4295 else if (lp[written] == NL) | |
4296 { | |
4297 /* NL -> NUL translation */ | |
4298 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
4299 } | |
4300 else | |
4301 { | |
4302 s = vim_strchr(lp + written, NL); | |
4303 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4304 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4305 &len, NULL); | |
4306 } | |
4307 if (len == (int)l) | |
4308 { | |
4309 /* Finished a line, add a NL, unless this line should not have | |
4310 * one. */ | |
4311 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4312 || (!curbuf->b_p_bin |
4313 && curbuf->b_p_fixeol) | |
2935 | 4314 || (lnum != curbuf->b_no_eol_lnum |
4315 && (lnum != curbuf->b_ml.ml_line_count | |
4316 || curbuf->b_p_eol))) | |
4317 { | |
4238 | 4318 WriteFile(g_hChildStd_IN_Wr, "\n", 1, (LPDWORD)&ignored, NULL); |
2935 | 4319 } |
4320 | |
4321 ++lnum; | |
4322 if (lnum > curbuf->b_op_end.lnum) | |
4323 break; | |
4324 | |
4325 lp = ml_get(lnum); | |
4326 written = 0; | |
4327 } | |
4328 else if (len > 0) | |
4329 written += len; | |
4330 } | |
4331 | |
4332 /* finished all the lines, close pipe */ | |
4333 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4334 return 0; |
2935 | 4335 } |
4336 | |
4337 | |
4338 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4339 | |
4340 /* | |
4341 * This function read from the children's stdout and write the | |
4342 * data on screen or in the buffer accordingly. | |
4343 */ | |
4344 static void | |
4345 dump_pipe(int options, | |
4346 HANDLE g_hChildStd_OUT_Rd, | |
4347 garray_T *ga, | |
4348 char_u buffer[], | |
4349 DWORD *buffer_off) | |
4350 { | |
4351 DWORD availableBytes = 0; | |
4352 DWORD i; | |
4353 int ret; | |
4354 DWORD len; | |
4355 DWORD toRead; | |
4356 int repeatCount; | |
4357 | |
4358 /* we query the pipe to see if there is any data to read | |
4359 * to avoid to perform a blocking read */ | |
4360 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4361 NULL, /* optional buffer */ | |
3622 | 4362 0, /* buffer size */ |
2935 | 4363 NULL, /* number of read bytes */ |
4364 &availableBytes, /* available bytes total */ | |
4365 NULL); /* byteLeft */ | |
4366 | |
4367 repeatCount = 0; | |
4368 /* We got real data in the pipe, read it */ | |
3622 | 4369 while (ret != 0 && availableBytes > 0) |
2935 | 4370 { |
4371 repeatCount++; | |
4372 toRead = | |
4373 # ifdef FEAT_MBYTE | |
4374 (DWORD)(BUFLEN - *buffer_off); | |
4375 # else | |
4376 (DWORD)BUFLEN; | |
4377 # endif | |
4378 toRead = availableBytes < toRead ? availableBytes : toRead; | |
4379 ReadFile(g_hChildStd_OUT_Rd, buffer | |
4380 # ifdef FEAT_MBYTE | |
4381 + *buffer_off, toRead | |
4382 # else | |
4383 , toRead | |
4384 # endif | |
4385 , &len, NULL); | |
4386 | |
4387 /* If we haven't read anything, there is a problem */ | |
4388 if (len == 0) | |
4389 break; | |
4390 | |
4391 availableBytes -= len; | |
4392 | |
4393 if (options & SHELL_READ) | |
4394 { | |
4395 /* Do NUL -> NL translation, append NL separated | |
4396 * lines to the current buffer. */ | |
4397 for (i = 0; i < len; ++i) | |
4398 { | |
4399 if (buffer[i] == NL) | |
4400 append_ga_line(ga); | |
4401 else if (buffer[i] == NUL) | |
4402 ga_append(ga, NL); | |
4403 else | |
4404 ga_append(ga, buffer[i]); | |
4405 } | |
4406 } | |
4407 # ifdef FEAT_MBYTE | |
4408 else if (has_mbyte) | |
4409 { | |
4410 int l; | |
3030 | 4411 int c; |
4412 char_u *p; | |
2935 | 4413 |
4414 len += *buffer_off; | |
4415 buffer[len] = NUL; | |
4416 | |
4417 /* Check if the last character in buffer[] is | |
4418 * incomplete, keep these bytes for the next | |
4419 * round. */ | |
4420 for (p = buffer; p < buffer + len; p += l) | |
4421 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4422 l = MB_CPTR2LEN(p); |
2935 | 4423 if (l == 0) |
4424 l = 1; /* NUL byte? */ | |
4425 else if (MB_BYTE2LEN(*p) != l) | |
4426 break; | |
4427 } | |
4428 if (p == buffer) /* no complete character */ | |
4429 { | |
4430 /* avoid getting stuck at an illegal byte */ | |
4431 if (len >= 12) | |
4432 ++p; | |
4433 else | |
4434 { | |
4435 *buffer_off = len; | |
4436 return; | |
4437 } | |
4438 } | |
4439 c = *p; | |
4440 *p = NUL; | |
4441 msg_puts(buffer); | |
4442 if (p < buffer + len) | |
4443 { | |
4444 *p = c; | |
4445 *buffer_off = (DWORD)((buffer + len) - p); | |
4446 mch_memmove(buffer, p, *buffer_off); | |
4447 return; | |
4448 } | |
4449 *buffer_off = 0; | |
4450 } | |
4451 # endif /* FEAT_MBYTE */ | |
4452 else | |
4453 { | |
4454 buffer[len] = NUL; | |
4455 msg_puts(buffer); | |
4456 } | |
4457 | |
4458 windgoto(msg_row, msg_col); | |
4459 cursor_on(); | |
4460 out_flush(); | |
4461 } | |
4462 } | |
4463 | |
4464 /* | |
4465 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4466 * for communication and doesn't open any new window. | |
4467 */ | |
4468 static int | |
4469 mch_system_piped(char *cmd, int options) | |
4470 { | |
4471 STARTUPINFO si; | |
4472 PROCESS_INFORMATION pi; | |
4473 DWORD ret = 0; | |
4474 | |
4475 HANDLE g_hChildStd_IN_Rd = NULL; | |
4476 HANDLE g_hChildStd_IN_Wr = NULL; | |
4477 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4478 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4479 | |
4480 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4481 DWORD len; | |
4482 | |
4483 /* buffer used to receive keys */ | |
4484 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4485 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4486 | |
4487 DWORD i; | |
4488 int c; | |
4489 int noread_cnt = 0; | |
4490 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
|
4491 int delay = 1; |
2935 | 4492 DWORD buffer_off = 0; /* valid bytes in buffer[] */ |
3361 | 4493 char *p = NULL; |
2935 | 4494 |
4495 SECURITY_ATTRIBUTES saAttr; | |
4496 | |
4497 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4498 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4499 saAttr.bInheritHandle = TRUE; | |
4500 saAttr.lpSecurityDescriptor = NULL; | |
4501 | |
4502 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4503 /* 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
|
4504 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4505 /* Create a pipe for the child process's STDIN. */ |
4506 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4507 /* 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
|
4508 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4509 { |
4510 CloseHandle(g_hChildStd_IN_Rd); | |
4511 CloseHandle(g_hChildStd_IN_Wr); | |
4512 CloseHandle(g_hChildStd_OUT_Rd); | |
4513 CloseHandle(g_hChildStd_OUT_Wr); | |
4514 MSG_PUTS(_("\nCannot create pipes\n")); | |
4515 } | |
4516 | |
4517 si.cb = sizeof(si); | |
4518 si.lpReserved = NULL; | |
4519 si.lpDesktop = NULL; | |
4520 si.lpTitle = NULL; | |
4521 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4522 | |
4523 /* set-up our file redirection */ | |
4524 si.hStdError = g_hChildStd_OUT_Wr; | |
4525 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4526 si.hStdInput = g_hChildStd_IN_Rd; | |
4527 si.wShowWindow = SW_HIDE; | |
4528 si.cbReserved2 = 0; | |
4529 si.lpReserved2 = NULL; | |
4530 | |
4531 if (options & SHELL_READ) | |
4532 ga_init2(&ga, 1, BUFLEN); | |
4533 | |
3361 | 4534 if (cmd != NULL) |
4535 { | |
4536 p = (char *)vim_strsave((char_u *)cmd); | |
4537 if (p != NULL) | |
4538 unescape_shellxquote((char_u *)p, p_sxe); | |
4539 else | |
4540 p = cmd; | |
4541 } | |
4542 | |
5547 | 4543 /* Now, run the command. |
4544 * About "Inherit handles" being TRUE: this command can be litigious, | |
4545 * handle inheritance was deactivated for pending temp file, but, if we | |
4546 * 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
|
4547 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
|
4548 &si, &pi, NULL, NULL); |
2935 | 4549 |
3361 | 4550 if (p != cmd) |
4551 vim_free(p); | |
2935 | 4552 |
4553 /* Close our unused side of the pipes */ | |
4554 CloseHandle(g_hChildStd_IN_Rd); | |
4555 CloseHandle(g_hChildStd_OUT_Wr); | |
4556 | |
4557 if (options & SHELL_WRITE) | |
4558 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4559 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4560 _beginthreadex(NULL, /* security attributes */ |
2935 | 4561 0, /* default stack size */ |
4562 sub_process_writer, /* function to be executed */ | |
4563 g_hChildStd_IN_Wr, /* parameter */ | |
4564 0, /* creation flag, start immediately */ | |
4565 NULL); /* we don't care about thread id */ | |
4566 CloseHandle(thread); | |
4567 g_hChildStd_IN_Wr = NULL; | |
4568 } | |
4569 | |
4570 /* Keep updating the window while waiting for the shell to finish. */ | |
4571 for (;;) | |
4572 { | |
4573 MSG msg; | |
4574 | |
5553 | 4575 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4576 { |
4577 TranslateMessage(&msg); | |
5553 | 4578 pDispatchMessage(&msg); |
2935 | 4579 } |
4580 | |
4581 /* write pipe information in the window */ | |
4582 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4583 # ifdef FEAT_GUI | |
4584 || gui.in_use | |
4585 # endif | |
4586 ) | |
4587 { | |
4588 len = 0; | |
4589 if (!(options & SHELL_EXPAND) | |
4590 && ((options & | |
4591 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4592 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4593 # ifdef FEAT_GUI | |
4594 || gui.in_use | |
4595 # endif | |
4596 ) | |
4597 && (ta_len > 0 || noread_cnt > 4)) | |
4598 { | |
4599 if (ta_len == 0) | |
4600 { | |
4601 /* Get extra characters when we don't have any. Reset the | |
4602 * counter and timer. */ | |
4603 noread_cnt = 0; | |
4604 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4605 } | |
4606 if (ta_len > 0 || len > 0) | |
4607 { | |
4608 /* | |
4609 * For pipes: Check for CTRL-C: send interrupt signal to | |
4610 * child. Check for CTRL-D: EOF, close pipe to child. | |
4611 */ | |
4612 if (len == 1 && cmd != NULL) | |
4613 { | |
4614 if (ta_buf[ta_len] == Ctrl_C) | |
4615 { | |
4616 /* Learn what exit code is expected, for | |
4617 * now put 9 as SIGKILL */ | |
4618 TerminateProcess(pi.hProcess, 9); | |
4619 } | |
4620 if (ta_buf[ta_len] == Ctrl_D) | |
4621 { | |
4622 CloseHandle(g_hChildStd_IN_Wr); | |
4623 g_hChildStd_IN_Wr = NULL; | |
4624 } | |
4625 } | |
4626 | |
4627 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4628 for (i = ta_len; i < ta_len + len; ++i) | |
4629 { | |
4630 if (ta_buf[i] == CSI && len - i > 2) | |
4631 { | |
4632 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4633 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4634 { | |
4635 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4636 (size_t)(len - i - 2)); | |
4637 if (c == K_DEL || c == K_KDEL) | |
4638 ta_buf[i] = DEL; | |
4639 else | |
4640 ta_buf[i] = Ctrl_H; | |
4641 len -= 2; | |
4642 } | |
4643 } | |
4644 else if (ta_buf[i] == '\r') | |
4645 ta_buf[i] = '\n'; | |
4646 # ifdef FEAT_MBYTE | |
4647 if (has_mbyte) | |
4648 i += (*mb_ptr2len_len)(ta_buf + i, | |
4649 ta_len + len - i) - 1; | |
4650 # endif | |
4651 } | |
4652 | |
4653 /* | |
4654 * For pipes: echo the typed characters. For a pty this | |
4655 * does not seem to work. | |
4656 */ | |
4657 for (i = ta_len; i < ta_len + len; ++i) | |
4658 { | |
4659 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4660 msg_putchar(ta_buf[i]); | |
4661 # ifdef FEAT_MBYTE | |
4662 else if (has_mbyte) | |
4663 { | |
4664 int l = (*mb_ptr2len)(ta_buf + i); | |
4665 | |
4666 msg_outtrans_len(ta_buf + i, l); | |
4667 i += l - 1; | |
4668 } | |
4669 # endif | |
4670 else | |
4671 msg_outtrans_len(ta_buf + i, 1); | |
4672 } | |
4673 windgoto(msg_row, msg_col); | |
4674 out_flush(); | |
4675 | |
4676 ta_len += len; | |
4677 | |
4678 /* | |
4679 * Write the characters to the child, unless EOF has been | |
4680 * typed for pipes. Write one character at a time, to | |
4681 * avoid losing too much typeahead. When writing buffer | |
4682 * lines, drop the typed characters (only check for | |
4683 * CTRL-C). | |
4684 */ | |
4685 if (options & SHELL_WRITE) | |
4686 ta_len = 0; | |
4687 else if (g_hChildStd_IN_Wr != NULL) | |
4688 { | |
4689 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4690 1, &len, NULL); | |
4691 // if we are typing in, we want to keep things reactive | |
4692 delay = 1; | |
4693 if (len > 0) | |
4694 { | |
4695 ta_len -= len; | |
4696 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4697 } | |
4698 } | |
4699 } | |
4700 } | |
4701 } | |
4702 | |
4703 if (ta_len) | |
4704 ui_inchar_undo(ta_buf, ta_len); | |
4705 | |
4706 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4707 { | |
3030 | 4708 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4709 break; |
4710 } | |
4711 | |
4712 ++noread_cnt; | |
3030 | 4713 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4714 |
4715 /* We start waiting for a very short time and then increase it, so | |
4716 * that we respond quickly when the process is quick, and don't | |
4717 * consume too much overhead when it's slow. */ | |
4718 if (delay < 50) | |
4719 delay += 10; | |
4720 } | |
4721 | |
4722 /* Close the pipe */ | |
4723 CloseHandle(g_hChildStd_OUT_Rd); | |
4724 if (g_hChildStd_IN_Wr != NULL) | |
4725 CloseHandle(g_hChildStd_IN_Wr); | |
4726 | |
4727 WaitForSingleObject(pi.hProcess, INFINITE); | |
4728 | |
4729 /* Get the command exit code */ | |
4730 GetExitCodeProcess(pi.hProcess, &ret); | |
4731 | |
4732 if (options & SHELL_READ) | |
4733 { | |
4734 if (ga.ga_len > 0) | |
4735 { | |
4736 append_ga_line(&ga); | |
4737 /* remember that the NL was missing */ | |
4738 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4739 } | |
4740 else | |
4741 curbuf->b_no_eol_lnum = 0; | |
4742 ga_clear(&ga); | |
4743 } | |
4744 | |
4745 /* Close the handles to the subprocess, so that it goes away */ | |
4746 CloseHandle(pi.hThread); | |
4747 CloseHandle(pi.hProcess); | |
4748 | |
4749 return ret; | |
4750 } | |
4751 | |
4752 static int | |
4753 mch_system(char *cmd, int options) | |
4754 { | |
4755 /* 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
|
4756 if (!p_stmp) |
2935 | 4757 return mch_system_piped(cmd, options); |
4758 else | |
4759 return mch_system_classic(cmd, options); | |
4760 } | |
7 | 4761 #else |
4762 | |
5547 | 4763 # ifdef FEAT_MBYTE |
4764 static int | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4765 mch_system(char *cmd, int options) |
5547 | 4766 { |
4767 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4768 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4769 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 4770 if (wcmd != NULL) |
4771 { | |
4772 int ret = _wsystem(wcmd); | |
4773 vim_free(wcmd); | |
4774 return ret; | |
4775 } | |
4776 } | |
4777 return system(cmd); | |
4778 } | |
4779 # else | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4780 # define mch_system(c, o) system(c) |
5547 | 4781 # endif |
7 | 4782 |
4783 #endif | |
4784 | |
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
|
4785 #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
|
4786 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4787 * 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
|
4788 */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4789 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
|
4790 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
|
4791 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
|
4792 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
|
4793 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4794 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
|
4795 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
|
4796 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
|
4797 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
|
4798 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
|
4799 buf_T *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
|
4800 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
|
4801 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
|
4802 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4803 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4804 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
|
4805 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4806 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
|
4807 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
|
4808 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
|
4809 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4810 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4811 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4812 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
|
4813 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
|
4814 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4815 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4816 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4817 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
|
4818 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
|
4819 } |
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
|
4820 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4821 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
|
4822 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4823 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
|
4824 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
|
4825 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
|
4826 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
|
4827 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
|
4828 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
|
4829 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4830 /* 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
|
4831 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
|
4832 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4833 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
|
4834 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
|
4835 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4836 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
|
4837 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4838 /* 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
|
4839 * 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
|
4840 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
|
4841 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
|
4842 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4843 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
|
4844 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
|
4845 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4846 retval = 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
|
4847 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
|
4848 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4849 /* 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
|
4850 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
|
4851 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4852 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
|
4853 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
|
4854 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4855 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
|
4856 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
|
4857 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4858 #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
|
4859 |
7 | 4860 /* |
4861 * Either execute a command by calling the shell or start a new shell | |
4862 */ | |
4863 int | |
4864 mch_call_shell( | |
26 | 4865 char_u *cmd, |
4866 int options) /* SHELL_*, see vim.h */ | |
7 | 4867 { |
4868 int x = 0; | |
4869 int tmode = cur_tmode; | |
4870 #ifdef FEAT_TITLE | |
6293 | 4871 char szShellTitle[512]; |
6290 | 4872 # ifdef FEAT_MBYTE |
6293 | 4873 int did_set_title = FALSE; |
4874 | |
6290 | 4875 /* Change the title to reflect that we are in a subshell. */ |
4876 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4877 { | |
4878 WCHAR szShellTitle[512]; | |
4879 | |
4880 if (GetConsoleTitleW(szShellTitle, | |
4881 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) | |
4882 { | |
4883 if (cmd == NULL) | |
4884 wcscat(szShellTitle, L" :sh"); | |
4885 else | |
4886 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4887 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL); |
6290 | 4888 |
4889 if (wn != NULL) | |
4890 { | |
4891 wcscat(szShellTitle, L" - !"); | |
4892 if ((wcslen(szShellTitle) + wcslen(wn) < | |
4893 sizeof(szShellTitle)/sizeof(WCHAR))) | |
4894 wcscat(szShellTitle, wn); | |
4895 SetConsoleTitleW(szShellTitle); | |
4896 vim_free(wn); | |
6293 | 4897 did_set_title = TRUE; |
6290 | 4898 } |
4899 } | |
4900 } | |
4901 } | |
6293 | 4902 if (!did_set_title) |
4903 # endif | |
4904 /* Change the title to reflect that we are in a subshell. */ | |
4905 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0) | |
7 | 4906 { |
6293 | 4907 if (cmd == NULL) |
4908 strcat(szShellTitle, " :sh"); | |
4909 else | |
4910 { | |
4911 strcat(szShellTitle, " - !"); | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4912 if ((strlen(szShellTitle) + strlen((char *)cmd) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4913 < sizeof(szShellTitle))) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4914 strcat(szShellTitle, (char *)cmd); |
6293 | 4915 } |
4916 SetConsoleTitle(szShellTitle); | |
7 | 4917 } |
4918 #endif | |
4919 | |
4920 out_flush(); | |
4921 | |
4922 #ifdef MCH_WRITE_DUMP | |
4923 if (fdDump) | |
4924 { | |
4925 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4926 fflush(fdDump); | |
4927 } | |
4928 #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
|
4929 #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
|
4930 /* 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
|
4931 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
|
4932 && (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
|
4933 { |
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 /* 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
|
4935 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
|
4936 #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
|
4937 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
|
4938 #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
|
4939 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
|
4940 } |
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 #endif |
7 | 4942 |
4943 /* | |
4944 * Catch all deadly signals while running the external command, because a | |
4945 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4946 */ | |
4947 signal(SIGINT, SIG_IGN); | |
4948 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4949 signal(SIGKILL, SIG_IGN); | |
4950 #else | |
4951 signal(SIGBREAK, SIG_IGN); | |
4952 #endif | |
4953 signal(SIGILL, SIG_IGN); | |
4954 signal(SIGFPE, SIG_IGN); | |
4955 signal(SIGSEGV, SIG_IGN); | |
4956 signal(SIGTERM, SIG_IGN); | |
4957 signal(SIGABRT, SIG_IGN); | |
4958 | |
4959 if (options & SHELL_COOKED) | |
4960 settmode(TMODE_COOK); /* set to normal mode */ | |
4961 | |
4962 if (cmd == NULL) | |
4963 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4964 x = mch_system((char *)p_sh, options); |
7 | 4965 } |
4966 else | |
4967 { | |
4968 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 4969 char_u *newcmd = NULL; |
4970 char_u *cmdbase = cmd; | |
4971 long_u cmdlen; | |
3361 | 4972 |
4973 /* Skip a leading ", ( and "(. */ | |
4974 if (*cmdbase == '"' ) | |
4975 ++cmdbase; | |
4976 if (*cmdbase == '(') | |
4977 ++cmdbase; | |
4978 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4979 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 4980 { |
4981 STARTUPINFO si; | |
4982 PROCESS_INFORMATION pi; | |
4983 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
|
4984 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 4985 char_u *p; |
4986 | |
5627 | 4987 ZeroMemory(&si, sizeof(si)); |
3361 | 4988 si.cb = sizeof(si); |
4989 si.lpReserved = NULL; | |
4990 si.lpDesktop = NULL; | |
4991 si.lpTitle = NULL; | |
4992 si.dwFlags = 0; | |
4993 si.cbReserved2 = 0; | |
4994 si.lpReserved2 = NULL; | |
4995 | |
4996 cmdbase = skipwhite(cmdbase + 5); | |
4997 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
|
4998 && VIM_ISWHITE(cmdbase[4])) |
3361 | 4999 { |
5000 cmdbase = skipwhite(cmdbase + 4); | |
5001 si.dwFlags = STARTF_USESHOWWINDOW; | |
5002 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
|
5003 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 5004 } |
5005 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
|
5006 && VIM_ISWHITE(cmdbase[2])) |
3361 | 5007 { |
5008 cmdbase = skipwhite(cmdbase + 2); | |
5009 flags = CREATE_NO_WINDOW; | |
5010 si.dwFlags = STARTF_USESTDHANDLES; | |
5011 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 5012 GENERIC_READ, // Access flags |
3361 | 5013 0, // Share flags |
3363 | 5014 NULL, // Security att. |
5015 OPEN_EXISTING, // Open flags | |
5016 FILE_ATTRIBUTE_NORMAL, // File att. | |
5017 NULL); // Temp file | |
3361 | 5018 si.hStdOutput = si.hStdInput; |
5019 si.hStdError = si.hStdInput; | |
5020 } | |
5021 | |
5022 /* Remove a trailing ", ) and )" if they have a match | |
5023 * at the start of the command. */ | |
5024 if (cmdbase > cmd) | |
5025 { | |
5026 p = cmdbase + STRLEN(cmdbase); | |
5027 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
5028 *--p = NUL; | |
5029 if (p > cmdbase && p[-1] == ')' | |
5030 && (*cmd =='(' || cmd[1] == '(')) | |
5031 *--p = NUL; | |
5032 } | |
5033 | |
3363 | 5034 newcmd = cmdbase; |
5035 unescape_shellxquote(cmdbase, p_sxe); | |
5036 | |
3361 | 5037 /* |
3363 | 5038 * If creating new console, arguments are passed to the |
5039 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
5040 * correctly for current 'cmd.exe'. So unescape characters in | |
5041 * shellxescape except '|' for avoiding to be treated as | |
5042 * argument to them. Pass the arguments to sub-shell. | |
3361 | 5043 */ |
3363 | 5044 if (flags != CREATE_NEW_CONSOLE) |
5045 { | |
5046 char_u *subcmd; | |
3367 | 5047 char_u *cmd_shell = mch_getenv("COMSPEC"); |
5048 | |
5049 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
|
5050 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5051 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5052 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5053 (char_u *)"|", '^', FALSE); |
3363 | 5054 if (subcmd != NULL) |
5055 { | |
5056 /* make "cmd.exe /c arguments" */ | |
5057 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
5058 newcmd = lalloc(cmdlen, TRUE); | |
5059 if (newcmd != NULL) | |
5060 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 5061 cmd_shell, subcmd); |
3363 | 5062 else |
5063 newcmd = cmdbase; | |
3367 | 5064 vim_free(subcmd); |
3363 | 5065 } |
5066 } | |
3361 | 5067 |
5068 /* | |
5069 * Now, start the command as a process, so that it doesn't | |
5070 * inherit our handles which causes unpleasant dangling swap | |
5071 * files if we exit before the spawned process | |
5072 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5073 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
|
5074 &si, &pi, NULL, NULL)) |
3361 | 5075 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
|
5076 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
|
5077 > (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
|
5078 x = 0; |
3361 | 5079 else |
5080 { | |
5081 x = -1; | |
5082 #ifdef FEAT_GUI_W32 | |
5083 EMSG(_("E371: Command not found")); | |
5084 #endif | |
5085 } | |
3363 | 5086 |
5087 if (newcmd != cmdbase) | |
5088 vim_free(newcmd); | |
5089 | |
5627 | 5090 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 5091 { |
5627 | 5092 /* Close the handle to \\.\NUL created above. */ |
3361 | 5093 CloseHandle(si.hStdInput); |
5094 } | |
5095 /* Close the handles to the subprocess, so that it goes away */ | |
5096 CloseHandle(pi.hThread); | |
5097 CloseHandle(pi.hProcess); | |
5098 } | |
5099 else | |
5100 { | |
3363 | 5101 cmdlen = ( |
7 | 5102 #ifdef FEAT_GUI_W32 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5103 (!p_stmp ? 0 : STRLEN(vimrun_path)) + |
7 | 5104 #endif |
1569 | 5105 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10); |
5106 | |
3361 | 5107 newcmd = lalloc(cmdlen, TRUE); |
5108 if (newcmd != NULL) | |
7 | 5109 { |
5110 #if defined(FEAT_GUI_W32) | |
5111 if (need_vimrun_warning) | |
5112 { | |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5113 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
|
5114 "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
|
5115 "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
|
5116 char *title = _("Vim Warning"); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5117 # ifdef FEAT_MBYTE |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5118 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
|
5119 { |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5120 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
|
5121 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
|
5122 |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5123 if (wmsg != NULL && wtitle != NULL) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5124 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5125 vim_free(wmsg); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5126 vim_free(wtitle); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5127 } |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5128 else |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5129 # endif |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5130 MessageBox(NULL, msg, title, MB_ICONWARNING); |
7 | 5131 need_vimrun_warning = FALSE; |
5132 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5133 if (!s_dont_use_vimrun && p_stmp) |
7 | 5134 /* Use vimrun to execute the command. It opens a console |
5135 * 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
|
5136 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 5137 vimrun_path, |
5138 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
5139 ? "-s " : "", | |
5140 p_sh, p_shcf, cmd); | |
5141 else | |
5142 #endif | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5143 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 5144 p_sh, p_shcf, cmd); |
7 | 5145 x = mch_system((char *)newcmd, options); |
3361 | 5146 vim_free(newcmd); |
7 | 5147 } |
5148 } | |
5149 } | |
5150 | |
5151 if (tmode == TMODE_RAW) | |
5152 settmode(TMODE_RAW); /* set to raw mode */ | |
5153 | |
5154 /* Print the return value, unless "vimrun" was used. */ | |
5155 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent | |
5156 #if defined(FEAT_GUI_W32) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5157 && ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) |
7 | 5158 #endif |
5159 ) | |
5160 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5161 smsg((char_u *)_("shell returned %d"), x); |
7 | 5162 msg_putchar('\n'); |
5163 } | |
5164 #ifdef FEAT_TITLE | |
5165 resettitle(); | |
5166 #endif | |
5167 | |
5168 signal(SIGINT, SIG_DFL); | |
5169 #if defined(__GNUC__) && !defined(__MINGW32__) | |
5170 signal(SIGKILL, SIG_DFL); | |
5171 #else | |
5172 signal(SIGBREAK, SIG_DFL); | |
5173 #endif | |
5174 signal(SIGILL, SIG_DFL); | |
5175 signal(SIGFPE, SIG_DFL); | |
5176 signal(SIGSEGV, SIG_DFL); | |
5177 signal(SIGTERM, SIG_DFL); | |
5178 signal(SIGABRT, SIG_DFL); | |
5179 | |
5180 return x; | |
5181 } | |
5182 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5183 #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
|
5184 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5185 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
|
5186 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
|
5187 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
|
5188 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
|
5189 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
|
5190 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
|
5191 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5192 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5193 HANDLE h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5194 # ifdef FEAT_MBYTE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5195 WCHAR *wn = NULL; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5196 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
|
5197 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5198 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
|
5199 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
|
5200 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5201 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
|
5202 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
|
5203 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
|
5204 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
|
5205 } |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5206 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5207 if (wn == NULL) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5208 # 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
|
5209 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
|
5210 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
|
5211 dwFlagsAndAttributes, NULL); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5212 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5213 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5214 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5215 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5216 * 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
|
5217 * 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
|
5218 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
5219 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
|
5220 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
|
5221 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5222 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
|
5223 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
|
5224 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
|
5225 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5226 /* 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
|
5227 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
|
5228 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5229 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5230 if (base) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5231 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5232 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
|
5233 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5234 /* 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
|
5235 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
|
5236 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5237 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5238 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
|
5239 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5240 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
|
5241 *((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
|
5242 p++; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5243 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5244 FreeEnvironmentStrings(base); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5245 *((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
|
5246 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5247 |
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
|
5248 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
|
5249 { |
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
|
5250 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
|
5251 { |
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
|
5252 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
|
5253 { |
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
|
5254 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
|
5255 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
|
5256 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
|
5257 --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
|
5258 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
|
5259 { |
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
|
5260 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
|
5261 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
|
5262 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
|
5263 |
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
|
5264 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
|
5265 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
|
5266 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
|
5267 *((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
|
5268 *((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
|
5269 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
|
5270 *((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
|
5271 *((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
|
5272 } |
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
|
5273 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
|
5274 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
|
5275 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5276 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5277 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5278 |
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
|
5279 # ifdef FEAT_CLIENTSERVER |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5280 if (is_terminal) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5281 { |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5282 char_u *servername = get_vim_var_str(VV_SEND_SERVER); |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5283 size_t lval = STRLEN(servername); |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5284 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
|
5285 |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5286 if (ga_grow(gap, (int)(14 + 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
|
5287 { |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5288 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
|
5289 *((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
|
5290 (WCHAR)"VIM_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
|
5291 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
|
5292 *((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
|
5293 (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
|
5294 *((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
|
5295 } |
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
|
5296 } |
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
|
5297 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5298 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5299 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5300 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5301 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
|
5302 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5303 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5304 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5305 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5306 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5307 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5308 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5309 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5310 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
|
5311 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5312 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5313 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
|
5314 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
|
5315 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
|
5316 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
|
5317 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
|
5318 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
|
5319 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
|
5320 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5321 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
|
5322 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5323 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5324 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5325 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5326 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5327 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5328 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5329 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
|
5330 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
|
5331 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5332 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5333 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5334 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5335 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5336 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5337 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5338 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5339 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
|
5340 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
|
5341 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5342 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5343 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5344 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5345 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5346 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5347 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5348 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5349 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5350 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5351 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5352 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5353 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5354 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
|
5355 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5356 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
|
5357 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5358 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5359 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
|
5360 { |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5361 EMSG2(_(e_notopen), fname); |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5362 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5363 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5364 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5365 else if (!use_null_for_in && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5366 (!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
|
5367 || !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
|
5368 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5369 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5370 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5371 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5372 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
|
5373 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5374 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
|
5375 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5376 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5377 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
|
5378 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5379 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5380 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5381 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5382 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5383 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5384 (!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
|
5385 || !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
|
5386 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5387 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5388 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5389 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5390 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
|
5391 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5392 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
|
5393 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5394 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5395 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
|
5396 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5397 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5398 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5399 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5400 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5401 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
|
5402 (!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
|
5403 || !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
|
5404 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5405 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5406 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5407 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5408 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5409 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
|
5410 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5411 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
|
5412 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5413 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5414 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5415 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5416 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5417 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5418 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5419 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5420 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5421 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5422 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5423 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5424 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5425 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
|
5426 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5427 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5428 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
|
5429 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5430 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
|
5431 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5432 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
|
5433 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5434 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5435 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5436 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5437 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5438 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5439 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5440 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
|
5441 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5442 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5443 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5444 /* 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
|
5445 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5446 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5447 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5448 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5449 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5450 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5451 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5452 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5453 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5454 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5455 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5456 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5457 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
|
5458 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5459 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5460 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5461 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5462 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5463 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5464 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
|
5465 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5466 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
|
5467 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5468 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
|
5469 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5470 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5471 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5472 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5473 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5474 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5475 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5476 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5477 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5478 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5479 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5480 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5481 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
|
5482 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5483 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5484 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5485 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5486 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5487 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5488 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5489 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5490 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
|
5491 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5492 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5493 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5494 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
|
5495 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5496 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
|
5497 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5498 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5499 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5500 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5501 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5502 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5503 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5504 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5505 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
|
5506 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5507 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5508 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5509 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5510 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5511 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5512 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5513 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5514 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5515 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5516 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
|
5517 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5518 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5519 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5520 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5521 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
|
5522 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5523 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5524 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5525 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5526 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5527 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5528 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5529 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
|
5530 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5531 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
|
5532 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5533 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
|
5534 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5535 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5536 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5537 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5538 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5539 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5540 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5541 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5542 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5543 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5544 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5545 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5546 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5547 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5548 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5549 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5550 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5551 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5552 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5553 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5554 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5555 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5556 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5557 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5558 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5559 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5560 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5561 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5562 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5563 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5564 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5565 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5566 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5567 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5568 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5569 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5570 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5571 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5572 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5573 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5574 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5575 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5576 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5577 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5578 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5579 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5580 * 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
|
5581 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5582 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5583 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
|
5584 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5585 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5586 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5587 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
|
5588 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5589 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5590 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5591 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
|
5592 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
|
5593 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5594 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5595 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
|
5596 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5597 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5598 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
|
5599 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5600 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5601 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5602 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5603 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5604 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5605 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5606 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5607 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5608 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5609 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5610 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5611 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5612 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5613 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5614 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5615 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5616 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5617 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5618 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5619 |
7 | 5620 |
5621 #ifndef FEAT_GUI_W32 | |
5622 | |
5623 /* | |
5624 * Start termcap mode | |
5625 */ | |
5626 static void | |
5627 termcap_mode_start(void) | |
5628 { | |
5629 DWORD cmodein; | |
5630 | |
5631 if (g_fTermcapMode) | |
5632 return; | |
5633 | |
5634 SaveConsoleBuffer(&g_cbNonTermcap); | |
5635 | |
5636 if (g_cbTermcap.IsValid) | |
5637 { | |
5638 /* | |
5639 * We've been in termcap mode before. Restore certain screen | |
5640 * characteristics, including the buffer size and the window | |
5641 * size. Since we will be redrawing the screen, we don't need | |
5642 * to restore the actual contents of the buffer. | |
5643 */ | |
5644 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
|
5645 reset_console_color_rgb(); |
7 | 5646 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5647 Rows = g_cbTermcap.Info.dwSize.Y; | |
5648 Columns = g_cbTermcap.Info.dwSize.X; | |
5649 } | |
5650 else | |
5651 { | |
5652 /* | |
5653 * This is our first time entering termcap mode. Clear the console | |
5654 * screen buffer, and resize the buffer to match the current window | |
5655 * size. We will use this as the size of our editing environment. | |
5656 */ | |
5657 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
|
5658 set_console_color_rgb(); |
7 | 5659 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5660 } | |
5661 | |
5662 #ifdef FEAT_TITLE | |
5663 resettitle(); | |
5664 #endif | |
5665 | |
5666 GetConsoleMode(g_hConIn, &cmodein); | |
5667 #ifdef FEAT_MOUSE | |
5668 if (g_fMouseActive) | |
5669 cmodein |= ENABLE_MOUSE_INPUT; | |
5670 else | |
5671 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5672 #endif | |
5673 cmodein |= ENABLE_WINDOW_INPUT; | |
5674 SetConsoleMode(g_hConIn, cmodein); | |
5675 | |
5676 redraw_later_clear(); | |
5677 g_fTermcapMode = TRUE; | |
5678 } | |
5679 | |
5680 | |
5681 /* | |
5682 * End termcap mode | |
5683 */ | |
5684 static void | |
5685 termcap_mode_end(void) | |
5686 { | |
5687 DWORD cmodein; | |
5688 ConsoleBuffer *cb; | |
5689 COORD coord; | |
5690 DWORD dwDummy; | |
5691 | |
5692 if (!g_fTermcapMode) | |
5693 return; | |
5694 | |
5695 SaveConsoleBuffer(&g_cbTermcap); | |
5696 | |
5697 GetConsoleMode(g_hConIn, &cmodein); | |
5698 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5699 SetConsoleMode(g_hConIn, cmodein); | |
5700 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5701 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5702 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5703 #else |
7 | 5704 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5705 #endif |
7 | 5706 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
|
5707 reset_console_color_rgb(); |
7 | 5708 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5709 | |
5710 if (p_rs || exiting) | |
5711 { | |
5712 /* | |
5713 * Clear anything that happens to be on the current line. | |
5714 */ | |
5715 coord.X = 0; | |
5716 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5717 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5718 cb->Info.dwSize.X, coord, &dwDummy); | |
5719 /* | |
5720 * The following is just for aesthetics. If we are exiting without | |
5721 * restoring the screen, then we want to have a prompt string | |
5722 * appear at the bottom line. However, the command interpreter | |
5723 * seems to always advance the cursor one line before displaying | |
5724 * the prompt string, which causes the screen to scroll. To | |
5725 * counter this, move the cursor up one line before exiting. | |
5726 */ | |
5727 if (exiting && !p_rs) | |
5728 coord.Y--; | |
5729 /* | |
5730 * Position the cursor at the leftmost column of the desired row. | |
5731 */ | |
5732 SetConsoleCursorPosition(g_hConOut, coord); | |
5733 } | |
5734 | |
5735 g_fTermcapMode = FALSE; | |
5736 } | |
5737 #endif /* FEAT_GUI_W32 */ | |
5738 | |
5739 | |
5740 #ifdef FEAT_GUI_W32 | |
5741 void | |
5742 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
|
5743 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
|
5744 int len UNUSED) |
7 | 5745 { |
5746 /* never used */ | |
5747 } | |
5748 | |
5749 #else | |
5750 | |
5751 /* | |
5752 * clear `n' chars, starting from `coord' | |
5753 */ | |
5754 static void | |
5755 clear_chars( | |
5756 COORD coord, | |
5757 DWORD n) | |
5758 { | |
5759 DWORD dwDummy; | |
5760 | |
5761 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
|
5762 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5763 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
|
5764 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
|
5765 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5766 FillConsoleOutputAttribute(g_hConOut, 0, n, coord, &dwDummy); |
7 | 5767 } |
5768 | |
5769 | |
5770 /* | |
5771 * Clear the screen | |
5772 */ | |
5773 static void | |
5774 clear_screen(void) | |
5775 { | |
5776 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
|
5777 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5778 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
|
5779 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
|
5780 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5781 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5782 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
|
5783 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
|
5784 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
|
5785 } |
7 | 5786 } |
5787 | |
5788 | |
5789 /* | |
5790 * Clear to end of display | |
5791 */ | |
5792 static void | |
5793 clear_to_end_of_display(void) | |
5794 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5795 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
|
5796 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5797 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
|
5798 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5799 * 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
|
5800 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5801 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5802 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
|
5803 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
|
5804 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
|
5805 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5806 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
|
5807 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
|
5808 } |
7 | 5809 } |
5810 | |
5811 | |
5812 /* | |
5813 * Clear to end of line | |
5814 */ | |
5815 static void | |
5816 clear_to_end_of_line(void) | |
5817 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5818 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
|
5819 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5820 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
|
5821 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
|
5822 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5823 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5824 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
|
5825 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
|
5826 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
|
5827 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5828 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
|
5829 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
|
5830 } |
7 | 5831 } |
5832 | |
5833 | |
5834 /* | |
5835 * Scroll the scroll region up by `cLines' lines | |
5836 */ | |
5837 static void | |
26 | 5838 scroll(unsigned cLines) |
7 | 5839 { |
5840 COORD oldcoord = g_coord; | |
5841 | |
5842 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5843 delete_lines(cLines); | |
5844 | |
5845 g_coord = oldcoord; | |
5846 } | |
5847 | |
5848 | |
5849 /* | |
5850 * Set the scroll region | |
5851 */ | |
5852 static void | |
5853 set_scroll_region( | |
5854 unsigned left, | |
5855 unsigned top, | |
5856 unsigned right, | |
5857 unsigned bottom) | |
5858 { | |
5859 if (left >= right | |
5860 || top >= bottom | |
5861 || right > (unsigned) Columns - 1 | |
5862 || bottom > (unsigned) Rows - 1) | |
5863 return; | |
5864 | |
5865 g_srScrollRegion.Left = left; | |
5866 g_srScrollRegion.Top = top; | |
5867 g_srScrollRegion.Right = right; | |
5868 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
|
5869 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5870 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
|
5871 vtp_printf("\033[%d;%dr", top + 1, bottom + 1); |
7 | 5872 } |
5873 | |
5874 | |
5875 /* | |
5876 * Insert `cLines' lines at the current cursor position | |
5877 */ | |
5878 static void | |
26 | 5879 insert_lines(unsigned cLines) |
7 | 5880 { |
5881 SMALL_RECT source; | |
5882 COORD dest; | |
5883 CHAR_INFO fill; | |
5884 | |
5885 dest.X = 0; | |
5886 dest.Y = g_coord.Y + cLines; | |
5887 | |
5888 source.Left = 0; | |
5889 source.Top = g_coord.Y; | |
5890 source.Right = g_srScrollRegion.Right; | |
5891 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5892 | |
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 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
|
5894 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5895 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
|
5896 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
|
5897 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5898 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
|
5899 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5900 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5901 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5902 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
|
5903 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5904 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
|
5905 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
|
5906 } |
7 | 5907 |
5908 /* Here we have to deal with a win32 console flake: If the scroll | |
5909 * region looks like abc and we scroll c to a and fill with d we get | |
5910 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5911 * vim expects cdd consistently... So we have to deal with that | |
5912 * here... (this also occurs scrolling the same way in the other | |
5913 * direction). */ | |
5914 | |
5915 if (source.Bottom < dest.Y) | |
5916 { | |
5917 COORD coord; | |
5918 | |
5919 coord.X = 0; | |
5920 coord.Y = source.Bottom; | |
5921 clear_chars(coord, Columns * (dest.Y - source.Bottom)); | |
5922 } | |
5923 } | |
5924 | |
5925 | |
5926 /* | |
5927 * Delete `cLines' lines at the current cursor position | |
5928 */ | |
5929 static void | |
26 | 5930 delete_lines(unsigned cLines) |
7 | 5931 { |
5932 SMALL_RECT source; | |
5933 COORD dest; | |
5934 CHAR_INFO fill; | |
5935 int nb; | |
5936 | |
5937 dest.X = 0; | |
5938 dest.Y = g_coord.Y; | |
5939 | |
5940 source.Left = 0; | |
5941 source.Top = g_coord.Y + cLines; | |
5942 source.Right = g_srScrollRegion.Right; | |
5943 source.Bottom = g_srScrollRegion.Bottom; | |
5944 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5945 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
|
5946 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5947 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
|
5948 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
|
5949 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5950 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
|
5951 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5952 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5953 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5954 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
|
5955 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5956 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
|
5957 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
|
5958 } |
7 | 5959 |
5960 /* Here we have to deal with a win32 console flake: If the scroll | |
5961 * region looks like abc and we scroll c to a and fill with d we get | |
5962 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5963 * vim expects cdd consistently... So we have to deal with that | |
5964 * here... (this also occurs scrolling the same way in the other | |
5965 * direction). */ | |
5966 | |
5967 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5968 | |
5969 if (nb < source.Top) | |
5970 { | |
5971 COORD coord; | |
5972 | |
5973 coord.X = 0; | |
5974 coord.Y = nb; | |
5975 clear_chars(coord, Columns * (source.Top - nb)); | |
5976 } | |
5977 } | |
5978 | |
5979 | |
5980 /* | |
5981 * Set the cursor position | |
5982 */ | |
5983 static void | |
5984 gotoxy( | |
5985 unsigned x, | |
5986 unsigned y) | |
5987 { | |
5988 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
5989 return; | |
5990 | |
5991 /* external cursor coords are 1-based; internal are 0-based */ | |
5992 g_coord.X = x - 1; | |
5993 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
|
5994 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5995 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
|
5996 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
|
5997 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5998 vtp_printf("\033[%d;%dH", y, x); |
7 | 5999 } |
6000 | |
6001 | |
6002 /* | |
6003 * Set the current text attribute = (foreground | background) | |
6004 * See ../doc/os_win32.txt for the numbers. | |
6005 */ | |
6006 static void | |
26 | 6007 textattr(WORD wAttr) |
7 | 6008 { |
6710 | 6009 g_attrCurrent = wAttr & 0xff; |
7 | 6010 |
6011 SetConsoleTextAttribute(g_hConOut, wAttr); | |
6012 } | |
6013 | |
6014 | |
6015 static void | |
26 | 6016 textcolor(WORD wAttr) |
7 | 6017 { |
6710 | 6018 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 6019 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6020 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
|
6021 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
|
6022 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6023 vtp_sgr_bulk(wAttr); |
7 | 6024 } |
6025 | |
6026 | |
6027 static void | |
26 | 6028 textbackground(WORD wAttr) |
7 | 6029 { |
6710 | 6030 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 6031 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6032 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
|
6033 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
|
6034 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6035 vtp_sgr_bulk(wAttr); |
7 | 6036 } |
6037 | |
6038 | |
6039 /* | |
6040 * restore the default text attribute (whatever we started with) | |
6041 */ | |
6042 static void | |
26 | 6043 normvideo(void) |
7 | 6044 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6045 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
|
6046 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
|
6047 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6048 vtp_sgr_bulk(0); |
7 | 6049 } |
6050 | |
6051 | |
6052 static WORD g_attrPreStandout = 0; | |
6053 | |
6054 /* | |
6055 * Make the text standout, by brightening it | |
6056 */ | |
6057 static void | |
6058 standout(void) | |
6059 { | |
6060 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
|
6061 |
7 | 6062 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
6063 } | |
6064 | |
6065 | |
6066 /* | |
6067 * Turn off standout mode | |
6068 */ | |
6069 static void | |
26 | 6070 standend(void) |
7 | 6071 { |
6072 if (g_attrPreStandout) | |
6073 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
|
6074 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6075 g_attrPreStandout = 0; |
7 | 6076 } |
6077 | |
6078 | |
6079 /* | |
1199 | 6080 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 6081 */ |
6082 void | |
26 | 6083 mch_set_normal_colors(void) |
7 | 6084 { |
6085 char_u *p; | |
6086 int n; | |
6087 | |
6088 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
6089 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
|
6090 if ( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6091 #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
|
6092 !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
|
6093 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6094 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 6095 { |
6096 p = T_ME + 2; | |
6097 n = getdigits(&p); | |
6098 if (*p == 'm' && n > 0) | |
6099 { | |
6100 cterm_normal_fg_color = (n & 0xf) + 1; | |
6101 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
6102 } | |
6103 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6104 #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
|
6105 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
|
6106 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
|
6107 #endif |
7 | 6108 } |
6109 | |
6110 | |
6111 /* | |
6112 * visual bell: flash the screen | |
6113 */ | |
6114 static void | |
26 | 6115 visual_bell(void) |
7 | 6116 { |
6117 COORD coordOrigin = {0, 0}; | |
6118 WORD attrFlash = ~g_attrCurrent & 0xff; | |
6119 | |
6120 DWORD dwDummy; | |
6121 LPWORD oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD)); | |
6122 | |
6123 if (oldattrs == NULL) | |
6124 return; | |
6125 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
6126 coordOrigin, &dwDummy); | |
6127 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
6128 coordOrigin, &dwDummy); | |
6129 | |
6130 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
|
6131 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
|
6132 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 6133 coordOrigin, &dwDummy); |
6134 vim_free(oldattrs); | |
6135 } | |
6136 | |
6137 | |
6138 /* | |
6139 * Make the cursor visible or invisible | |
6140 */ | |
6141 static void | |
26 | 6142 cursor_visible(BOOL fVisible) |
7 | 6143 { |
6144 s_cursor_visible = fVisible; | |
6145 #ifdef MCH_CURSOR_SHAPE | |
6146 mch_update_cursor(); | |
6147 #endif | |
6148 } | |
6149 | |
6150 | |
6151 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6152 * 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
|
6153 * Returns the number of bytes actually written (at least one). |
7 | 6154 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6155 static DWORD |
7 | 6156 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6157 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6158 DWORD cbToWrite) |
7 | 6159 { |
6160 COORD coord = g_coord; | |
6161 DWORD written; | |
6162 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6163 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6164 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
|
6165 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6166 static WCHAR *unicodebuf = NULL; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6167 static int unibuflen = 0; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6168 int length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6169 DWORD n, cchwritten, cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6170 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6171 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
|
6172 if (unicodebuf == NULL || length > unibuflen) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6173 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6174 vim_free(unicodebuf); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6175 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
|
6176 unibuflen = length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6177 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6178 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
|
6179 unicodebuf, unibuflen); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6180 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6181 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
|
6182 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6183 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
|
6184 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6185 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
|
6186 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
|
6187 /* 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
|
6188 * 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
|
6189 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
|
6190 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
|
6191 || 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
|
6192 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
|
6193 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6194 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6195 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6196 if (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
|
6197 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
|
6198 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
|
6199 } |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6200 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6201 if (cchwritten == length) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6202 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6203 written = cbToWrite; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6204 g_coord.X += (SHORT)cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6205 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6206 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6207 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6208 char_u *p = pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6209 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
|
6210 MB_CPTR_ADV(p); |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6211 written = p - pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6212 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
|
6213 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6214 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6215 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6216 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6217 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6218 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6219 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6220 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
|
6221 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
|
6222 /* 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
|
6223 * 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
|
6224 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
|
6225 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
|
6226 || 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
|
6227 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
|
6228 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6229 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6230 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6231 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
|
6232 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
|
6233 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
|
6234 } |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6235 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6236 g_coord.X += (SHORT) written; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6237 } |
7 | 6238 |
6239 while (g_coord.X > g_srScrollRegion.Right) | |
6240 { | |
6241 g_coord.X -= (SHORT) Columns; | |
6242 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6243 g_coord.Y++; | |
6244 } | |
6245 | |
6246 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6247 | |
6248 return written; | |
6249 } | |
6250 | |
6251 | |
6252 /* | |
6253 * mch_write(): write the output buffer to the screen, translating ESC | |
6254 * sequences into calls to console output routines. | |
6255 */ | |
6256 void | |
6257 mch_write( | |
6258 char_u *s, | |
6259 int len) | |
6260 { | |
6261 s[len] = NUL; | |
6262 | |
6263 if (!term_console) | |
6264 { | |
6265 write(1, s, (unsigned)len); | |
6266 return; | |
6267 } | |
6268 | |
6269 /* translate ESC | sequences into faked bios calls */ | |
6270 while (len--) | |
6271 { | |
6272 /* optimization: use one single write_chars for runs of text, | |
6273 * 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
|
6274 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 6275 |
6276 if (p_wd) | |
6277 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6278 WaitForChar(p_wd, FALSE); |
7 | 6279 if (prefix != 0) |
6280 prefix = 1; | |
6281 } | |
6282 | |
6283 if (prefix != 0) | |
6284 { | |
6285 DWORD nWritten; | |
6286 | |
6287 nWritten = write_chars(s, prefix); | |
6288 #ifdef MCH_WRITE_DUMP | |
6289 if (fdDump) | |
6290 { | |
6291 fputc('>', fdDump); | |
6292 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6293 fputs("<\n", fdDump); | |
6294 } | |
6295 #endif | |
6296 len -= (nWritten - 1); | |
6297 s += nWritten; | |
6298 } | |
6299 else if (s[0] == '\n') | |
6300 { | |
6301 /* \n, newline: go to the beginning of the next line or scroll */ | |
6302 if (g_coord.Y == g_srScrollRegion.Bottom) | |
6303 { | |
6304 scroll(1); | |
6305 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6306 } | |
6307 else | |
6308 { | |
6309 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6310 } | |
6311 #ifdef MCH_WRITE_DUMP | |
6312 if (fdDump) | |
6313 fputs("\\n\n", fdDump); | |
6314 #endif | |
6315 s++; | |
6316 } | |
6317 else if (s[0] == '\r') | |
6318 { | |
6319 /* \r, carriage return: go to beginning of line */ | |
6320 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
6321 #ifdef MCH_WRITE_DUMP | |
6322 if (fdDump) | |
6323 fputs("\\r\n", fdDump); | |
6324 #endif | |
6325 s++; | |
6326 } | |
6327 else if (s[0] == '\b') | |
6328 { | |
6329 /* \b, backspace: move cursor one position left */ | |
6330 if (g_coord.X > g_srScrollRegion.Left) | |
6331 g_coord.X--; | |
6332 else if (g_coord.Y > g_srScrollRegion.Top) | |
6333 { | |
6334 g_coord.X = g_srScrollRegion.Right; | |
6335 g_coord.Y--; | |
6336 } | |
6337 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6338 #ifdef MCH_WRITE_DUMP | |
6339 if (fdDump) | |
6340 fputs("\\b\n", fdDump); | |
6341 #endif | |
6342 s++; | |
6343 } | |
6344 else if (s[0] == '\a') | |
6345 { | |
6346 /* \a, bell */ | |
6347 MessageBeep(0xFFFFFFFF); | |
6348 #ifdef MCH_WRITE_DUMP | |
6349 if (fdDump) | |
6350 fputs("\\a\n", fdDump); | |
6351 #endif | |
6352 s++; | |
6353 } | |
6354 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6355 { | |
6356 #ifdef MCH_WRITE_DUMP | |
24 | 6357 char_u *old_s = s; |
7 | 6358 #endif |
24 | 6359 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
|
6360 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
7 | 6361 |
6362 switch (s[2]) | |
6363 { | |
6364 case '0': case '1': case '2': case '3': case '4': | |
6365 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
|
6366 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
|
6367 do |
7 | 6368 { |
6369 ++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
|
6370 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
|
6371 argc += (argc < 15) ? 1 : 0; |
7 | 6372 if (p > s + len) |
6373 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
|
6374 } 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
|
6375 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6376 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
|
6377 break; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6378 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6379 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
|
6380 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
|
6381 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
|
6382 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6383 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
|
6384 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6385 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
|
6386 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6387 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
|
6388 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
|
6389 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6390 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
|
6391 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6392 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
|
6393 vtp_sgr_bulks(argc, args); |
7 | 6394 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6395 else if (argc == 2 && *p == 'H') |
7 | 6396 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6397 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
|
6398 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6399 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
|
6400 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6401 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
|
6402 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6403 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
|
6404 { |
7 | 6405 gotoxy(g_coord.X + 1, |
6406 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6407 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6408 else if (argc == 1 && *p == 'b') |
7 | 6409 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6410 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
|
6411 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6412 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
|
6413 { |
7 | 6414 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6415 g_coord.Y + 1); | |
6416 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6417 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
|
6418 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6419 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
|
6420 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6421 else if (argc == 1 && *p == 'H') |
7 | 6422 { |
6423 gotoxy(1, arg1); | |
6424 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6425 else if (argc == 1 && *p == 'L') |
7 | 6426 { |
6427 insert_lines(arg1); | |
6428 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6429 else if (argc == 1 && *p == 'M') |
7 | 6430 { |
6431 delete_lines(arg1); | |
6432 } | |
6433 | |
835 | 6434 len -= (int)(p - s); |
7 | 6435 s = p + 1; |
6436 break; | |
6437 | |
6438 case 'A': | |
6439 gotoxy(g_coord.X + 1, | |
6440 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6441 goto got3; | |
6442 | |
6443 case 'B': | |
6444 visual_bell(); | |
6445 goto got3; | |
6446 | |
6447 case 'C': | |
6448 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6449 g_coord.Y + 1); | |
6450 goto got3; | |
6451 | |
6452 case 'E': | |
6453 termcap_mode_end(); | |
6454 goto got3; | |
6455 | |
6456 case 'F': | |
6457 standout(); | |
6458 goto got3; | |
6459 | |
6460 case 'f': | |
6461 standend(); | |
6462 goto got3; | |
6463 | |
6464 case 'H': | |
6465 gotoxy(1, 1); | |
6466 goto got3; | |
6467 | |
6468 case 'j': | |
6469 clear_to_end_of_display(); | |
6470 goto got3; | |
6471 | |
6472 case 'J': | |
6473 clear_screen(); | |
6474 goto got3; | |
6475 | |
6476 case 'K': | |
6477 clear_to_end_of_line(); | |
6478 goto got3; | |
6479 | |
6480 case 'L': | |
6481 insert_lines(1); | |
6482 goto got3; | |
6483 | |
6484 case 'M': | |
6485 delete_lines(1); | |
6486 goto got3; | |
6487 | |
6488 case 'S': | |
6489 termcap_mode_start(); | |
6490 goto got3; | |
6491 | |
6492 case 'V': | |
6493 cursor_visible(TRUE); | |
6494 goto got3; | |
6495 | |
6496 case 'v': | |
6497 cursor_visible(FALSE); | |
6498 goto got3; | |
6499 | |
6500 got3: | |
6501 s += 3; | |
6502 len -= 2; | |
6503 } | |
6504 | |
6505 #ifdef MCH_WRITE_DUMP | |
6506 if (fdDump) | |
6507 { | |
6508 fputs("ESC | ", fdDump); | |
6509 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6510 fputc('\n', fdDump); | |
6511 } | |
6512 #endif | |
6513 } | |
6514 else | |
6515 { | |
6516 /* Write a single character */ | |
6517 DWORD nWritten; | |
6518 | |
6519 nWritten = write_chars(s, 1); | |
6520 #ifdef MCH_WRITE_DUMP | |
6521 if (fdDump) | |
6522 { | |
6523 fputc('>', fdDump); | |
6524 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6525 fputs("<\n", fdDump); | |
6526 } | |
6527 #endif | |
6528 | |
6529 len -= (nWritten - 1); | |
6530 s += nWritten; | |
6531 } | |
6532 } | |
6533 | |
6534 #ifdef MCH_WRITE_DUMP | |
6535 if (fdDump) | |
6536 fflush(fdDump); | |
6537 #endif | |
6538 } | |
6539 | |
6540 #endif /* FEAT_GUI_W32 */ | |
6541 | |
6542 | |
6543 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6544 * Delay for "msec" milliseconds. |
7 | 6545 */ |
6546 void | |
6547 mch_delay( | |
6548 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
|
6549 int ignoreinput UNUSED) |
7 | 6550 { |
6551 #ifdef FEAT_GUI_W32 | |
6552 Sleep((int)msec); /* never wait for input */ | |
14 | 6553 #else /* Console */ |
7 | 6554 if (ignoreinput) |
14 | 6555 # ifdef FEAT_MZSCHEME |
6556 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6557 { | |
6558 int towait = p_mzq; | |
6559 | |
6560 /* if msec is large enough, wait by portions in p_mzq */ | |
6561 while (msec > 0) | |
6562 { | |
6563 mzvim_check_threads(); | |
6564 if (msec < towait) | |
6565 towait = msec; | |
6566 Sleep(towait); | |
6567 msec -= towait; | |
6568 } | |
6569 } | |
6570 else | |
6571 # endif | |
6572 Sleep((int)msec); | |
7 | 6573 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6574 WaitForChar(msec, FALSE); |
7 | 6575 #endif |
6576 } | |
6577 | |
6578 | |
6579 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6580 * 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
|
6581 * This can also remove a symbolic link like Unix. |
7 | 6582 * Return 0 for success, -1 for failure. |
6583 */ | |
6584 int | |
6585 mch_remove(char_u *name) | |
6586 { | |
6587 #ifdef FEAT_MBYTE | |
6588 WCHAR *wn = NULL; | |
6589 int n; | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6590 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6591 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6592 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6593 * 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
|
6594 * 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
|
6595 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6596 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
|
6597 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6598 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6599 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6600 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6601 #ifdef FEAT_MBYTE |
7 | 6602 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6603 { | |
1752 | 6604 wn = enc_to_utf16(name, NULL); |
7 | 6605 if (wn != NULL) |
6606 { | |
6607 n = DeleteFileW(wn) ? 0 : -1; | |
6608 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6609 return n; |
7 | 6610 } |
6611 } | |
6612 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6613 return DeleteFile((LPCSTR)name) ? 0 : -1; |
7 | 6614 } |
6615 | |
6616 | |
6617 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6618 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6619 */ |
6620 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6621 mch_breakcheck(int force) |
7 | 6622 { |
6623 #ifndef FEAT_GUI_W32 /* never used */ | |
6624 if (g_fCtrlCPressed || g_fCBrkPressed) | |
6625 { | |
12066
8ad282dee649
patch 8.0.0913: MS-Windows: CTRL-C kills shell in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12050
diff
changeset
|
6626 ctrl_break_was_pressed = g_fCBrkPressed; |
7 | 6627 g_fCtrlCPressed = g_fCBrkPressed = FALSE; |
6628 got_int = TRUE; | |
6629 } | |
6630 #endif | |
6631 } | |
6632 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6633 /* 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
|
6634 #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
|
6635 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6636 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6637 * 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
|
6638 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6639 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
|
6640 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
|
6641 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6642 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6643 |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6644 PlatformId(); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6645 /* 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
|
6646 * 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
|
6647 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6648 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6649 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6650 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6651 /* 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
|
6652 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
|
6653 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6654 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
|
6655 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6656 /* 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
|
6657 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
|
6658 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6659 /* 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
|
6660 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
|
6661 } |
7 | 6662 |
6663 #ifdef FEAT_MBYTE | |
6664 /* | |
6665 * Same code as below, but with wide functions and no comments. | |
6666 * Return 0 for success, non-zero for failure. | |
6667 */ | |
6668 int | |
6669 mch_wrename(WCHAR *wold, WCHAR *wnew) | |
6670 { | |
6671 WCHAR *p; | |
6672 int i; | |
6673 WCHAR szTempFile[_MAX_PATH + 1]; | |
6674 WCHAR szNewPath[_MAX_PATH + 1]; | |
6675 HANDLE hf; | |
6676 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6677 p = wold; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6678 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
|
6679 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
|
6680 && wold[i + 1] != 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6681 p = wold + i + 1; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6682 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
|
6683 return (MoveFileW(wold, wnew) == 0); |
7 | 6684 |
6685 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) | |
6686 return -1; | |
6687 *p = NUL; | |
6688 | |
6689 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) | |
6690 return -2; | |
6691 | |
6692 if (!DeleteFileW(szTempFile)) | |
6693 return -3; | |
6694 | |
6695 if (!MoveFileW(wold, szTempFile)) | |
6696 return -4; | |
6697 | |
6698 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6699 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6700 return -5; | |
6701 if (!CloseHandle(hf)) | |
6702 return -6; | |
6703 | |
6704 if (!MoveFileW(szTempFile, wnew)) | |
6705 { | |
6706 (void)MoveFileW(szTempFile, wold); | |
6707 return -7; | |
6708 } | |
6709 | |
6710 DeleteFileW(szTempFile); | |
6711 | |
6712 if (!DeleteFileW(wold)) | |
6713 return -8; | |
6714 | |
6715 return 0; | |
6716 } | |
6717 #endif | |
6718 | |
6719 | |
6720 /* | |
6721 * mch_rename() works around a bug in rename (aka MoveFile) in | |
6722 * Windows 95: rename("foo.bar", "foo.bar~") will generate a | |
6723 * file whose short file name is "FOO.BAR" (its long file name will | |
6724 * be correct: "foo.bar~"). Because a file can be accessed by | |
6725 * either its SFN or its LFN, "foo.bar" has effectively been | |
6726 * renamed to "foo.bar", which is not at all what was wanted. This | |
6727 * seems to happen only when renaming files with three-character | |
6728 * extensions by appending a suffix that does not include ".". | |
6729 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6730 * | |
6731 * There is another problem, which isn't really a bug but isn't right either: | |
6732 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6733 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6734 * service pack 6. Doesn't seem to happen on Windows 98. | |
6735 * | |
6736 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6737 * Should probably set errno appropriately when errors occur. | |
6738 */ | |
6739 int | |
6740 mch_rename( | |
6741 const char *pszOldFile, | |
6742 const char *pszNewFile) | |
6743 { | |
6744 char szTempFile[_MAX_PATH+1]; | |
6745 char szNewPath[_MAX_PATH+1]; | |
6746 char *pszFilePart; | |
6747 HANDLE hf; | |
6748 #ifdef FEAT_MBYTE | |
6749 WCHAR *wold = NULL; | |
6750 WCHAR *wnew = NULL; | |
6751 int retval = -1; | |
6752 | |
6753 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
6754 { | |
1752 | 6755 wold = enc_to_utf16((char_u *)pszOldFile, NULL); |
6756 wnew = enc_to_utf16((char_u *)pszNewFile, NULL); | |
7 | 6757 if (wold != NULL && wnew != NULL) |
6758 retval = mch_wrename(wold, wnew); | |
6759 vim_free(wold); | |
6760 vim_free(wnew); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6761 return retval; |
7 | 6762 } |
6763 #endif | |
6764 | |
6765 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6766 * 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
|
6767 * seventh character. |
7 | 6768 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6769 pszFilePart = (char *)gettail((char_u *)pszOldFile); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6770 if (STRLEN(pszFilePart) < 8 || pszFilePart[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6771 return rename(pszOldFile, pszNewFile); |
7 | 6772 |
6773 /* Get base path of new file name. Undocumented feature: If pszNewFile is | |
6774 * a directory, no error is returned and pszFilePart will be NULL. */ | |
6775 if (GetFullPathName(pszNewFile, _MAX_PATH, szNewPath, &pszFilePart) == 0 | |
6776 || pszFilePart == NULL) | |
6777 return -1; | |
6778 *pszFilePart = NUL; | |
6779 | |
6780 /* Get (and create) a unique temporary file name in directory of new file */ | |
6781 if (GetTempFileName(szNewPath, "VIM", 0, szTempFile) == 0) | |
6782 return -2; | |
6783 | |
6784 /* blow the temp file away */ | |
6785 if (!DeleteFile(szTempFile)) | |
6786 return -3; | |
6787 | |
6788 /* rename old file to the temp file */ | |
6789 if (!MoveFile(pszOldFile, szTempFile)) | |
6790 return -4; | |
6791 | |
6792 /* now create an empty file called pszOldFile; this prevents the operating | |
6793 * system using pszOldFile as an alias (SFN) if we're renaming within the | |
6794 * same directory. For example, we're editing a file called | |
6795 * filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt | |
6796 * to filena~1.txt~ (i.e., we're making a backup while writing it), the | |
6797 * SFN for filena~1.txt~ will be filena~1.txt, by default, which will | |
39 | 6798 * cause all sorts of problems later in buf_write(). So, we create an |
6799 * empty file called filena~1.txt and the system will have to find some | |
6800 * other SFN for filena~1.txt~, such as filena~2.txt | |
7 | 6801 */ |
6802 if ((hf = CreateFile(pszOldFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6803 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6804 return -5; | |
6805 if (!CloseHandle(hf)) | |
6806 return -6; | |
6807 | |
6808 /* rename the temp file to the new file */ | |
6809 if (!MoveFile(szTempFile, pszNewFile)) | |
6810 { | |
6811 /* Renaming failed. Rename the file back to its old name, so that it | |
6812 * looks like nothing happened. */ | |
6813 (void)MoveFile(szTempFile, pszOldFile); | |
6814 | |
6815 return -7; | |
6816 } | |
6817 | |
6818 /* Seems to be left around on Novell filesystems */ | |
6819 DeleteFile(szTempFile); | |
6820 | |
6821 /* finally, remove the empty old file */ | |
6822 if (!DeleteFile(pszOldFile)) | |
6823 return -8; | |
6824 | |
6825 return 0; /* success */ | |
6826 } | |
6827 | |
6828 /* | |
6829 * Get the default shell for the current hardware platform | |
6830 */ | |
6831 char * | |
26 | 6832 default_shell(void) |
7 | 6833 { |
6834 PlatformId(); | |
6835 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6836 return "cmd.exe"; |
7 | 6837 } |
6838 | |
6839 /* | |
6840 * mch_access() extends access() to do more detailed check on network drives. | |
6841 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6842 */ | |
6843 int | |
6844 mch_access(char *n, int p) | |
6845 { | |
6846 HANDLE hFile; | |
6847 DWORD am; | |
6848 int retval = -1; /* default: fail */ | |
6849 #ifdef FEAT_MBYTE | |
6850 WCHAR *wn = NULL; | |
6851 | |
6852 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
|
6853 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
|
6854 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6855 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6856 if (mch_isdir((char_u *)n)) |
7 | 6857 { |
6858 char TempName[_MAX_PATH + 16] = ""; | |
6859 #ifdef FEAT_MBYTE | |
6860 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6861 #endif | |
6862 | |
6863 if (p & R_OK) | |
6864 { | |
6865 /* Read check is performed by seeing if we can do a find file on | |
6866 * the directory for any file. */ | |
6867 #ifdef FEAT_MBYTE | |
6868 if (wn != NULL) | |
6869 { | |
6870 int i; | |
6871 WIN32_FIND_DATAW d; | |
6872 | |
6873 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) | |
6874 TempNameW[i] = wn[i]; | |
6875 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/') | |
6876 TempNameW[i++] = '\\'; | |
6877 TempNameW[i++] = '*'; | |
6878 TempNameW[i++] = 0; | |
6879 | |
6880 hFile = FindFirstFileW(TempNameW, &d); | |
6881 if (hFile == INVALID_HANDLE_VALUE) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6882 goto getout; |
7 | 6883 else |
6884 (void)FindClose(hFile); | |
6885 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6886 else |
7 | 6887 #endif |
6888 { | |
6889 char *pch; | |
6890 WIN32_FIND_DATA d; | |
6891 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6892 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH); |
7 | 6893 pch = TempName + STRLEN(TempName) - 1; |
6894 if (*pch != '\\' && *pch != '/') | |
6895 *++pch = '\\'; | |
6896 *++pch = '*'; | |
6897 *++pch = NUL; | |
6898 | |
6899 hFile = FindFirstFile(TempName, &d); | |
6900 if (hFile == INVALID_HANDLE_VALUE) | |
6901 goto getout; | |
6902 (void)FindClose(hFile); | |
6903 } | |
6904 } | |
6905 | |
6906 if (p & W_OK) | |
6907 { | |
6908 /* Trying to create a temporary file in the directory should catch | |
6909 * directories on read-only network shares. However, in | |
6910 * directories whose ACL allows writes but denies deletes will end | |
6911 * up keeping the temporary file :-(. */ | |
6912 #ifdef FEAT_MBYTE | |
6913 if (wn != NULL) | |
6914 { | |
6915 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
|
6916 goto getout; |
7 | 6917 else |
6918 DeleteFileW(TempNameW); | |
6919 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6920 else |
7 | 6921 #endif |
6922 { | |
6923 if (!GetTempFileName(n, "VIM", 0, TempName)) | |
6924 goto getout; | |
6925 mch_remove((char_u *)TempName); | |
6926 } | |
6927 } | |
6928 } | |
6929 else | |
6930 { | |
6931 /* Trying to open the file for the required access does ACL, read-only | |
6932 * network share, and file attribute checks. */ | |
6933 am = ((p & W_OK) ? GENERIC_WRITE : 0) | |
6934 | ((p & R_OK) ? GENERIC_READ : 0); | |
6935 #ifdef FEAT_MBYTE | |
6936 if (wn != NULL) | |
6937 hFile = CreateFileW(wn, am, 0, NULL, OPEN_EXISTING, 0, NULL); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6938 else |
7 | 6939 #endif |
6940 hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); | |
6941 if (hFile == INVALID_HANDLE_VALUE) | |
6942 goto getout; | |
6943 CloseHandle(hFile); | |
6944 } | |
6945 | |
6946 retval = 0; /* success */ | |
6947 getout: | |
6948 #ifdef FEAT_MBYTE | |
6949 vim_free(wn); | |
6950 #endif | |
6951 return retval; | |
6952 } | |
6953 | |
6954 #if defined(FEAT_MBYTE) || defined(PROTO) | |
6955 /* | |
1752 | 6956 * Version of open() that may use UTF-16 file name. |
7 | 6957 */ |
6958 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6959 mch_open(const char *name, int flags, int mode) |
7 | 6960 { |
39 | 6961 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */ |
6962 # ifndef __BORLANDC__ | |
7 | 6963 WCHAR *wn; |
6964 int f; | |
6965 | |
39 | 6966 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 6967 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6968 wn = enc_to_utf16((char_u *)name, NULL); |
7 | 6969 if (wn != NULL) |
6970 { | |
6971 f = _wopen(wn, flags, mode); | |
6972 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6973 return f; |
7 | 6974 } |
6975 } | |
39 | 6976 # endif |
7 | 6977 |
6345 | 6978 /* open() can open a file which name is longer than _MAX_PATH bytes |
6979 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
6980 * causes unexpected error in another part. We make it an error explicitly | |
6981 * here. */ | |
6982 if (strlen(name) >= _MAX_PATH) | |
6983 return -1; | |
6984 | |
7 | 6985 return open(name, flags, mode); |
6986 } | |
6987 | |
6988 /* | |
1752 | 6989 * Version of fopen() that may use UTF-16 file name. |
7 | 6990 */ |
6991 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6992 mch_fopen(const char *name, const char *mode) |
7 | 6993 { |
6994 WCHAR *wn, *wm; | |
6995 FILE *f = NULL; | |
6996 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6997 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 6998 { |
1686 | 6999 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 7000 /* Work around an annoying assertion in the Microsoft debug CRT |
7001 * when mode's text/binary setting doesn't match _get_fmode(). */ | |
7002 char newMode = mode[strlen(mode) - 1]; | |
7003 int oldMode = 0; | |
7004 | |
7005 _get_fmode(&oldMode); | |
7006 if (newMode == 't') | |
7007 _set_fmode(_O_TEXT); | |
7008 else if (newMode == 'b') | |
7009 _set_fmode(_O_BINARY); | |
7010 # endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7011 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
|
7012 wm = enc_to_utf16((char_u *)mode, NULL); |
7 | 7013 if (wn != NULL && wm != NULL) |
7014 f = _wfopen(wn, wm); | |
7015 vim_free(wn); | |
7016 vim_free(wm); | |
1569 | 7017 |
1686 | 7018 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 7019 _set_fmode(oldMode); |
7020 # endif | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7021 return f; |
7 | 7022 } |
7023 | |
6345 | 7024 /* fopen() can open a file which name is longer than _MAX_PATH bytes |
7025 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
7026 * causes unexpected error in another part. We make it an error explicitly | |
7027 * here. */ | |
7028 if (strlen(name) >= _MAX_PATH) | |
7029 return NULL; | |
7030 | |
7 | 7031 return fopen(name, mode); |
7032 } | |
7033 #endif | |
7034 | |
7035 #ifdef FEAT_MBYTE | |
7036 /* | |
7037 * SUB STREAM (aka info stream) handling: | |
7038 * | |
7039 * NTFS can have sub streams for each file. Normal contents of file is | |
7040 * stored in the main stream, and extra contents (author information and | |
7041 * title and so on) can be stored in sub stream. After Windows 2000, user | |
7042 * can access and store those informations in sub streams via explorer's | |
7043 * property menuitem in right click menu. Those informations in sub streams | |
7044 * were lost when copying only the main stream. So we have to copy sub | |
7045 * streams. | |
7046 * | |
7047 * Incomplete explanation: | |
7048 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
7049 * More useful info and an example: | |
7050 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
7051 */ | |
7052 | |
7053 /* | |
7054 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
7055 * and write to stream "substream" of file "to". | |
7056 * Errors are ignored. | |
7057 */ | |
7058 static void | |
7059 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
7060 { | |
7061 HANDLE hTo; | |
7062 WCHAR *to_name; | |
7063 | |
7064 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
7065 wcscpy(to_name, to); | |
7066 wcscat(to_name, substream); | |
7067 | |
7068 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
7069 FILE_ATTRIBUTE_NORMAL, NULL); | |
7070 if (hTo != INVALID_HANDLE_VALUE) | |
7071 { | |
7072 long done; | |
7073 DWORD todo; | |
7074 DWORD readcnt, written; | |
7075 char buf[4096]; | |
7076 | |
7077 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
7078 for (done = 0; done < len; done += written) | |
7079 { | |
7080 /* (size_t) cast for Borland C 5.5 */ | |
835 | 7081 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
7082 : (size_t)(len - done)); | |
7 | 7083 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
7084 FALSE, FALSE, context) | |
7085 || readcnt != todo | |
7086 || !WriteFile(hTo, buf, todo, &written, NULL) | |
7087 || written != todo) | |
7088 break; | |
7089 } | |
7090 CloseHandle(hTo); | |
7091 } | |
7092 | |
7093 free(to_name); | |
7094 } | |
7095 | |
7096 /* | |
7097 * Copy info streams from file "from" to file "to". | |
7098 */ | |
7099 static void | |
7100 copy_infostreams(char_u *from, char_u *to) | |
7101 { | |
7102 WCHAR *fromw; | |
7103 WCHAR *tow; | |
7104 HANDLE sh; | |
7105 WIN32_STREAM_ID sid; | |
7106 int headersize; | |
7107 WCHAR streamname[_MAX_PATH]; | |
7108 DWORD readcount; | |
7109 void *context = NULL; | |
7110 DWORD lo, hi; | |
7111 int len; | |
7112 | |
7113 /* Convert the file names to wide characters. */ | |
1752 | 7114 fromw = enc_to_utf16(from, NULL); |
7115 tow = enc_to_utf16(to, NULL); | |
7 | 7116 if (fromw != NULL && tow != NULL) |
7117 { | |
7118 /* Open the file for reading. */ | |
7119 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
7120 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
7121 if (sh != INVALID_HANDLE_VALUE) | |
7122 { | |
7123 /* Use BackupRead() to find the info streams. Repeat until we | |
7124 * have done them all.*/ | |
7125 for (;;) | |
7126 { | |
7127 /* Get the header to find the length of the stream name. If | |
7128 * the "readcount" is zero we have done all info streams. */ | |
7129 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 7130 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 7131 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
7132 &readcount, FALSE, FALSE, &context) | |
7133 || readcount == 0) | |
7134 break; | |
7135 | |
7136 /* We only deal with streams that have a name. The normal | |
7137 * file data appears to be without a name, even though docs | |
7138 * suggest it is called "::$DATA". */ | |
7139 if (sid.dwStreamNameSize > 0) | |
7140 { | |
7141 /* Read the stream name. */ | |
7142 if (!BackupRead(sh, (LPBYTE)streamname, | |
7143 sid.dwStreamNameSize, | |
7144 &readcount, FALSE, FALSE, &context)) | |
7145 break; | |
7146 | |
7147 /* Copy an info stream with a name ":anything:$DATA". | |
7148 * Skip "::$DATA", it has no stream name (examples suggest | |
7149 * it might be used for the normal file contents). | |
7150 * Note that BackupRead() counts bytes, but the name is in | |
7151 * wide characters. */ | |
7152 len = readcount / sizeof(WCHAR); | |
7153 streamname[len] = 0; | |
7154 if (len > 7 && wcsicmp(streamname + len - 6, | |
7155 L":$DATA") == 0) | |
7156 { | |
7157 streamname[len - 6] = 0; | |
7158 copy_substream(sh, &context, tow, streamname, | |
10 | 7159 (long)sid.Size.u.LowPart); |
7 | 7160 } |
7161 } | |
7162 | |
7163 /* Advance to the next stream. We might try seeking too far, | |
7164 * but BackupSeek() doesn't skip over stream borders, thus | |
7165 * that's OK. */ | |
323 | 7166 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 7167 &lo, &hi, &context); |
7168 } | |
7169 | |
7170 /* Clear the context. */ | |
7171 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
7172 | |
7173 CloseHandle(sh); | |
7174 } | |
7175 } | |
7176 vim_free(fromw); | |
7177 vim_free(tow); | |
7178 } | |
7179 #endif | |
7180 | |
7181 /* | |
7182 * Copy file attributes from file "from" to file "to". | |
7183 * For Windows NT and later we copy info streams. | |
7184 * Always returns zero, errors are ignored. | |
7185 */ | |
7186 int | |
7187 mch_copy_file_attribute(char_u *from, char_u *to) | |
7188 { | |
7189 #ifdef FEAT_MBYTE | |
7190 /* File streams only work on Windows NT and later. */ | |
7191 PlatformId(); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7192 copy_infostreams(from, to); |
7 | 7193 #endif |
7194 return 0; | |
7195 } | |
7196 | |
7197 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
7198 /* | |
7199 * Recreate a destroyed stack guard page in win32. | |
7200 * Written by Benjamin Peterson. | |
7201 */ | |
7202 | |
7203 /* These magic numbers are from the MS header files */ | |
7204 #define MIN_STACK_WINNT 2 | |
7205 | |
7206 /* | |
7207 * This function does the same thing as _resetstkoflw(), which is only | |
7208 * available in DevStudio .net and later. | |
7209 * Returns 0 for failure, 1 for success. | |
7210 */ | |
7211 int | |
7212 myresetstkoflw(void) | |
7213 { | |
7214 BYTE *pStackPtr; | |
7215 BYTE *pGuardPage; | |
7216 BYTE *pStackBase; | |
7217 BYTE *pLowestPossiblePage; | |
7218 MEMORY_BASIC_INFORMATION mbi; | |
7219 SYSTEM_INFO si; | |
7220 DWORD nPageSize; | |
7221 DWORD dummy; | |
7222 | |
7223 PlatformId(); | |
7224 | |
7225 /* We need to know the system page size. */ | |
7226 GetSystemInfo(&si); | |
7227 nPageSize = si.dwPageSize; | |
7228 | |
7229 /* ...and the current stack pointer */ | |
7230 pStackPtr = (BYTE*)_alloca(1); | |
7231 | |
7232 /* ...and the base of the stack. */ | |
7233 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
7234 return 0; | |
7235 pStackBase = (BYTE*)mbi.AllocationBase; | |
7236 | |
7237 /* ...and the page thats min_stack_req pages away from stack base; this is | |
7238 * 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
|
7239 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7240 |
7 | 7241 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7242 /* 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
|
7243 * 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
|
7244 */ |
7 | 7245 BYTE *pBlock = pStackBase; |
7246 | |
406 | 7247 for (;;) |
7 | 7248 { |
7249 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
7250 return 0; | |
7251 | |
7252 pBlock += mbi.RegionSize; | |
7253 | |
7254 if (mbi.State & MEM_COMMIT) | |
7255 break; | |
7256 } | |
7257 | |
7258 /* mbi now describes the first committed block in the stack. */ | |
7259 if (mbi.Protect & PAGE_GUARD) | |
7260 return 1; | |
7261 | |
7262 /* decide where the guard page should start */ | |
7263 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
7264 pGuardPage = pLowestPossiblePage; | |
7265 else | |
7266 pGuardPage = (BYTE*)mbi.BaseAddress; | |
7267 | |
7268 /* allocate the guard page */ | |
7269 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
7270 return 0; | |
7271 | |
7272 /* apply the guard attribute to the page */ | |
7273 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
7274 &dummy)) | |
7275 return 0; | |
7276 } | |
7277 | |
7278 return 1; | |
7279 } | |
7280 #endif | |
26 | 7281 |
7282 | |
7283 #if defined(FEAT_MBYTE) || defined(PROTO) | |
7284 /* | |
7285 * The command line arguments in UCS2 | |
7286 */ | |
344 | 7287 static int nArgsW = 0; |
26 | 7288 static LPWSTR *ArglistW = NULL; |
7289 static int global_argc = 0; | |
7290 static char **global_argv; | |
7291 | |
7292 static int used_file_argc = 0; /* last argument in global_argv[] used | |
7293 for the argument list. */ | |
7294 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
7295 command line arguments added to | |
7296 the argument list */ | |
7297 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
7298 static int used_file_literal = FALSE; /* take file names literally */ | |
7299 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 7300 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 7301 static int used_alist_count = 0; |
7302 | |
7303 | |
7304 /* | |
7305 * Get the command line arguments. Unicode version. | |
7306 * Returns argc. Zero when something fails. | |
7307 */ | |
7308 int | |
7309 get_cmd_argsW(char ***argvp) | |
7310 { | |
7311 char **argv = NULL; | |
7312 int argc = 0; | |
7313 int i; | |
7314 | |
6193 | 7315 free_cmd_argsW(); |
26 | 7316 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7317 if (ArglistW != NULL) | |
7318 { | |
7319 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7320 if (argv != NULL) | |
7321 { | |
7322 argc = nArgsW; | |
7323 argv[argc] = NULL; | |
7324 for (i = 0; i < argc; ++i) | |
7325 { | |
7326 int len; | |
7327 | |
7328 /* Convert each Unicode argument to the current codepage. */ | |
7329 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 7330 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7331 (LPSTR *)&argv[i], &len, 0, 0); |
7332 if (argv[i] == NULL) | |
7333 { | |
7334 /* Out of memory, clear everything. */ | |
7335 while (i > 0) | |
7336 free(argv[--i]); | |
7337 free(argv); | |
5529 | 7338 argv = NULL; |
26 | 7339 argc = 0; |
7340 } | |
7341 } | |
7342 } | |
7343 } | |
7344 | |
7345 global_argc = argc; | |
7346 global_argv = argv; | |
7347 if (argc > 0) | |
6193 | 7348 { |
7349 if (used_file_indexes != NULL) | |
7350 free(used_file_indexes); | |
26 | 7351 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7352 } |
26 | 7353 |
7354 if (argvp != NULL) | |
7355 *argvp = argv; | |
7356 return argc; | |
7357 } | |
7358 | |
7359 void | |
7360 free_cmd_argsW(void) | |
7361 { | |
7362 if (ArglistW != NULL) | |
7363 { | |
7364 GlobalFree(ArglistW); | |
7365 ArglistW = NULL; | |
7366 } | |
7367 } | |
7368 | |
7369 /* | |
7370 * Remember "name" is an argument that was added to the argument list. | |
7371 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7372 * is called. | |
7373 */ | |
7374 void | |
819 | 7375 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7376 { |
7377 int i; | |
7378 | |
7379 if (used_file_indexes == NULL) | |
7380 return; | |
7381 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7382 if (STRCMP(global_argv[i], name) == 0) | |
7383 { | |
7384 used_file_argc = i; | |
7385 used_file_indexes[used_file_count++] = i; | |
7386 break; | |
7387 } | |
7388 used_file_literal = literal; | |
7389 used_file_full_path = full_path; | |
819 | 7390 used_file_diff_mode = diff_mode; |
26 | 7391 } |
7392 | |
7393 /* | |
7394 * Remember the length of the argument list as it was. If it changes then we | |
7395 * leave it alone when 'encoding' is set. | |
7396 */ | |
7397 void | |
7398 set_alist_count(void) | |
7399 { | |
7400 used_alist_count = GARGCOUNT; | |
7401 } | |
7402 | |
7403 /* | |
7404 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
7405 * has been changed while starting up. Use the UCS-2 command line arguments | |
7406 * and convert them to 'encoding'. | |
7407 */ | |
7408 void | |
7409 fix_arg_enc(void) | |
7410 { | |
7411 int i; | |
7412 int idx; | |
7413 char_u *str; | |
41 | 7414 int *fnum_list; |
26 | 7415 |
7416 /* Safety checks: | |
7417 * - if argument count differs between the wide and non-wide argument | |
7418 * list, something must be wrong. | |
7419 * - the file name arguments must have been located. | |
7420 * - the length of the argument list wasn't changed by the user. | |
7421 */ | |
344 | 7422 if (global_argc != nArgsW |
26 | 7423 || ArglistW == NULL |
7424 || used_file_indexes == NULL | |
7425 || used_file_count == 0 | |
7426 || used_alist_count != GARGCOUNT) | |
7427 return; | |
7428 | |
41 | 7429 /* Remember the buffer numbers for the arguments. */ |
7430 fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT); | |
7431 if (fnum_list == NULL) | |
7432 return; /* out of memory */ | |
7433 for (i = 0; i < GARGCOUNT; ++i) | |
7434 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7435 | |
26 | 7436 /* Clear the argument list. Make room for the new arguments. */ |
7437 alist_clear(&global_alist); | |
7438 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 7439 return; /* out of memory */ |
26 | 7440 |
7441 for (i = 0; i < used_file_count; ++i) | |
7442 { | |
7443 idx = used_file_indexes[i]; | |
1752 | 7444 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7445 if (str != NULL) |
41 | 7446 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7447 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
|
7448 |
819 | 7449 #ifdef FEAT_DIFF |
7450 /* When using diff mode may need to concatenate file name to | |
7451 * directory name. Just like it's done in main(). */ | |
7452 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
7453 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7454 { | |
7455 char_u *r; | |
7456 | |
7457 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7458 if (r != NULL) | |
7459 { | |
7460 vim_free(str); | |
7461 str = r; | |
7462 } | |
7463 } | |
7464 #endif | |
41 | 7465 /* Re-use the old buffer by renaming it. When not using literal |
7466 * names it's done by alist_expand() below. */ | |
7467 if (used_file_literal) | |
7468 buf_set_name(fnum_list[i], str); | |
7469 | |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7470 /* 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
|
7471 * 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
|
7472 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
|
7473 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7474 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
|
7475 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7476 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
|
7477 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7478 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7479 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7480 } |
26 | 7481 } |
7482 | |
7483 if (!used_file_literal) | |
7484 { | |
7485 /* Now expand wildcards in the arguments. */ | |
7486 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
7487 * 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
|
7488 * "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
|
7489 * 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
|
7490 * 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
|
7491 * encoding options were changed. */ |
26 | 7492 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
|
7493 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); |
41 | 7494 alist_expand(fnum_list, used_alist_count); |
26 | 7495 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
|
7496 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); |
26 | 7497 } |
7498 | |
7499 /* If wildcard expansion failed, we are editing the first file of the | |
7500 * arglist and there is no file name: Edit the first argument now. */ | |
7501 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
7502 { | |
7503 do_cmdline_cmd((char_u *)":rewind"); | |
7504 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
|
7505 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); |
26 | 7506 } |
41 | 7507 |
7508 set_alist_count(); | |
26 | 7509 } |
7510 #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
|
7511 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7512 int |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7513 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
|
7514 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7515 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
|
7516 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7517 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
|
7518 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
|
7519 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
|
7520 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7521 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
|
7522 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7523 #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
|
7524 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
|
7525 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7526 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
|
7527 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7528 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
|
7529 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
|
7530 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
|
7531 _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
|
7532 # 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
|
7533 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
|
7534 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7535 /* 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
|
7536 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
|
7537 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7538 else |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7539 #endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7540 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7541 _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
|
7542 # 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
|
7543 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
|
7544 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7545 /* 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
|
7546 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
|
7547 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7548 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7549 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
|
7550 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7551 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7552 #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
|
7553 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7554 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7555 * 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
|
7556 * 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
|
7557 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7558 # 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
|
7559 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7560 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
|
7561 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
|
7562 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7563 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
|
7564 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
|
7565 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
|
7566 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7567 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
|
7568 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
|
7569 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
|
7570 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
|
7571 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
|
7572 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
|
7573 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7574 /* 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
|
7575 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
|
7576 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
|
7577 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7578 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7579 (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
|
7580 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
|
7581 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7582 (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
|
7583 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
|
7584 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
|
7585 && 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
|
7586 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
|
7587 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7588 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7589 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
|
7590 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
|
7591 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
|
7592 save_console_bg_rgb = (guicolor_T)csbi.ColorTable[0]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7593 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[7]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7594 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7595 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
|
7596 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7597 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7598 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
|
7599 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
|
7600 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7601 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
|
7602 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7603 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7604 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
|
7605 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
|
7606 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
|
7607 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7608 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7609 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
|
7610 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
|
7611 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
|
7612 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7613 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
|
7614 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
|
7615 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
|
7616 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
|
7617 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
|
7618 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7619 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7620 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
|
7621 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
|
7622 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
|
7623 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7624 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
|
7625 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7626 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
|
7627 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
|
7628 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7629 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7630 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
|
7631 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
|
7632 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
|
7633 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
|
7634 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7635 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7636 /* 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
|
7637 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
|
7638 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
|
7639 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
|
7640 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7641 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
|
7642 *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
|
7643 *p++ = '['; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7644 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7645 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
|
7646 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7647 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
|
7648 *p++ = ';'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7649 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7650 p--; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7651 *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
|
7652 *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
|
7653 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
|
7654 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7655 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7656 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
|
7657 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
|
7658 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7659 # 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
|
7660 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
|
7661 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
|
7662 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
|
7663 guicolor_T bg = INVALCOLOR; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7664 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7665 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
|
7666 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7667 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7668 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
|
7669 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
|
7670 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
|
7671 if (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
|
7672 fg = 0xc0c0c0; /* white text */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7673 if (bg == INVALCOLOR) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7674 bg = 0x000000; /* black background */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7675 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
|
7676 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
|
7677 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7678 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
|
7679 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
|
7680 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
|
7681 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7682 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
|
7683 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
|
7684 csbi.srWindow.Bottom += 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7685 csbi.ColorTable[0] = (COLORREF)bg; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7686 csbi.ColorTable[7] = (COLORREF)fg; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7687 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
|
7688 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
|
7689 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7690 } |
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 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
|
7693 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
|
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 # 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
|
7696 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
|
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 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
|
7699 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
|
7700 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
|
7701 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7702 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
|
7703 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
|
7704 csbi.srWindow.Bottom += 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7705 csbi.ColorTable[0] = (COLORREF)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
|
7706 csbi.ColorTable[7] = (COLORREF)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
|
7707 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
|
7708 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
|
7709 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7710 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7711 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7712 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7713 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
|
7714 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7715 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
|
7716 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
|
7717 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7718 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
|
7719 } |
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 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7722 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
|
7723 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7724 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
|
7725 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7726 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7727 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7728 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
|
7729 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7730 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
|
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 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7733 #endif |