Mercurial > vim
annotate src/os_win32.c @ 14094:cc99f2e4de00
Added tag v8.1.0064 for changeset a9d94f10ecef3324f811bf3fc237a48423a4326d
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 17 Jun 2018 16:30:07 +0200 |
parents | 39ec4b90e4a7 |
children | 4d3f6bf86bec |
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 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
217 # define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256))) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
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); | |
2633 | |
2634 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2635 GetConsoleMode(g_hConIn, &g_cmodein); | |
2636 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2637 | |
2638 #ifdef FEAT_TITLE | |
2639 SaveConsoleTitleAndIcon(); | |
2640 /* | |
2641 * Set both the small and big icons of the console window to Vim's icon. | |
2642 * Note that Vim presently only has one size of icon (32x32), but it | |
2643 * automatically gets scaled down to 16x16 when setting the small icon. | |
2644 */ | |
2645 if (g_fCanChangeIcon) | |
2646 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2647 #endif | |
2648 | |
2649 ui_get_shellsize(); | |
2650 | |
2651 #ifdef MCH_WRITE_DUMP | |
2652 fdDump = fopen("dump", "wt"); | |
2653 | |
2654 if (fdDump) | |
2655 { | |
2656 time_t t; | |
2657 | |
2658 time(&t); | |
2659 fputs(ctime(&t), fdDump); | |
2660 fflush(fdDump); | |
2661 } | |
2662 #endif | |
2663 | |
2664 g_fWindInitCalled = TRUE; | |
2665 | |
2666 #ifdef FEAT_MOUSE | |
2667 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2668 #endif | |
2669 | |
2670 #ifdef FEAT_CLIPBOARD | |
4168 | 2671 win_clip_init(); |
7 | 2672 #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
|
2673 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2674 vtp_init(); |
7 | 2675 } |
2676 | |
2677 /* | |
2678 * non-GUI version of mch_exit(). | |
2679 * Shut down and exit with status `r' | |
2680 * Careful: mch_exit() may be called before mch_init()! | |
2681 */ | |
2682 void | |
2683 mch_exit(int r) | |
2684 { | |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2685 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
|
2686 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2687 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
|
2688 |
7 | 2689 stoptermcap(); |
2690 if (g_fWindInitCalled) | |
2691 settmode(TMODE_COOK); | |
2692 | |
2693 ml_close_all(TRUE); /* remove all memfiles */ | |
2694 | |
2695 if (g_fWindInitCalled) | |
2696 { | |
2697 #ifdef FEAT_TITLE | |
2698 mch_restore_title(3); | |
2699 /* | |
2700 * Restore both the small and big icons of the console window to | |
2701 * what they were at startup. Don't do this when the window is | |
2702 * closed, Vim would hang here. | |
2703 */ | |
2704 if (g_fCanChangeIcon && !g_fForceExit) | |
2705 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
2706 #endif | |
2707 | |
2708 #ifdef MCH_WRITE_DUMP | |
2709 if (fdDump) | |
2710 { | |
2711 time_t t; | |
2712 | |
2713 time(&t); | |
2714 fputs(ctime(&t), fdDump); | |
2715 fclose(fdDump); | |
2716 } | |
2717 fdDump = NULL; | |
2718 #endif | |
2719 } | |
2720 | |
2721 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2722 SetConsoleMode(g_hConIn, g_cmodein); | |
2723 SetConsoleMode(g_hConOut, g_cmodeout); | |
2724 | |
2725 #ifdef DYNAMIC_GETTEXT | |
2726 dyn_libintl_end(); | |
2727 #endif | |
2728 | |
2729 exit(r); | |
2730 } | |
2731 #endif /* !FEAT_GUI_W32 */ | |
2732 | |
2733 /* | |
2734 * Do we have an interactive window? | |
2735 */ | |
2736 int | |
2737 mch_check_win( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
2738 int argc UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
2739 char **argv UNUSED) |
7 | 2740 { |
2741 get_exe_name(); | |
2742 | |
2743 #ifdef FEAT_GUI_W32 | |
2744 return OK; /* GUI always has a tty */ | |
2745 #else | |
2746 if (isatty(1)) | |
2747 return OK; | |
2748 return FAIL; | |
2749 #endif | |
2750 } | |
2751 | |
2752 | |
5326 | 2753 #ifdef FEAT_MBYTE |
2754 /* | |
2755 * fname_casew(): Wide version of fname_case(). Set the case of the file name, | |
2756 * if it already exists. When "len" is > 0, also expand short to long | |
2757 * filenames. | |
2758 * Return FAIL if wide functions are not available, OK otherwise. | |
2759 * NOTE: much of this is identical to fname_case(), keep in sync! | |
2760 */ | |
2761 static int | |
2762 fname_casew( | |
2763 WCHAR *name, | |
2764 int len) | |
2765 { | |
2766 WCHAR szTrueName[_MAX_PATH + 2]; | |
2767 WCHAR szTrueNameTemp[_MAX_PATH + 2]; | |
2768 WCHAR *ptrue, *ptruePrev; | |
2769 WCHAR *porig, *porigPrev; | |
2770 int flen; | |
2771 WIN32_FIND_DATAW fb; | |
5529 | 2772 HANDLE hFind = INVALID_HANDLE_VALUE; |
5326 | 2773 int c; |
2774 int slen; | |
2775 | |
2776 flen = (int)wcslen(name); | |
2777 if (flen > _MAX_PATH) | |
2778 return OK; | |
2779 | |
2780 /* slash_adjust(name) not needed, already adjusted by fname_case(). */ | |
2781 | |
2782 /* Build the new name in szTrueName[] one component at a time. */ | |
2783 porig = name; | |
2784 ptrue = szTrueName; | |
2785 | |
2786 if (iswalpha(porig[0]) && porig[1] == L':') | |
2787 { | |
2788 /* copy leading drive letter */ | |
2789 *ptrue++ = *porig++; | |
2790 *ptrue++ = *porig++; | |
2791 } | |
5529 | 2792 *ptrue = NUL; /* in case nothing follows */ |
5326 | 2793 |
2794 while (*porig != NUL) | |
2795 { | |
2796 /* copy \ characters */ | |
2797 while (*porig == psepc) | |
2798 *ptrue++ = *porig++; | |
2799 | |
2800 ptruePrev = ptrue; | |
2801 porigPrev = porig; | |
2802 while (*porig != NUL && *porig != psepc) | |
2803 { | |
2804 *ptrue++ = *porig++; | |
2805 } | |
2806 *ptrue = NUL; | |
2807 | |
2808 /* To avoid a slow failure append "\*" when searching a directory, | |
2809 * server or network share. */ | |
2810 wcscpy(szTrueNameTemp, szTrueName); | |
2811 slen = (int)wcslen(szTrueNameTemp); | |
2812 if (*porig == psepc && slen + 2 < _MAX_PATH) | |
2813 wcscpy(szTrueNameTemp + slen, L"\\*"); | |
2814 | |
2815 /* Skip "", "." and "..". */ | |
2816 if (ptrue > ptruePrev | |
2817 && (ptruePrev[0] != L'.' | |
2818 || (ptruePrev[1] != NUL | |
2819 && (ptruePrev[1] != L'.' || ptruePrev[2] != NUL))) | |
2820 && (hFind = FindFirstFileW(szTrueNameTemp, &fb)) | |
2821 != INVALID_HANDLE_VALUE) | |
2822 { | |
2823 c = *porig; | |
2824 *porig = NUL; | |
2825 | |
2826 /* Only use the match when it's the same name (ignoring case) or | |
2827 * expansion is allowed and there is a match with the short name | |
2828 * and there is enough room. */ | |
2829 if (_wcsicoll(porigPrev, fb.cFileName) == 0 | |
2830 || (len > 0 | |
2831 && (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0 | |
2832 && (int)(ptruePrev - szTrueName) | |
2833 + (int)wcslen(fb.cFileName) < len))) | |
2834 { | |
2835 wcscpy(ptruePrev, fb.cFileName); | |
2836 | |
2837 /* Look for exact match and prefer it if found. Must be a | |
2838 * long name, otherwise there would be only one match. */ | |
2839 while (FindNextFileW(hFind, &fb)) | |
2840 { | |
2841 if (*fb.cAlternateFileName != NUL | |
2842 && (wcscoll(porigPrev, fb.cFileName) == 0 | |
2843 || (len > 0 | |
2844 && (_wcsicoll(porigPrev, | |
2845 fb.cAlternateFileName) == 0 | |
2846 && (int)(ptruePrev - szTrueName) | |
2847 + (int)wcslen(fb.cFileName) < len)))) | |
2848 { | |
2849 wcscpy(ptruePrev, fb.cFileName); | |
2850 break; | |
2851 } | |
2852 } | |
2853 } | |
2854 FindClose(hFind); | |
2855 *porig = c; | |
2856 ptrue = ptruePrev + wcslen(ptruePrev); | |
2857 } | |
2858 } | |
2859 | |
2860 wcscpy(name, szTrueName); | |
2861 return OK; | |
2862 } | |
2863 #endif | |
2864 | |
7 | 2865 /* |
2866 * fname_case(): Set the case of the file name, if it already exists. | |
2867 * When "len" is > 0, also expand short to long filenames. | |
5326 | 2868 * NOTE: much of this is identical to fname_casew(), keep in sync! |
7 | 2869 */ |
2870 void | |
2871 fname_case( | |
2872 char_u *name, | |
2873 int len) | |
2874 { | |
2875 char szTrueName[_MAX_PATH + 2]; | |
2604 | 2876 char szTrueNameTemp[_MAX_PATH + 2]; |
7 | 2877 char *ptrue, *ptruePrev; |
2878 char *porig, *porigPrev; | |
2879 int flen; | |
2880 WIN32_FIND_DATA fb; | |
2881 HANDLE hFind; | |
2882 int c; | |
2604 | 2883 int slen; |
7 | 2884 |
434 | 2885 flen = (int)STRLEN(name); |
5326 | 2886 if (flen == 0) |
7 | 2887 return; |
2888 | |
2889 slash_adjust(name); | |
2890 | |
5326 | 2891 #ifdef FEAT_MBYTE |
2892 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2893 { | |
2894 WCHAR *p = enc_to_utf16(name, NULL); | |
2895 | |
2896 if (p != NULL) | |
2897 { | |
2898 char_u *q; | |
6262 | 2899 WCHAR buf[_MAX_PATH + 1]; |
2900 | |
2901 wcsncpy(buf, p, _MAX_PATH); | |
2902 buf[_MAX_PATH] = L'\0'; | |
5326 | 2903 vim_free(p); |
2904 | |
2905 if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK) | |
2906 { | |
2907 q = utf16_to_enc(buf, NULL); | |
2908 if (q != NULL) | |
2909 { | |
2910 vim_strncpy(name, q, (len > 0) ? len - 1 : flen); | |
2911 vim_free(q); | |
2912 return; | |
2913 } | |
2914 } | |
2915 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2916 return; |
5326 | 2917 } |
2918 #endif | |
2919 | |
2920 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH. | |
2921 * So we should check this after calling wide function. */ | |
2922 if (flen > _MAX_PATH) | |
2923 return; | |
2924 | |
7 | 2925 /* 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
|
2926 porig = (char *)name; |
7 | 2927 ptrue = szTrueName; |
2928 | |
2929 if (isalpha(porig[0]) && porig[1] == ':') | |
2930 { | |
2931 /* copy leading drive letter */ | |
2932 *ptrue++ = *porig++; | |
2933 *ptrue++ = *porig++; | |
2934 } | |
5529 | 2935 *ptrue = NUL; /* in case nothing follows */ |
7 | 2936 |
2937 while (*porig != NUL) | |
2938 { | |
2939 /* copy \ characters */ | |
2940 while (*porig == psepc) | |
2941 *ptrue++ = *porig++; | |
2942 | |
2943 ptruePrev = ptrue; | |
2944 porigPrev = porig; | |
2945 while (*porig != NUL && *porig != psepc) | |
2946 { | |
2947 #ifdef FEAT_MBYTE | |
2948 int l; | |
2949 | |
2950 if (enc_dbcs) | |
2951 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2952 l = (*mb_ptr2len)((char_u *)porig); |
7 | 2953 while (--l >= 0) |
2954 *ptrue++ = *porig++; | |
2955 } | |
2956 else | |
2957 #endif | |
2958 *ptrue++ = *porig++; | |
2959 } | |
2960 *ptrue = NUL; | |
2961 | |
2604 | 2962 /* To avoid a slow failure append "\*" when searching a directory, |
2963 * server or network share. */ | |
2964 STRCPY(szTrueNameTemp, szTrueName); | |
2615 | 2965 slen = (int)strlen(szTrueNameTemp); |
2604 | 2966 if (*porig == psepc && slen + 2 < _MAX_PATH) |
2967 STRCPY(szTrueNameTemp + slen, "\\*"); | |
2968 | |
7 | 2969 /* Skip "", "." and "..". */ |
2970 if (ptrue > ptruePrev | |
2971 && (ptruePrev[0] != '.' | |
2972 || (ptruePrev[1] != NUL | |
2973 && (ptruePrev[1] != '.' || ptruePrev[2] != NUL))) | |
2604 | 2974 && (hFind = FindFirstFile(szTrueNameTemp, &fb)) |
7 | 2975 != INVALID_HANDLE_VALUE) |
2976 { | |
2977 c = *porig; | |
2978 *porig = NUL; | |
2979 | |
2980 /* Only use the match when it's the same name (ignoring case) or | |
2981 * expansion is allowed and there is a match with the short name | |
2982 * and there is enough room. */ | |
2983 if (_stricoll(porigPrev, fb.cFileName) == 0 | |
2984 || (len > 0 | |
2985 && (_stricoll(porigPrev, fb.cAlternateFileName) == 0 | |
2986 && (int)(ptruePrev - szTrueName) | |
2987 + (int)strlen(fb.cFileName) < len))) | |
2988 { | |
2989 STRCPY(ptruePrev, fb.cFileName); | |
2990 | |
2991 /* Look for exact match and prefer it if found. Must be a | |
2992 * long name, otherwise there would be only one match. */ | |
2993 while (FindNextFile(hFind, &fb)) | |
2994 { | |
2995 if (*fb.cAlternateFileName != NUL | |
2996 && (strcoll(porigPrev, fb.cFileName) == 0 | |
2997 || (len > 0 | |
2998 && (_stricoll(porigPrev, | |
2999 fb.cAlternateFileName) == 0 | |
3000 && (int)(ptruePrev - szTrueName) | |
3001 + (int)strlen(fb.cFileName) < len)))) | |
3002 { | |
3003 STRCPY(ptruePrev, fb.cFileName); | |
3004 break; | |
3005 } | |
3006 } | |
3007 } | |
3008 FindClose(hFind); | |
3009 *porig = c; | |
3010 ptrue = ptruePrev + strlen(ptruePrev); | |
3011 } | |
3012 } | |
3013 | |
3014 STRCPY(name, szTrueName); | |
3015 } | |
3016 | |
3017 | |
3018 /* | |
3019 * Insert user name in s[len]. | |
3020 */ | |
3021 int | |
3022 mch_get_user_name( | |
26 | 3023 char_u *s, |
3024 int len) | |
7 | 3025 { |
1414 | 3026 char szUserName[256 + 1]; /* UNLEN is 256 */ |
7 | 3027 DWORD cch = sizeof szUserName; |
3028 | |
5549 | 3029 #ifdef FEAT_MBYTE |
3030 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3031 { | |
3032 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ | |
3033 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); | |
3034 | |
3035 if (GetUserNameW(wszUserName, &wcch)) | |
3036 { | |
3037 char_u *p = utf16_to_enc(wszUserName, NULL); | |
3038 | |
3039 if (p != NULL) | |
3040 { | |
3041 vim_strncpy(s, p, len - 1); | |
3042 vim_free(p); | |
3043 return OK; | |
3044 } | |
3045 } | |
3046 } | |
3047 #endif | |
7 | 3048 if (GetUserName(szUserName, &cch)) |
3049 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3050 vim_strncpy(s, (char_u *)szUserName, len - 1); |
7 | 3051 return OK; |
3052 } | |
3053 s[0] = NUL; | |
3054 return FAIL; | |
3055 } | |
3056 | |
3057 | |
3058 /* | |
3059 * Insert host name in s[len]. | |
3060 */ | |
3061 void | |
3062 mch_get_host_name( | |
3063 char_u *s, | |
3064 int len) | |
3065 { | |
3066 DWORD cch = len; | |
3067 | |
5551 | 3068 #ifdef FEAT_MBYTE |
3069 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3070 { | |
3071 WCHAR wszHostName[256 + 1]; | |
3072 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); | |
3073 | |
3074 if (GetComputerNameW(wszHostName, &wcch)) | |
3075 { | |
3076 char_u *p = utf16_to_enc(wszHostName, NULL); | |
3077 | |
3078 if (p != NULL) | |
3079 { | |
3080 vim_strncpy(s, p, len - 1); | |
3081 vim_free(p); | |
3082 return; | |
3083 } | |
3084 } | |
3085 } | |
3086 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3087 if (!GetComputerName((LPSTR)s, &cch)) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3088 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1); |
7 | 3089 } |
3090 | |
3091 | |
3092 /* | |
3093 * return process ID | |
3094 */ | |
3095 long | |
26 | 3096 mch_get_pid(void) |
7 | 3097 { |
3098 return (long)GetCurrentProcessId(); | |
3099 } | |
3100 | |
3101 | |
3102 /* | |
3103 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
3104 * Return OK for success, FAIL for failure. | |
3105 */ | |
3106 int | |
3107 mch_dirname( | |
3108 char_u *buf, | |
3109 int len) | |
3110 { | |
3111 /* | |
3112 * Originally this was: | |
3113 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
3114 * But the Win32s known bug list says that getcwd() doesn't work | |
3115 * so use the Win32 system call instead. <Negri> | |
3116 */ | |
3117 #ifdef FEAT_MBYTE | |
3118 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3119 { | |
3120 WCHAR wbuf[_MAX_PATH + 1]; | |
3121 | |
3122 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) | |
3123 { | |
1752 | 3124 char_u *p = utf16_to_enc(wbuf, NULL); |
7 | 3125 |
3126 if (p != NULL) | |
3127 { | |
417 | 3128 vim_strncpy(buf, p, len - 1); |
7 | 3129 vim_free(p); |
3130 return OK; | |
3131 } | |
3132 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3133 return FAIL; |
7 | 3134 } |
3135 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3136 return (GetCurrentDirectory(len, (LPSTR)buf) != 0 ? OK : FAIL); |
7 | 3137 } |
3138 | |
3139 /* | |
5494 | 3140 * Get file permissions for "name". |
3141 * Return mode_t or -1 for error. | |
7 | 3142 */ |
3143 long | |
26 | 3144 mch_getperm(char_u *name) |
7 | 3145 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
3146 stat_T st; |
5494 | 3147 int n; |
3148 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3149 n = mch_stat((char *)name, &st); |
5588 | 3150 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 3151 } |
3152 | |
3153 | |
3154 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3155 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3156 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3157 * Return FAIL for failure, OK otherwise. |
7 | 3158 */ |
3159 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3160 mch_setperm(char_u *name, long perm) |
7 | 3161 { |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3162 long n = -1; |
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3163 |
7 | 3164 #ifdef FEAT_MBYTE |
3165 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3166 { | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3167 WCHAR *p = enc_to_utf16(name, NULL); |
7 | 3168 |
3169 if (p != NULL) | |
3170 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3171 n = _wchmod(p, perm); |
7 | 3172 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3173 if (n == -1) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3174 return FAIL; |
7 | 3175 } |
3176 } | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3177 if (n == -1) |
7 | 3178 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3179 n = _chmod((const char *)name, perm); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3180 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3181 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3182 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3183 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3184 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3185 return OK; |
7 | 3186 } |
3187 | |
3188 /* | |
3189 * Set hidden flag for "name". | |
3190 */ | |
3191 void | |
3192 mch_hide(char_u *name) | |
3193 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3194 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3195 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3196 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3197 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3198 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3199 win32_setattrs(name, attrs); |
7 | 3200 } |
3201 | |
3202 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3203 * 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
|
3204 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3205 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3206 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3207 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3208 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3209 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3210 if (f == -1) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3211 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
|
3212 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3213 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3214 } |
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 /* |
7 | 3217 * return TRUE if "name" is a directory |
3218 * return FALSE if "name" is not a directory or upon error | |
3219 */ | |
3220 int | |
3221 mch_isdir(char_u *name) | |
3222 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3223 int f = win32_getattrs(name); |
7 | 3224 |
3225 if (f == -1) | |
3226 return FALSE; /* file does not exist at all */ | |
3227 | |
3228 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3229 } | |
3230 | |
3231 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3232 * 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
|
3233 * 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
|
3234 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3235 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3236 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3237 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3238 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3239 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
|
3240 } |
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 /* |
2803 | 3243 * Create directory "name". |
3244 * Return 0 on success, -1 on error. | |
3245 */ | |
3246 int | |
3247 mch_mkdir(char_u *name) | |
3248 { | |
3249 #ifdef FEAT_MBYTE | |
3250 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3251 { | |
3252 WCHAR *p; | |
3253 int retval; | |
3254 | |
3255 p = enc_to_utf16(name, NULL); | |
3256 if (p == NULL) | |
3257 return -1; | |
3258 retval = _wmkdir(p); | |
3259 vim_free(p); | |
3260 return retval; | |
3261 } | |
3262 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3263 return _mkdir((const char *)name); |
2803 | 3264 } |
3265 | |
3266 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3267 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3268 * Return 0 on success, -1 on error. |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3269 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3270 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3271 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3272 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3273 #ifdef FEAT_MBYTE |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3274 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
|
3275 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3276 WCHAR *p; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3277 int retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3278 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3279 p = enc_to_utf16(name, NULL); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3280 if (p == NULL) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3281 return -1; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3282 retval = _wrmdir(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3283 vim_free(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3284 return retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3285 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3286 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3287 return _rmdir((const char *)name); |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3288 } |
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 /* |
696 | 3291 * Return TRUE if file "fname" has more than one link. |
3292 */ | |
3293 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3294 mch_is_hard_link(char_u *fname) |
696 | 3295 { |
2793 | 3296 BY_HANDLE_FILE_INFORMATION info; |
3297 | |
3298 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3299 && info.nNumberOfLinks > 1; | |
3300 } | |
3301 | |
3302 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3303 * 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
|
3304 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3305 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3306 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3307 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3308 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3309 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3310 WIN32_FIND_DATAA findDataA; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3311 DWORD fileFlags = 0, reparseTag = 0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3312 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3313 WCHAR *wn = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3314 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3315 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3316 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
|
3317 wn = enc_to_utf16(name, NULL); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3318 if (wn != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3319 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3320 hFind = FindFirstFileW(wn, &findDataW); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3321 vim_free(wn); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3322 if (hFind != INVALID_HANDLE_VALUE) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3323 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3324 fileFlags = findDataW.dwFileAttributes; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3325 reparseTag = findDataW.dwReserved0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3326 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3327 } |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3328 else |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3329 #endif |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3330 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3331 hFind = FindFirstFile((LPCSTR)name, &findDataA); |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3332 if (hFind != INVALID_HANDLE_VALUE) |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3333 { |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3334 fileFlags = findDataA.dwFileAttributes; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3335 reparseTag = findDataA.dwReserved0; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3336 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3337 } |
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 if (hFind != INVALID_HANDLE_VALUE) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3340 FindClose(hFind); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3341 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3342 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
|
3343 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3344 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3345 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3346 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3347 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3348 } |
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 * 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
|
3352 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3353 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3354 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3355 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3356 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3357 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
|
3358 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3359 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3360 } |
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 /* |
2793 | 3363 * Get the by-handle-file-information for "fname". |
3364 * Returns FILEINFO_OK when OK. | |
3365 * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
3366 * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
3367 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3368 */ | |
3369 int | |
3370 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3371 { | |
696 | 3372 HANDLE hFile; |
2793 | 3373 int res = FILEINFO_READ_FAIL; |
696 | 3374 #ifdef FEAT_MBYTE |
3375 WCHAR *wn = NULL; | |
3376 | |
3377 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2793 | 3378 { |
1752 | 3379 wn = enc_to_utf16(fname, NULL); |
2793 | 3380 if (wn == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3381 return FILEINFO_ENC_FAIL; |
2793 | 3382 } |
696 | 3383 if (wn != NULL) |
3384 { | |
3385 hFile = CreateFileW(wn, /* file name */ | |
3386 GENERIC_READ, /* access mode */ | |
2793 | 3387 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3388 NULL, /* security descriptor */ |
3389 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3390 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3391 NULL); /* handle to template file */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3392 vim_free(wn); |
696 | 3393 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3394 else |
696 | 3395 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3396 hFile = CreateFile((LPCSTR)fname, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3397 GENERIC_READ, /* access mode */ |
2793 | 3398 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3399 NULL, /* security descriptor */ |
3400 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3401 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3402 NULL); /* handle to template file */ |
3403 | |
3404 if (hFile != INVALID_HANDLE_VALUE) | |
3405 { | |
2793 | 3406 if (GetFileInformationByHandle(hFile, info) != 0) |
3407 res = FILEINFO_OK; | |
3408 else | |
3409 res = FILEINFO_INFO_FAIL; | |
696 | 3410 CloseHandle(hFile); |
3411 } | |
3412 | |
3413 return res; | |
3414 } | |
3415 | |
3416 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3417 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3418 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3419 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3420 */ |
5494 | 3421 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3422 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3423 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3424 int attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3425 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3426 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3427 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3428 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3429 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3430 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3431 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3432 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3433 attr = GetFileAttributesW(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3434 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3435 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3436 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3437 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3438 attr = GetFileAttributes((char *)name); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3439 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3440 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3441 } |
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 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3445 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3446 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3447 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3448 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3449 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3450 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3451 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3452 int res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3453 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3454 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3455 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3456 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3457 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3458 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3459 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3460 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3461 res = SetFileAttributesW(p, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3462 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3463 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3464 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3465 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3466 res = SetFileAttributes((char *)name, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3467 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3468 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3469 } |
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 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3473 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3474 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3475 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3476 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3477 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3478 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3479 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3480 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3481 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3482 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3483 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3484 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3485 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3486 /* |
7 | 3487 * Return TRUE if file or directory "name" is writable (not readonly). |
3488 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3489 * delete a file. Let's say this means it is writable. | |
3490 */ | |
3491 int | |
3492 mch_writable(char_u *name) | |
3493 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3494 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3495 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3496 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3497 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3498 } |
3499 | |
3500 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3501 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3502 * 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
|
3503 * 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
|
3504 * the allocated memory. |
7 | 3505 */ |
3506 int | |
6700 | 3507 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3508 { |
10 | 3509 char_u buf[_MAX_PATH]; |
835 | 3510 int len = (int)STRLEN(name); |
10 | 3511 char_u *p; |
3512 | |
3513 if (len >= _MAX_PATH) /* safety check */ | |
3514 return FALSE; | |
3515 | |
3516 /* If there already is an extension try using the name directly. Also do | |
3517 * this with a Unix-shell like 'shell'. */ | |
3518 if (vim_strchr(gettail(name), '.') != NULL | |
3519 || 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
|
3520 if (executable_exists((char *)name, path, use_path)) |
10 | 3521 return TRUE; |
3522 | |
3523 /* | |
3524 * Loop over all extensions in $PATHEXT. | |
3525 */ | |
417 | 3526 vim_strncpy(buf, name, _MAX_PATH - 1); |
10 | 3527 p = mch_getenv("PATHEXT"); |
3528 if (p == NULL) | |
3529 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3530 while (*p) | |
3531 { | |
3532 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3533 { | |
3534 /* A single "." means no extension is added. */ | |
3535 buf[len] = NUL; | |
3536 ++p; | |
3537 if (*p) | |
3538 ++p; | |
3539 } | |
3540 else | |
3541 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
|
3542 if (executable_exists((char *)buf, path, use_path)) |
10 | 3543 return TRUE; |
3544 } | |
3545 return FALSE; | |
7 | 3546 } |
3547 | |
3548 /* | |
3549 * Check what "name" is: | |
3550 * NODE_NORMAL: file or directory (or doesn't exist) | |
3551 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3552 * NODE_OTHER: non-writable things | |
3553 */ | |
3554 int | |
3555 mch_nodetype(char_u *name) | |
3556 { | |
3557 HANDLE hFile; | |
3558 int type; | |
5324 | 3559 #ifdef FEAT_MBYTE |
3560 WCHAR *wn = NULL; | |
3561 #endif | |
7 | 3562 |
1004 | 3563 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
3564 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE | |
3565 * here. */ | |
3566 if (STRNCMP(name, "\\\\.\\", 4) == 0) | |
3567 return NODE_WRITABLE; | |
3568 | |
5324 | 3569 #ifdef FEAT_MBYTE |
3570 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
|
3571 wn = enc_to_utf16(name, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3572 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3573 if (wn != NULL) |
5324 | 3574 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3575 hFile = CreateFileW(wn, /* file name */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3576 GENERIC_WRITE, /* access mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3577 0, /* share mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3578 NULL, /* security descriptor */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3579 OPEN_EXISTING, /* creation disposition */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3580 0, /* file attributes */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3581 NULL); /* handle to template file */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3582 vim_free(wn); |
5324 | 3583 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3584 else |
5324 | 3585 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3586 hFile = CreateFile((LPCSTR)name, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3587 GENERIC_WRITE, /* access mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3588 0, /* share mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3589 NULL, /* security descriptor */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3590 OPEN_EXISTING, /* creation disposition */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3591 0, /* file attributes */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3592 NULL); /* handle to template file */ |
5324 | 3593 |
7 | 3594 if (hFile == INVALID_HANDLE_VALUE) |
3595 return NODE_NORMAL; | |
3596 | |
3597 type = GetFileType(hFile); | |
3598 CloseHandle(hFile); | |
3599 if (type == FILE_TYPE_CHAR) | |
3600 return NODE_WRITABLE; | |
3601 if (type == FILE_TYPE_DISK) | |
3602 return NODE_NORMAL; | |
3603 return NODE_OTHER; | |
3604 } | |
3605 | |
3606 #ifdef HAVE_ACL | |
3607 struct my_acl | |
3608 { | |
3609 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3610 PSID pSidOwner; | |
3611 PSID pSidGroup; | |
3612 PACL pDacl; | |
3613 PACL pSacl; | |
3614 }; | |
3615 #endif | |
3616 | |
3617 /* | |
3618 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3619 * Return NULL if the ACL is not available for whatever reason. | |
3620 */ | |
3621 vim_acl_T | |
26 | 3622 mch_get_acl(char_u *fname) |
7 | 3623 { |
3624 #ifndef HAVE_ACL | |
3625 return (vim_acl_T)NULL; | |
3626 #else | |
3627 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3628 DWORD err; |
7 | 3629 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3630 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
|
3631 if (p != NULL) |
7 | 3632 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3633 # ifdef FEAT_MBYTE |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3634 WCHAR *wn = NULL; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3635 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3636 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
|
3637 wn = enc_to_utf16(fname, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3638 if (wn != NULL) |
7 | 3639 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3640 /* 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
|
3641 err = GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3642 wn, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3643 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3644 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3645 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3646 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3647 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3648 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3649 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3650 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3651 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3652 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3653 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3654 err == ERROR_PRIVILEGE_NOT_HELD) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3655 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3656 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3657 (void)GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3658 wn, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3659 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3660 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3661 NULL, |
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 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3664 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3665 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3666 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3667 if (p->pSecurityDescriptor == NULL) |
7 | 3668 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3669 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
|
3670 p = NULL; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3671 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3672 vim_free(wn); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3673 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3674 else |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3675 # endif |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3676 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3677 /* 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
|
3678 err = GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3679 (LPSTR)fname, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3680 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3681 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3682 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3683 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3684 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3685 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3686 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3687 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3688 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3689 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3690 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3691 err == ERROR_PRIVILEGE_NOT_HELD) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3692 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3693 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3694 (void)GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3695 (LPSTR)fname, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3696 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3697 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3698 NULL, |
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 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3701 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3702 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3703 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3704 if (p->pSecurityDescriptor == NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3705 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3706 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
|
3707 p = NULL; |
7 | 3708 } |
3709 } | |
3710 } | |
3711 | |
3712 return (vim_acl_T)p; | |
3713 #endif | |
3714 } | |
3715 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3716 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3717 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3718 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3719 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3720 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3721 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3722 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3723 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3724 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3725 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3726 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3727 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3728 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3729 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3730 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3731 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3732 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3733 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3734 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3735 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3736 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3737 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3738 |
7 | 3739 /* |
3740 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3741 * Errors are ignored. | |
3742 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3743 */ | |
3744 void | |
26 | 3745 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3746 { |
3747 #ifdef HAVE_ACL | |
3748 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
|
3749 SECURITY_INFORMATION sec_info = 0; |
7 | 3750 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3751 if (p != NULL) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3752 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3753 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3754 WCHAR *wn = NULL; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3755 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3756 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3757 /* Set security flags */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3758 if (p->pSidOwner) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3759 sec_info |= OWNER_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3760 if (p->pSidGroup) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3761 sec_info |= GROUP_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3762 if (p->pDacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3763 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3764 sec_info |= DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3765 /* Do not inherit its parent's DACL. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3766 * 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
|
3767 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3768 if (!is_acl_inherited(p->pDacl)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3769 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3770 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3771 if (p->pSacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3772 sec_info |= SACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3773 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3774 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3775 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3776 wn = enc_to_utf16(fname, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3777 if (wn != NULL) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3778 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3779 (void)SetNamedSecurityInfoW( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3780 wn, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3781 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3782 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3783 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3784 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3785 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3786 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3787 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3788 vim_free(wn); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3789 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3790 else |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3791 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3792 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3793 (void)SetNamedSecurityInfo( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3794 (LPSTR)fname, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3795 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3796 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3797 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3798 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3799 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3800 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3801 ); |
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 } |
7 | 3804 #endif |
3805 } | |
3806 | |
3807 void | |
26 | 3808 mch_free_acl(vim_acl_T acl) |
7 | 3809 { |
3810 #ifdef HAVE_ACL | |
3811 struct my_acl *p = (struct my_acl *)acl; | |
3812 | |
3813 if (p != NULL) | |
3814 { | |
3815 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3816 vim_free(p); | |
3817 } | |
3818 #endif | |
3819 } | |
3820 | |
3821 #ifndef FEAT_GUI_W32 | |
3822 | |
3823 /* | |
3824 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3825 */ | |
3826 static BOOL WINAPI | |
3827 handler_routine( | |
3828 DWORD dwCtrlType) | |
3829 { | |
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
|
3830 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
|
3831 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
|
3832 |
7 | 3833 switch (dwCtrlType) |
3834 { | |
3835 case CTRL_C_EVENT: | |
3836 if (ctrl_c_interrupts) | |
3837 g_fCtrlCPressed = TRUE; | |
3838 return TRUE; | |
3839 | |
3840 case CTRL_BREAK_EVENT: | |
3841 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
|
3842 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
|
3843 /* 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
|
3844 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
|
3845 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
|
3846 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
|
3847 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
|
3848 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
|
3849 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
|
3850 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
|
3851 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3852 return TRUE; |
3853 | |
3854 /* fatal events: shut down gracefully */ | |
3855 case CTRL_CLOSE_EVENT: | |
3856 case CTRL_LOGOFF_EVENT: | |
3857 case CTRL_SHUTDOWN_EVENT: | |
3858 windgoto((int)Rows - 1, 0); | |
3859 g_fForceExit = TRUE; | |
3860 | |
1569 | 3861 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3862 (dwCtrlType == CTRL_CLOSE_EVENT |
3863 ? _("close") | |
3864 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3865 ? _("logoff") | |
3866 : _("shutdown"))); | |
3867 #ifdef DEBUG | |
3868 OutputDebugString(IObuff); | |
3869 #endif | |
3870 | |
3871 preserve_exit(); /* output IObuff, preserve files and exit */ | |
3872 | |
3873 return TRUE; /* not reached */ | |
3874 | |
3875 default: | |
3876 return FALSE; | |
3877 } | |
3878 } | |
3879 | |
3880 | |
3881 /* | |
3882 * set the tty in (raw) ? "raw" : "cooked" mode | |
3883 */ | |
3884 void | |
26 | 3885 mch_settmode(int tmode) |
7 | 3886 { |
3887 DWORD cmodein; | |
3888 DWORD cmodeout; | |
3889 BOOL bEnableHandler; | |
3890 | |
3891 GetConsoleMode(g_hConIn, &cmodein); | |
3892 GetConsoleMode(g_hConOut, &cmodeout); | |
3893 if (tmode == TMODE_RAW) | |
3894 { | |
3895 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3896 ENABLE_ECHO_INPUT); | |
3897 #ifdef FEAT_MOUSE | |
3898 if (g_fMouseActive) | |
3899 cmodein |= ENABLE_MOUSE_INPUT; | |
3900 #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
|
3901 cmodeout &= ~( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3902 #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
|
3903 /* 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
|
3904 * VTP. */ |
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_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
|
3906 #else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3907 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
|
3908 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3909 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3910 bEnableHandler = TRUE; |
3911 } | |
3912 else /* cooked */ | |
3913 { | |
3914 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3915 ENABLE_ECHO_INPUT); | |
3916 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3917 bEnableHandler = FALSE; | |
3918 } | |
3919 SetConsoleMode(g_hConIn, cmodein); | |
3920 SetConsoleMode(g_hConOut, cmodeout); | |
3921 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3922 | |
3923 #ifdef MCH_WRITE_DUMP | |
3924 if (fdDump) | |
3925 { | |
3926 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3927 tmode == TMODE_RAW ? "raw" : | |
3928 tmode == TMODE_COOK ? "cooked" : "normal", | |
3929 cmodein, cmodeout); | |
3930 fflush(fdDump); | |
3931 } | |
3932 #endif | |
3933 } | |
3934 | |
3935 | |
3936 /* | |
3937 * Get the size of the current window in `Rows' and `Columns' | |
3938 * Return OK when size could be determined, FAIL otherwise. | |
3939 */ | |
3940 int | |
26 | 3941 mch_get_shellsize(void) |
7 | 3942 { |
3943 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3944 | |
3945 if (!g_fTermcapMode && g_cbTermcap.IsValid) | |
3946 { | |
3947 /* | |
3948 * For some reason, we are trying to get the screen dimensions | |
3949 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3950 * variables are really intended to mean the size of Vim screen | |
3951 * while in termcap mode. | |
3952 */ | |
3953 Rows = g_cbTermcap.Info.dwSize.Y; | |
3954 Columns = g_cbTermcap.Info.dwSize.X; | |
3955 } | |
3956 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3957 { | |
3958 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3959 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3960 } | |
3961 else | |
3962 { | |
3963 Rows = 25; | |
3964 Columns = 80; | |
3965 } | |
3966 return OK; | |
3967 } | |
3968 | |
3969 /* | |
3970 * Set a console window to `xSize' * `ySize' | |
3971 */ | |
3972 static void | |
3973 ResizeConBufAndWindow( | |
26 | 3974 HANDLE hConsole, |
3975 int xSize, | |
3976 int ySize) | |
7 | 3977 { |
3978 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ | |
3979 SMALL_RECT srWindowRect; /* hold the new console size */ | |
3980 COORD coordScreen; | |
3981 | |
3982 #ifdef MCH_WRITE_DUMP | |
3983 if (fdDump) | |
3984 { | |
3985 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3986 fflush(fdDump); | |
3987 } | |
3988 #endif | |
3989 | |
3990 /* get the largest size we can size the console window to */ | |
3991 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
3992 | |
3993 /* define the new console window size and scroll position */ | |
3994 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
3995 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3996 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3997 | |
3998 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3999 { | |
4000 int sx, sy; | |
4001 | |
4002 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
4003 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
4004 if (sy < ySize || sx < xSize) | |
4005 { | |
4006 /* | |
4007 * Increasing number of lines/columns, do buffer first. | |
4008 * Use the maximal size in x and y direction. | |
4009 */ | |
4010 if (sy < ySize) | |
4011 coordScreen.Y = ySize; | |
4012 else | |
4013 coordScreen.Y = sy; | |
4014 if (sx < xSize) | |
4015 coordScreen.X = xSize; | |
4016 else | |
4017 coordScreen.X = sx; | |
4018 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
4019 } | |
4020 } | |
4021 | |
4022 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &srWindowRect)) | |
4023 { | |
4024 #ifdef MCH_WRITE_DUMP | |
4025 if (fdDump) | |
4026 { | |
4027 fprintf(fdDump, "SetConsoleWindowInfo failed: %lx\n", | |
4028 GetLastError()); | |
4029 fflush(fdDump); | |
4030 } | |
4031 #endif | |
4032 } | |
4033 | |
4034 /* define the new console buffer size */ | |
4035 coordScreen.X = xSize; | |
4036 coordScreen.Y = ySize; | |
4037 | |
4038 if (!SetConsoleScreenBufferSize(hConsole, coordScreen)) | |
4039 { | |
4040 #ifdef MCH_WRITE_DUMP | |
4041 if (fdDump) | |
4042 { | |
4043 fprintf(fdDump, "SetConsoleScreenBufferSize failed: %lx\n", | |
4044 GetLastError()); | |
4045 fflush(fdDump); | |
4046 } | |
4047 #endif | |
4048 } | |
4049 } | |
4050 | |
4051 | |
4052 /* | |
4053 * Set the console window to `Rows' * `Columns' | |
4054 */ | |
4055 void | |
26 | 4056 mch_set_shellsize(void) |
7 | 4057 { |
4058 COORD coordScreen; | |
4059 | |
4060 /* Don't change window size while still starting up */ | |
4061 if (suppress_winsize != 0) | |
4062 { | |
4063 suppress_winsize = 2; | |
4064 return; | |
4065 } | |
4066 | |
4067 if (term_console) | |
4068 { | |
4069 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
4070 | |
4071 /* Clamp Rows and Columns to reasonable values */ | |
4072 if (Rows > coordScreen.Y) | |
4073 Rows = coordScreen.Y; | |
4074 if (Columns > coordScreen.X) | |
4075 Columns = coordScreen.X; | |
4076 | |
4077 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
4078 } | |
4079 } | |
4080 | |
4081 /* | |
4082 * Rows and/or Columns has changed. | |
4083 */ | |
4084 void | |
26 | 4085 mch_new_shellsize(void) |
7 | 4086 { |
4087 set_scroll_region(0, 0, Columns - 1, Rows - 1); | |
4088 } | |
4089 | |
4090 | |
4091 /* | |
4092 * Called when started up, to set the winsize that was delayed. | |
4093 */ | |
4094 void | |
26 | 4095 mch_set_winsize_now(void) |
7 | 4096 { |
4097 if (suppress_winsize == 2) | |
4098 { | |
4099 suppress_winsize = 0; | |
4100 mch_set_shellsize(); | |
4101 shell_resized(); | |
4102 } | |
4103 suppress_winsize = 0; | |
4104 } | |
4105 #endif /* FEAT_GUI_W32 */ | |
4106 | |
5547 | 4107 static BOOL |
4108 vim_create_process( | |
5556 | 4109 char *cmd, |
5569 | 4110 BOOL inherit_handles, |
5547 | 4111 DWORD flags, |
4112 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
|
4113 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
|
4114 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4115 char *cwd) |
5547 | 4116 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4117 #ifdef FEAT_MBYTE |
5547 | 4118 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
4119 { | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4120 BOOL ret; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4121 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
|
4122 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4123 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
|
4124 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
|
4125 goto fallback; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4126 if (cwd != NULL) |
5547 | 4127 { |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4128 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
|
4129 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
|
4130 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4131 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
|
4132 goto fallback; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4133 } |
5547 | 4134 } |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4135 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4136 ret = CreateProcessW( |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4137 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
|
4138 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
|
4139 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
|
4140 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
|
4141 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
|
4142 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
|
4143 env, /* Environment */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4144 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
|
4145 (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
|
4146 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
|
4147 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
|
4148 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
|
4149 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
|
4150 return ret; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4151 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4152 fallback: |
5547 | 4153 #endif |
4154 return CreateProcess( | |
4155 NULL, /* Executable name */ | |
4156 cmd, /* Command to execute */ | |
4157 NULL, /* Process security attributes */ | |
4158 NULL, /* Thread security attributes */ | |
4159 inherit_handles, /* Inherit handles */ | |
4160 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
|
4161 env, /* Environment */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4162 cwd, /* Current directory */ |
5547 | 4163 si, /* Startup information */ |
4164 pi); /* Process information */ | |
4165 } | |
7 | 4166 |
4167 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4168 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
|
4169 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
|
4170 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
|
4171 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
|
4172 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4173 #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
|
4174 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
|
4175 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4176 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
|
4177 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
|
4178 { |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4179 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
|
4180 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
|
4181 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
|
4182 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
|
4183 } |
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 #endif |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4186 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
|
4187 } |
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 |
7 | 4190 #if defined(FEAT_GUI_W32) || defined(PROTO) |
4191 | |
4192 /* | |
4193 * Specialised version of system() for Win32 GUI mode. | |
4194 * This version proceeds as follows: | |
4195 * 1. Create a console window for use by the subprocess | |
4196 * 2. Run the subprocess (it gets the allocated console by default) | |
4197 * 3. Wait for the subprocess to terminate and get its exit code | |
4198 * 4. Prompt the user to press a key to close the console window | |
4199 */ | |
4200 static int | |
2935 | 4201 mch_system_classic(char *cmd, int options) |
7 | 4202 { |
4203 STARTUPINFO si; | |
4204 PROCESS_INFORMATION pi; | |
4205 DWORD ret = 0; | |
4206 HWND hwnd = GetFocus(); | |
4207 | |
4208 si.cb = sizeof(si); | |
4209 si.lpReserved = NULL; | |
4210 si.lpDesktop = NULL; | |
4211 si.lpTitle = NULL; | |
4212 si.dwFlags = STARTF_USESHOWWINDOW; | |
4213 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4214 * It's nicer to run a filter command in a minimized window. |
2643 | 4215 * Don't activate the window to keep focus on Vim. |
7 | 4216 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4217 if (options & SHELL_DOOUT) |
2643 | 4218 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 4219 else |
4220 si.wShowWindow = SW_SHOWNORMAL; | |
4221 si.cbReserved2 = 0; | |
4222 si.lpReserved2 = NULL; | |
4223 | |
4224 /* Now, run the command */ | |
5547 | 4225 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
|
4226 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
|
4227 &si, &pi, NULL, NULL); |
7 | 4228 |
4229 /* Wait for the command to terminate before continuing */ | |
4230 { | |
4231 #ifdef FEAT_GUI | |
4232 int delay = 1; | |
4233 | |
4234 /* Keep updating the window while waiting for the shell to finish. */ | |
4235 for (;;) | |
4236 { | |
4237 MSG msg; | |
4238 | |
3010 | 4239 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 4240 { |
4241 TranslateMessage(&msg); | |
3010 | 4242 pDispatchMessage(&msg); |
3720 | 4243 delay = 1; |
4244 continue; | |
7 | 4245 } |
4246 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4247 break; | |
4248 | |
4249 /* We start waiting for a very short time and then increase it, so | |
4250 * that we respond quickly when the process is quick, and don't | |
4251 * consume too much overhead when it's slow. */ | |
4252 if (delay < 50) | |
4253 delay += 10; | |
4254 } | |
4255 #else | |
4256 WaitForSingleObject(pi.hProcess, INFINITE); | |
4257 #endif | |
4258 | |
4259 /* Get the command exit code */ | |
4260 GetExitCodeProcess(pi.hProcess, &ret); | |
4261 } | |
4262 | |
4263 /* Close the handles to the subprocess, so that it goes away */ | |
4264 CloseHandle(pi.hThread); | |
4265 CloseHandle(pi.hProcess); | |
4266 | |
4267 /* Try to get input focus back. Doesn't always work though. */ | |
4268 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
4269 | |
4270 return ret; | |
4271 } | |
2935 | 4272 |
4273 /* | |
4274 * Thread launched by the gui to send the current buffer data to the | |
4275 * process. This way avoid to hang up vim totally if the children | |
4276 * process take a long time to process the lines. | |
4277 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4278 static unsigned int __stdcall |
2935 | 4279 sub_process_writer(LPVOID param) |
4280 { | |
4281 HANDLE g_hChildStd_IN_Wr = param; | |
4282 linenr_T lnum = curbuf->b_op_start.lnum; | |
4283 DWORD len = 0; | |
4284 DWORD l; | |
4285 char_u *lp = ml_get(lnum); | |
4286 char_u *s; | |
4287 int written = 0; | |
4288 | |
4289 for (;;) | |
4290 { | |
4291 l = (DWORD)STRLEN(lp + written); | |
4292 if (l == 0) | |
4293 len = 0; | |
4294 else if (lp[written] == NL) | |
4295 { | |
4296 /* NL -> NUL translation */ | |
4297 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
4298 } | |
4299 else | |
4300 { | |
4301 s = vim_strchr(lp + written, NL); | |
4302 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4303 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4304 &len, NULL); | |
4305 } | |
4306 if (len == (int)l) | |
4307 { | |
4308 /* Finished a line, add a NL, unless this line should not have | |
4309 * one. */ | |
4310 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4311 || (!curbuf->b_p_bin |
4312 && curbuf->b_p_fixeol) | |
2935 | 4313 || (lnum != curbuf->b_no_eol_lnum |
4314 && (lnum != curbuf->b_ml.ml_line_count | |
4315 || curbuf->b_p_eol))) | |
4316 { | |
4238 | 4317 WriteFile(g_hChildStd_IN_Wr, "\n", 1, (LPDWORD)&ignored, NULL); |
2935 | 4318 } |
4319 | |
4320 ++lnum; | |
4321 if (lnum > curbuf->b_op_end.lnum) | |
4322 break; | |
4323 | |
4324 lp = ml_get(lnum); | |
4325 written = 0; | |
4326 } | |
4327 else if (len > 0) | |
4328 written += len; | |
4329 } | |
4330 | |
4331 /* finished all the lines, close pipe */ | |
4332 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4333 return 0; |
2935 | 4334 } |
4335 | |
4336 | |
4337 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4338 | |
4339 /* | |
4340 * This function read from the children's stdout and write the | |
4341 * data on screen or in the buffer accordingly. | |
4342 */ | |
4343 static void | |
4344 dump_pipe(int options, | |
4345 HANDLE g_hChildStd_OUT_Rd, | |
4346 garray_T *ga, | |
4347 char_u buffer[], | |
4348 DWORD *buffer_off) | |
4349 { | |
4350 DWORD availableBytes = 0; | |
4351 DWORD i; | |
4352 int ret; | |
4353 DWORD len; | |
4354 DWORD toRead; | |
4355 int repeatCount; | |
4356 | |
4357 /* we query the pipe to see if there is any data to read | |
4358 * to avoid to perform a blocking read */ | |
4359 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4360 NULL, /* optional buffer */ | |
3622 | 4361 0, /* buffer size */ |
2935 | 4362 NULL, /* number of read bytes */ |
4363 &availableBytes, /* available bytes total */ | |
4364 NULL); /* byteLeft */ | |
4365 | |
4366 repeatCount = 0; | |
4367 /* We got real data in the pipe, read it */ | |
3622 | 4368 while (ret != 0 && availableBytes > 0) |
2935 | 4369 { |
4370 repeatCount++; | |
4371 toRead = | |
4372 # ifdef FEAT_MBYTE | |
4373 (DWORD)(BUFLEN - *buffer_off); | |
4374 # else | |
4375 (DWORD)BUFLEN; | |
4376 # endif | |
4377 toRead = availableBytes < toRead ? availableBytes : toRead; | |
4378 ReadFile(g_hChildStd_OUT_Rd, buffer | |
4379 # ifdef FEAT_MBYTE | |
4380 + *buffer_off, toRead | |
4381 # else | |
4382 , toRead | |
4383 # endif | |
4384 , &len, NULL); | |
4385 | |
4386 /* If we haven't read anything, there is a problem */ | |
4387 if (len == 0) | |
4388 break; | |
4389 | |
4390 availableBytes -= len; | |
4391 | |
4392 if (options & SHELL_READ) | |
4393 { | |
4394 /* Do NUL -> NL translation, append NL separated | |
4395 * lines to the current buffer. */ | |
4396 for (i = 0; i < len; ++i) | |
4397 { | |
4398 if (buffer[i] == NL) | |
4399 append_ga_line(ga); | |
4400 else if (buffer[i] == NUL) | |
4401 ga_append(ga, NL); | |
4402 else | |
4403 ga_append(ga, buffer[i]); | |
4404 } | |
4405 } | |
4406 # ifdef FEAT_MBYTE | |
4407 else if (has_mbyte) | |
4408 { | |
4409 int l; | |
3030 | 4410 int c; |
4411 char_u *p; | |
2935 | 4412 |
4413 len += *buffer_off; | |
4414 buffer[len] = NUL; | |
4415 | |
4416 /* Check if the last character in buffer[] is | |
4417 * incomplete, keep these bytes for the next | |
4418 * round. */ | |
4419 for (p = buffer; p < buffer + len; p += l) | |
4420 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4421 l = MB_CPTR2LEN(p); |
2935 | 4422 if (l == 0) |
4423 l = 1; /* NUL byte? */ | |
4424 else if (MB_BYTE2LEN(*p) != l) | |
4425 break; | |
4426 } | |
4427 if (p == buffer) /* no complete character */ | |
4428 { | |
4429 /* avoid getting stuck at an illegal byte */ | |
4430 if (len >= 12) | |
4431 ++p; | |
4432 else | |
4433 { | |
4434 *buffer_off = len; | |
4435 return; | |
4436 } | |
4437 } | |
4438 c = *p; | |
4439 *p = NUL; | |
4440 msg_puts(buffer); | |
4441 if (p < buffer + len) | |
4442 { | |
4443 *p = c; | |
4444 *buffer_off = (DWORD)((buffer + len) - p); | |
4445 mch_memmove(buffer, p, *buffer_off); | |
4446 return; | |
4447 } | |
4448 *buffer_off = 0; | |
4449 } | |
4450 # endif /* FEAT_MBYTE */ | |
4451 else | |
4452 { | |
4453 buffer[len] = NUL; | |
4454 msg_puts(buffer); | |
4455 } | |
4456 | |
4457 windgoto(msg_row, msg_col); | |
4458 cursor_on(); | |
4459 out_flush(); | |
4460 } | |
4461 } | |
4462 | |
4463 /* | |
4464 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4465 * for communication and doesn't open any new window. | |
4466 */ | |
4467 static int | |
4468 mch_system_piped(char *cmd, int options) | |
4469 { | |
4470 STARTUPINFO si; | |
4471 PROCESS_INFORMATION pi; | |
4472 DWORD ret = 0; | |
4473 | |
4474 HANDLE g_hChildStd_IN_Rd = NULL; | |
4475 HANDLE g_hChildStd_IN_Wr = NULL; | |
4476 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4477 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4478 | |
4479 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4480 DWORD len; | |
4481 | |
4482 /* buffer used to receive keys */ | |
4483 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4484 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4485 | |
4486 DWORD i; | |
4487 int c; | |
4488 int noread_cnt = 0; | |
4489 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
|
4490 int delay = 1; |
2935 | 4491 DWORD buffer_off = 0; /* valid bytes in buffer[] */ |
3361 | 4492 char *p = NULL; |
2935 | 4493 |
4494 SECURITY_ATTRIBUTES saAttr; | |
4495 | |
4496 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4497 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4498 saAttr.bInheritHandle = TRUE; | |
4499 saAttr.lpSecurityDescriptor = NULL; | |
4500 | |
4501 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4502 /* 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
|
4503 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4504 /* Create a pipe for the child process's STDIN. */ |
4505 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4506 /* 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
|
4507 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4508 { |
4509 CloseHandle(g_hChildStd_IN_Rd); | |
4510 CloseHandle(g_hChildStd_IN_Wr); | |
4511 CloseHandle(g_hChildStd_OUT_Rd); | |
4512 CloseHandle(g_hChildStd_OUT_Wr); | |
4513 MSG_PUTS(_("\nCannot create pipes\n")); | |
4514 } | |
4515 | |
4516 si.cb = sizeof(si); | |
4517 si.lpReserved = NULL; | |
4518 si.lpDesktop = NULL; | |
4519 si.lpTitle = NULL; | |
4520 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4521 | |
4522 /* set-up our file redirection */ | |
4523 si.hStdError = g_hChildStd_OUT_Wr; | |
4524 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4525 si.hStdInput = g_hChildStd_IN_Rd; | |
4526 si.wShowWindow = SW_HIDE; | |
4527 si.cbReserved2 = 0; | |
4528 si.lpReserved2 = NULL; | |
4529 | |
4530 if (options & SHELL_READ) | |
4531 ga_init2(&ga, 1, BUFLEN); | |
4532 | |
3361 | 4533 if (cmd != NULL) |
4534 { | |
4535 p = (char *)vim_strsave((char_u *)cmd); | |
4536 if (p != NULL) | |
4537 unescape_shellxquote((char_u *)p, p_sxe); | |
4538 else | |
4539 p = cmd; | |
4540 } | |
4541 | |
5547 | 4542 /* Now, run the command. |
4543 * About "Inherit handles" being TRUE: this command can be litigious, | |
4544 * handle inheritance was deactivated for pending temp file, but, if we | |
4545 * 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
|
4546 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
|
4547 &si, &pi, NULL, NULL); |
2935 | 4548 |
3361 | 4549 if (p != cmd) |
4550 vim_free(p); | |
2935 | 4551 |
4552 /* Close our unused side of the pipes */ | |
4553 CloseHandle(g_hChildStd_IN_Rd); | |
4554 CloseHandle(g_hChildStd_OUT_Wr); | |
4555 | |
4556 if (options & SHELL_WRITE) | |
4557 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4558 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4559 _beginthreadex(NULL, /* security attributes */ |
2935 | 4560 0, /* default stack size */ |
4561 sub_process_writer, /* function to be executed */ | |
4562 g_hChildStd_IN_Wr, /* parameter */ | |
4563 0, /* creation flag, start immediately */ | |
4564 NULL); /* we don't care about thread id */ | |
4565 CloseHandle(thread); | |
4566 g_hChildStd_IN_Wr = NULL; | |
4567 } | |
4568 | |
4569 /* Keep updating the window while waiting for the shell to finish. */ | |
4570 for (;;) | |
4571 { | |
4572 MSG msg; | |
4573 | |
5553 | 4574 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4575 { |
4576 TranslateMessage(&msg); | |
5553 | 4577 pDispatchMessage(&msg); |
2935 | 4578 } |
4579 | |
4580 /* write pipe information in the window */ | |
4581 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4582 # ifdef FEAT_GUI | |
4583 || gui.in_use | |
4584 # endif | |
4585 ) | |
4586 { | |
4587 len = 0; | |
4588 if (!(options & SHELL_EXPAND) | |
4589 && ((options & | |
4590 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4591 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4592 # ifdef FEAT_GUI | |
4593 || gui.in_use | |
4594 # endif | |
4595 ) | |
4596 && (ta_len > 0 || noread_cnt > 4)) | |
4597 { | |
4598 if (ta_len == 0) | |
4599 { | |
4600 /* Get extra characters when we don't have any. Reset the | |
4601 * counter and timer. */ | |
4602 noread_cnt = 0; | |
4603 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4604 } | |
4605 if (ta_len > 0 || len > 0) | |
4606 { | |
4607 /* | |
4608 * For pipes: Check for CTRL-C: send interrupt signal to | |
4609 * child. Check for CTRL-D: EOF, close pipe to child. | |
4610 */ | |
4611 if (len == 1 && cmd != NULL) | |
4612 { | |
4613 if (ta_buf[ta_len] == Ctrl_C) | |
4614 { | |
4615 /* Learn what exit code is expected, for | |
4616 * now put 9 as SIGKILL */ | |
4617 TerminateProcess(pi.hProcess, 9); | |
4618 } | |
4619 if (ta_buf[ta_len] == Ctrl_D) | |
4620 { | |
4621 CloseHandle(g_hChildStd_IN_Wr); | |
4622 g_hChildStd_IN_Wr = NULL; | |
4623 } | |
4624 } | |
4625 | |
4626 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4627 for (i = ta_len; i < ta_len + len; ++i) | |
4628 { | |
4629 if (ta_buf[i] == CSI && len - i > 2) | |
4630 { | |
4631 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4632 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4633 { | |
4634 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4635 (size_t)(len - i - 2)); | |
4636 if (c == K_DEL || c == K_KDEL) | |
4637 ta_buf[i] = DEL; | |
4638 else | |
4639 ta_buf[i] = Ctrl_H; | |
4640 len -= 2; | |
4641 } | |
4642 } | |
4643 else if (ta_buf[i] == '\r') | |
4644 ta_buf[i] = '\n'; | |
4645 # ifdef FEAT_MBYTE | |
4646 if (has_mbyte) | |
4647 i += (*mb_ptr2len_len)(ta_buf + i, | |
4648 ta_len + len - i) - 1; | |
4649 # endif | |
4650 } | |
4651 | |
4652 /* | |
4653 * For pipes: echo the typed characters. For a pty this | |
4654 * does not seem to work. | |
4655 */ | |
4656 for (i = ta_len; i < ta_len + len; ++i) | |
4657 { | |
4658 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4659 msg_putchar(ta_buf[i]); | |
4660 # ifdef FEAT_MBYTE | |
4661 else if (has_mbyte) | |
4662 { | |
4663 int l = (*mb_ptr2len)(ta_buf + i); | |
4664 | |
4665 msg_outtrans_len(ta_buf + i, l); | |
4666 i += l - 1; | |
4667 } | |
4668 # endif | |
4669 else | |
4670 msg_outtrans_len(ta_buf + i, 1); | |
4671 } | |
4672 windgoto(msg_row, msg_col); | |
4673 out_flush(); | |
4674 | |
4675 ta_len += len; | |
4676 | |
4677 /* | |
4678 * Write the characters to the child, unless EOF has been | |
4679 * typed for pipes. Write one character at a time, to | |
4680 * avoid losing too much typeahead. When writing buffer | |
4681 * lines, drop the typed characters (only check for | |
4682 * CTRL-C). | |
4683 */ | |
4684 if (options & SHELL_WRITE) | |
4685 ta_len = 0; | |
4686 else if (g_hChildStd_IN_Wr != NULL) | |
4687 { | |
4688 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4689 1, &len, NULL); | |
4690 // if we are typing in, we want to keep things reactive | |
4691 delay = 1; | |
4692 if (len > 0) | |
4693 { | |
4694 ta_len -= len; | |
4695 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4696 } | |
4697 } | |
4698 } | |
4699 } | |
4700 } | |
4701 | |
4702 if (ta_len) | |
4703 ui_inchar_undo(ta_buf, ta_len); | |
4704 | |
4705 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4706 { | |
3030 | 4707 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4708 break; |
4709 } | |
4710 | |
4711 ++noread_cnt; | |
3030 | 4712 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4713 |
4714 /* We start waiting for a very short time and then increase it, so | |
4715 * that we respond quickly when the process is quick, and don't | |
4716 * consume too much overhead when it's slow. */ | |
4717 if (delay < 50) | |
4718 delay += 10; | |
4719 } | |
4720 | |
4721 /* Close the pipe */ | |
4722 CloseHandle(g_hChildStd_OUT_Rd); | |
4723 if (g_hChildStd_IN_Wr != NULL) | |
4724 CloseHandle(g_hChildStd_IN_Wr); | |
4725 | |
4726 WaitForSingleObject(pi.hProcess, INFINITE); | |
4727 | |
4728 /* Get the command exit code */ | |
4729 GetExitCodeProcess(pi.hProcess, &ret); | |
4730 | |
4731 if (options & SHELL_READ) | |
4732 { | |
4733 if (ga.ga_len > 0) | |
4734 { | |
4735 append_ga_line(&ga); | |
4736 /* remember that the NL was missing */ | |
4737 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4738 } | |
4739 else | |
4740 curbuf->b_no_eol_lnum = 0; | |
4741 ga_clear(&ga); | |
4742 } | |
4743 | |
4744 /* Close the handles to the subprocess, so that it goes away */ | |
4745 CloseHandle(pi.hThread); | |
4746 CloseHandle(pi.hProcess); | |
4747 | |
4748 return ret; | |
4749 } | |
4750 | |
4751 static int | |
4752 mch_system(char *cmd, int options) | |
4753 { | |
4754 /* 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
|
4755 if (!p_stmp) |
2935 | 4756 return mch_system_piped(cmd, options); |
4757 else | |
4758 return mch_system_classic(cmd, options); | |
4759 } | |
7 | 4760 #else |
4761 | |
5547 | 4762 # ifdef FEAT_MBYTE |
4763 static int | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4764 mch_system(char *cmd, int options) |
5547 | 4765 { |
4766 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4767 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4768 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 4769 if (wcmd != NULL) |
4770 { | |
4771 int ret = _wsystem(wcmd); | |
4772 vim_free(wcmd); | |
4773 return ret; | |
4774 } | |
4775 } | |
4776 return system(cmd); | |
4777 } | |
4778 # else | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4779 # define mch_system(c, o) system(c) |
5547 | 4780 # endif |
7 | 4781 |
4782 #endif | |
4783 | |
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
|
4784 #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
|
4785 /* |
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 * 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
|
4787 */ |
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 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
|
4789 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
|
4790 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
|
4791 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
|
4792 { |
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 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
|
4794 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
|
4795 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
|
4796 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
|
4797 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
|
4798 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
|
4799 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
|
4800 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
|
4801 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4802 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4803 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
|
4804 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4805 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
|
4806 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
|
4807 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
|
4808 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4809 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4810 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4811 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
|
4812 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
|
4813 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4814 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4815 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4816 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
|
4817 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
|
4818 } |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4819 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4820 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
|
4821 |
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 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
|
4823 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
|
4824 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
|
4825 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
|
4826 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
|
4827 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
|
4828 |
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 /* 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
|
4830 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
|
4831 |
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 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
|
4833 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
|
4834 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4835 if (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
|
4836 { |
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 /* 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
|
4838 * 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
|
4839 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
|
4840 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
|
4841 } |
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 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
|
4843 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
|
4844 } |
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 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
|
4846 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
|
4847 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4848 /* 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
|
4849 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
|
4850 |
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 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
|
4852 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
|
4853 |
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 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
|
4855 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
|
4856 } |
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 #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
|
4858 |
7 | 4859 /* |
4860 * Either execute a command by calling the shell or start a new shell | |
4861 */ | |
4862 int | |
4863 mch_call_shell( | |
26 | 4864 char_u *cmd, |
4865 int options) /* SHELL_*, see vim.h */ | |
7 | 4866 { |
4867 int x = 0; | |
4868 int tmode = cur_tmode; | |
4869 #ifdef FEAT_TITLE | |
6293 | 4870 char szShellTitle[512]; |
6290 | 4871 # ifdef FEAT_MBYTE |
6293 | 4872 int did_set_title = FALSE; |
4873 | |
6290 | 4874 /* Change the title to reflect that we are in a subshell. */ |
4875 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4876 { | |
4877 WCHAR szShellTitle[512]; | |
4878 | |
4879 if (GetConsoleTitleW(szShellTitle, | |
4880 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) | |
4881 { | |
4882 if (cmd == NULL) | |
4883 wcscat(szShellTitle, L" :sh"); | |
4884 else | |
4885 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4886 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL); |
6290 | 4887 |
4888 if (wn != NULL) | |
4889 { | |
4890 wcscat(szShellTitle, L" - !"); | |
4891 if ((wcslen(szShellTitle) + wcslen(wn) < | |
4892 sizeof(szShellTitle)/sizeof(WCHAR))) | |
4893 wcscat(szShellTitle, wn); | |
4894 SetConsoleTitleW(szShellTitle); | |
4895 vim_free(wn); | |
6293 | 4896 did_set_title = TRUE; |
6290 | 4897 } |
4898 } | |
4899 } | |
4900 } | |
6293 | 4901 if (!did_set_title) |
4902 # endif | |
4903 /* Change the title to reflect that we are in a subshell. */ | |
4904 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0) | |
7 | 4905 { |
6293 | 4906 if (cmd == NULL) |
4907 strcat(szShellTitle, " :sh"); | |
4908 else | |
4909 { | |
4910 strcat(szShellTitle, " - !"); | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4911 if ((strlen(szShellTitle) + strlen((char *)cmd) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4912 < sizeof(szShellTitle))) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4913 strcat(szShellTitle, (char *)cmd); |
6293 | 4914 } |
4915 SetConsoleTitle(szShellTitle); | |
7 | 4916 } |
4917 #endif | |
4918 | |
4919 out_flush(); | |
4920 | |
4921 #ifdef MCH_WRITE_DUMP | |
4922 if (fdDump) | |
4923 { | |
4924 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4925 fflush(fdDump); | |
4926 } | |
4927 #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
|
4928 #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
|
4929 /* 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
|
4930 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
|
4931 && (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
|
4932 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4933 /* 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
|
4934 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
|
4935 #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
|
4936 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
|
4937 #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
|
4938 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
|
4939 } |
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 #endif |
7 | 4941 |
4942 /* | |
4943 * Catch all deadly signals while running the external command, because a | |
4944 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4945 */ | |
4946 signal(SIGINT, SIG_IGN); | |
4947 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4948 signal(SIGKILL, SIG_IGN); | |
4949 #else | |
4950 signal(SIGBREAK, SIG_IGN); | |
4951 #endif | |
4952 signal(SIGILL, SIG_IGN); | |
4953 signal(SIGFPE, SIG_IGN); | |
4954 signal(SIGSEGV, SIG_IGN); | |
4955 signal(SIGTERM, SIG_IGN); | |
4956 signal(SIGABRT, SIG_IGN); | |
4957 | |
4958 if (options & SHELL_COOKED) | |
4959 settmode(TMODE_COOK); /* set to normal mode */ | |
4960 | |
4961 if (cmd == NULL) | |
4962 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4963 x = mch_system((char *)p_sh, options); |
7 | 4964 } |
4965 else | |
4966 { | |
4967 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 4968 char_u *newcmd = NULL; |
4969 char_u *cmdbase = cmd; | |
4970 long_u cmdlen; | |
3361 | 4971 |
4972 /* Skip a leading ", ( and "(. */ | |
4973 if (*cmdbase == '"' ) | |
4974 ++cmdbase; | |
4975 if (*cmdbase == '(') | |
4976 ++cmdbase; | |
4977 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4978 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 4979 { |
4980 STARTUPINFO si; | |
4981 PROCESS_INFORMATION pi; | |
4982 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
|
4983 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 4984 char_u *p; |
4985 | |
5627 | 4986 ZeroMemory(&si, sizeof(si)); |
3361 | 4987 si.cb = sizeof(si); |
4988 si.lpReserved = NULL; | |
4989 si.lpDesktop = NULL; | |
4990 si.lpTitle = NULL; | |
4991 si.dwFlags = 0; | |
4992 si.cbReserved2 = 0; | |
4993 si.lpReserved2 = NULL; | |
4994 | |
4995 cmdbase = skipwhite(cmdbase + 5); | |
4996 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
|
4997 && VIM_ISWHITE(cmdbase[4])) |
3361 | 4998 { |
4999 cmdbase = skipwhite(cmdbase + 4); | |
5000 si.dwFlags = STARTF_USESHOWWINDOW; | |
5001 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
|
5002 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 5003 } |
5004 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
|
5005 && VIM_ISWHITE(cmdbase[2])) |
3361 | 5006 { |
5007 cmdbase = skipwhite(cmdbase + 2); | |
5008 flags = CREATE_NO_WINDOW; | |
5009 si.dwFlags = STARTF_USESTDHANDLES; | |
5010 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 5011 GENERIC_READ, // Access flags |
3361 | 5012 0, // Share flags |
3363 | 5013 NULL, // Security att. |
5014 OPEN_EXISTING, // Open flags | |
5015 FILE_ATTRIBUTE_NORMAL, // File att. | |
5016 NULL); // Temp file | |
3361 | 5017 si.hStdOutput = si.hStdInput; |
5018 si.hStdError = si.hStdInput; | |
5019 } | |
5020 | |
5021 /* Remove a trailing ", ) and )" if they have a match | |
5022 * at the start of the command. */ | |
5023 if (cmdbase > cmd) | |
5024 { | |
5025 p = cmdbase + STRLEN(cmdbase); | |
5026 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
5027 *--p = NUL; | |
5028 if (p > cmdbase && p[-1] == ')' | |
5029 && (*cmd =='(' || cmd[1] == '(')) | |
5030 *--p = NUL; | |
5031 } | |
5032 | |
3363 | 5033 newcmd = cmdbase; |
5034 unescape_shellxquote(cmdbase, p_sxe); | |
5035 | |
3361 | 5036 /* |
3363 | 5037 * If creating new console, arguments are passed to the |
5038 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
5039 * correctly for current 'cmd.exe'. So unescape characters in | |
5040 * shellxescape except '|' for avoiding to be treated as | |
5041 * argument to them. Pass the arguments to sub-shell. | |
3361 | 5042 */ |
3363 | 5043 if (flags != CREATE_NEW_CONSOLE) |
5044 { | |
5045 char_u *subcmd; | |
3367 | 5046 char_u *cmd_shell = mch_getenv("COMSPEC"); |
5047 | |
5048 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
|
5049 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5050 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5051 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5052 (char_u *)"|", '^', FALSE); |
3363 | 5053 if (subcmd != NULL) |
5054 { | |
5055 /* make "cmd.exe /c arguments" */ | |
5056 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
5057 newcmd = lalloc(cmdlen, TRUE); | |
5058 if (newcmd != NULL) | |
5059 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 5060 cmd_shell, subcmd); |
3363 | 5061 else |
5062 newcmd = cmdbase; | |
3367 | 5063 vim_free(subcmd); |
3363 | 5064 } |
5065 } | |
3361 | 5066 |
5067 /* | |
5068 * Now, start the command as a process, so that it doesn't | |
5069 * inherit our handles which causes unpleasant dangling swap | |
5070 * files if we exit before the spawned process | |
5071 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5072 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
|
5073 &si, &pi, NULL, NULL)) |
3361 | 5074 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
|
5075 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
|
5076 > (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
|
5077 x = 0; |
3361 | 5078 else |
5079 { | |
5080 x = -1; | |
5081 #ifdef FEAT_GUI_W32 | |
5082 EMSG(_("E371: Command not found")); | |
5083 #endif | |
5084 } | |
3363 | 5085 |
5086 if (newcmd != cmdbase) | |
5087 vim_free(newcmd); | |
5088 | |
5627 | 5089 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 5090 { |
5627 | 5091 /* Close the handle to \\.\NUL created above. */ |
3361 | 5092 CloseHandle(si.hStdInput); |
5093 } | |
5094 /* Close the handles to the subprocess, so that it goes away */ | |
5095 CloseHandle(pi.hThread); | |
5096 CloseHandle(pi.hProcess); | |
5097 } | |
5098 else | |
5099 { | |
3363 | 5100 cmdlen = ( |
7 | 5101 #ifdef FEAT_GUI_W32 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5102 (!p_stmp ? 0 : STRLEN(vimrun_path)) + |
7 | 5103 #endif |
1569 | 5104 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10); |
5105 | |
3361 | 5106 newcmd = lalloc(cmdlen, TRUE); |
5107 if (newcmd != NULL) | |
7 | 5108 { |
5109 #if defined(FEAT_GUI_W32) | |
5110 if (need_vimrun_warning) | |
5111 { | |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5112 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
|
5113 "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
|
5114 "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
|
5115 char *title = _("Vim Warning"); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5116 # ifdef FEAT_MBYTE |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5117 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
|
5118 { |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5119 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
|
5120 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
|
5121 |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5122 if (wmsg != NULL && wtitle != NULL) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5123 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5124 vim_free(wmsg); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5125 vim_free(wtitle); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5126 } |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5127 else |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5128 # endif |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5129 MessageBox(NULL, msg, title, MB_ICONWARNING); |
7 | 5130 need_vimrun_warning = FALSE; |
5131 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5132 if (!s_dont_use_vimrun && p_stmp) |
7 | 5133 /* Use vimrun to execute the command. It opens a console |
5134 * 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
|
5135 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 5136 vimrun_path, |
5137 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
5138 ? "-s " : "", | |
5139 p_sh, p_shcf, cmd); | |
5140 else | |
5141 #endif | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5142 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 5143 p_sh, p_shcf, cmd); |
7 | 5144 x = mch_system((char *)newcmd, options); |
3361 | 5145 vim_free(newcmd); |
7 | 5146 } |
5147 } | |
5148 } | |
5149 | |
5150 if (tmode == TMODE_RAW) | |
5151 settmode(TMODE_RAW); /* set to raw mode */ | |
5152 | |
5153 /* Print the return value, unless "vimrun" was used. */ | |
5154 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent | |
5155 #if defined(FEAT_GUI_W32) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5156 && ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) |
7 | 5157 #endif |
5158 ) | |
5159 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5160 smsg((char_u *)_("shell returned %d"), x); |
7 | 5161 msg_putchar('\n'); |
5162 } | |
5163 #ifdef FEAT_TITLE | |
5164 resettitle(); | |
5165 #endif | |
5166 | |
5167 signal(SIGINT, SIG_DFL); | |
5168 #if defined(__GNUC__) && !defined(__MINGW32__) | |
5169 signal(SIGKILL, SIG_DFL); | |
5170 #else | |
5171 signal(SIGBREAK, SIG_DFL); | |
5172 #endif | |
5173 signal(SIGILL, SIG_DFL); | |
5174 signal(SIGFPE, SIG_DFL); | |
5175 signal(SIGSEGV, SIG_DFL); | |
5176 signal(SIGTERM, SIG_DFL); | |
5177 signal(SIGABRT, SIG_DFL); | |
5178 | |
5179 return x; | |
5180 } | |
5181 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5182 #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
|
5183 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5184 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
|
5185 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
|
5186 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
|
5187 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
|
5188 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
|
5189 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
|
5190 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5191 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5192 HANDLE h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5193 # ifdef FEAT_MBYTE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5194 WCHAR *wn = NULL; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5195 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
|
5196 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5197 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
|
5198 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
|
5199 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
5200 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
|
5201 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
|
5202 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
|
5203 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
|
5204 } |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5205 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5206 if (wn == NULL) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5207 # 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
|
5208 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
|
5209 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
|
5210 dwFlagsAndAttributes, NULL); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5211 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5212 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5213 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5214 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5215 * 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
|
5216 * 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
|
5217 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
5218 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
|
5219 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
|
5220 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5221 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
|
5222 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
|
5223 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
|
5224 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5225 /* 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
|
5226 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
|
5227 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5228 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5229 if (base) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5230 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5231 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
|
5232 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5233 /* 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
|
5234 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
|
5235 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5236 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5237 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
|
5238 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5239 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
|
5240 *((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
|
5241 p++; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5242 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5243 FreeEnvironmentStrings(base); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5244 *((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
|
5245 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5246 |
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
|
5247 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
|
5248 { |
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 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
|
5250 { |
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
|
5251 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
|
5252 { |
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
|
5253 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
|
5254 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
|
5255 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
|
5256 --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
|
5257 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
|
5258 { |
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 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
|
5260 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
|
5261 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
|
5262 |
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 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
|
5264 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
|
5265 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
|
5266 *((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
|
5267 *((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
|
5268 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
|
5269 *((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
|
5270 *((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
|
5271 } |
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 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
|
5273 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
|
5274 } |
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 |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5278 # if defined(FEAT_CLIENTSERVER) || defined(FEAT_TERMINAL) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5279 { |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5280 # ifdef FEAT_CLIENTSERVER |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5281 char_u *servername = get_vim_var_str(VV_SEND_SERVER); |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5282 size_t servername_len = STRLEN(servername); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5283 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5284 # ifdef FEAT_TERMINAL |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5285 char_u *version = get_vim_var_str(VV_VERSION); |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5286 size_t version_len = STRLEN(version); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5287 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5288 // size of "VIM_SERVERNAME=" and value, |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5289 // plus "VIM_TERMINAL=" and value, |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5290 // plus two terminating NULs |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5291 size_t n = 0 |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5292 # ifdef FEAT_CLIENTSERVER |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5293 + 15 + servername_len |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5294 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5295 # ifdef FEAT_TERMINAL |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5296 + 13 + version_len + 2 |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5297 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5298 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5299 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5300 if (ga_grow(gap, (int)n) == OK) |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5301 { |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5302 # ifdef FEAT_CLIENTSERVER |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5303 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
|
5304 *((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
|
5305 (WCHAR)"VIM_SERVERNAME="[n]; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5306 for (n = 0; n < servername_len; n++) |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5307 *((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
|
5308 (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
|
5309 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5310 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5311 # ifdef FEAT_TERMINAL |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5312 if (is_terminal) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5313 { |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5314 for (n = 0; n < 13; n++) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5315 *((WCHAR*)gap->ga_data + gap->ga_len++) = |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5316 (WCHAR)"VIM_TERMINAL="[n]; |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5317 for (n = 0; n < version_len; n++) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5318 *((WCHAR*)gap->ga_data + gap->ga_len++) = |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5319 (WCHAR)version[n]; |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5320 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5321 } |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5322 # endif |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5323 } |
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
|
5324 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5325 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5326 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5327 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5328 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5329 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
|
5330 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5331 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5332 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5333 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5334 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5335 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5336 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5337 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5338 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
|
5339 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5340 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5341 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
|
5342 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
|
5343 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
|
5344 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
|
5345 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
|
5346 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
|
5347 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
|
5348 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5349 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
|
5350 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5351 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5352 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5353 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5354 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5355 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5356 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5357 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
|
5358 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
|
5359 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5360 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5361 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5362 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5363 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5364 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5365 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5366 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5367 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
|
5368 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
|
5369 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5370 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5371 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5372 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5373 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5374 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5375 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5376 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5377 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5378 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5379 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5380 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5381 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5382 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
|
5383 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5384 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
|
5385 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5386 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5387 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
|
5388 { |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5389 EMSG2(_(e_notopen), fname); |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5390 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5391 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5392 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5393 else if (!use_null_for_in && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5394 (!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
|
5395 || !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
|
5396 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5397 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5398 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5399 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5400 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
|
5401 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5402 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
|
5403 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5404 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5405 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
|
5406 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5407 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5408 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5409 } |
8471
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 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5412 (!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
|
5413 || !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
|
5414 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5415 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5416 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5417 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5418 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
|
5419 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5420 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
|
5421 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5422 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5423 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
|
5424 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5425 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5426 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5427 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5428 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5429 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
|
5430 (!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
|
5431 || !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
|
5432 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5433 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5434 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5435 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5436 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5437 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
|
5438 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5439 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
|
5440 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5441 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5442 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5443 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5444 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5445 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5446 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5447 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5448 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5449 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5450 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5451 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5452 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5453 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
|
5454 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5455 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5456 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
|
5457 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5458 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
|
5459 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5460 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
|
5461 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5462 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5463 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5464 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5465 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5466 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5467 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5468 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
|
5469 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5470 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5471 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5472 /* 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
|
5473 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5474 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5475 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5476 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5477 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5478 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5479 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5480 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5481 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5482 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5483 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5484 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5485 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
|
5486 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5487 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5488 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5489 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5490 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5491 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5492 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
|
5493 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5494 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
|
5495 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5496 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
|
5497 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5498 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5499 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5500 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5501 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5502 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5503 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5504 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5505 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5506 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5507 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5508 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5509 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
|
5510 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5511 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5512 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5513 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5514 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5515 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5516 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5517 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5518 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
|
5519 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5520 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5521 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5522 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
|
5523 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5524 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
|
5525 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5526 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5527 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5528 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5529 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5530 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5531 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5532 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5533 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
|
5534 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5535 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5536 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5537 job_T *job = job_list; |
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 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5540 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5541 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5542 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5543 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5544 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
|
5545 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5546 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5547 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5548 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5549 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
|
5550 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5551 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5552 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5553 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5554 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5555 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5556 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5557 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
|
5558 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5559 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
|
5560 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5561 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
|
5562 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5563 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5564 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5565 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5566 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5567 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5568 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5569 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5570 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5571 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5572 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5573 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5574 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5575 if (pid != 0) |
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 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5578 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5579 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5580 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5581 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5582 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5583 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5584 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5585 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5586 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5587 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5588 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5589 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5590 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5591 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5592 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5593 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5594 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5595 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5596 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5597 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5598 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5599 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5600 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5601 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5602 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5603 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5604 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5605 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5606 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5607 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5608 * 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
|
5609 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5610 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5611 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
|
5612 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5613 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5614 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5615 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
|
5616 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5617 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5618 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5619 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
|
5620 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
|
5621 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5622 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5623 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
|
5624 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5625 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5626 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
|
5627 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5628 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5629 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5630 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5631 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5632 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5633 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5634 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5635 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5636 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5637 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5638 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5639 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5640 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5641 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5642 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5643 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5644 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5645 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5646 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5647 |
7 | 5648 |
5649 #ifndef FEAT_GUI_W32 | |
5650 | |
5651 /* | |
5652 * Start termcap mode | |
5653 */ | |
5654 static void | |
5655 termcap_mode_start(void) | |
5656 { | |
5657 DWORD cmodein; | |
5658 | |
5659 if (g_fTermcapMode) | |
5660 return; | |
5661 | |
5662 SaveConsoleBuffer(&g_cbNonTermcap); | |
5663 | |
5664 if (g_cbTermcap.IsValid) | |
5665 { | |
5666 /* | |
5667 * We've been in termcap mode before. Restore certain screen | |
5668 * characteristics, including the buffer size and the window | |
5669 * size. Since we will be redrawing the screen, we don't need | |
5670 * to restore the actual contents of the buffer. | |
5671 */ | |
5672 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
|
5673 reset_console_color_rgb(); |
7 | 5674 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5675 Rows = g_cbTermcap.Info.dwSize.Y; | |
5676 Columns = g_cbTermcap.Info.dwSize.X; | |
5677 } | |
5678 else | |
5679 { | |
5680 /* | |
5681 * This is our first time entering termcap mode. Clear the console | |
5682 * screen buffer, and resize the buffer to match the current window | |
5683 * size. We will use this as the size of our editing environment. | |
5684 */ | |
5685 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
|
5686 set_console_color_rgb(); |
7 | 5687 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5688 } | |
5689 | |
5690 #ifdef FEAT_TITLE | |
5691 resettitle(); | |
5692 #endif | |
5693 | |
5694 GetConsoleMode(g_hConIn, &cmodein); | |
5695 #ifdef FEAT_MOUSE | |
5696 if (g_fMouseActive) | |
5697 cmodein |= ENABLE_MOUSE_INPUT; | |
5698 else | |
5699 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5700 #endif | |
5701 cmodein |= ENABLE_WINDOW_INPUT; | |
5702 SetConsoleMode(g_hConIn, cmodein); | |
5703 | |
5704 redraw_later_clear(); | |
5705 g_fTermcapMode = TRUE; | |
5706 } | |
5707 | |
5708 | |
5709 /* | |
5710 * End termcap mode | |
5711 */ | |
5712 static void | |
5713 termcap_mode_end(void) | |
5714 { | |
5715 DWORD cmodein; | |
5716 ConsoleBuffer *cb; | |
5717 COORD coord; | |
5718 DWORD dwDummy; | |
5719 | |
5720 if (!g_fTermcapMode) | |
5721 return; | |
5722 | |
5723 SaveConsoleBuffer(&g_cbTermcap); | |
5724 | |
5725 GetConsoleMode(g_hConIn, &cmodein); | |
5726 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5727 SetConsoleMode(g_hConIn, cmodein); | |
5728 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5729 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5730 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5731 #else |
7 | 5732 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5733 #endif |
7 | 5734 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
|
5735 reset_console_color_rgb(); |
7 | 5736 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5737 | |
5738 if (p_rs || exiting) | |
5739 { | |
5740 /* | |
5741 * Clear anything that happens to be on the current line. | |
5742 */ | |
5743 coord.X = 0; | |
5744 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5745 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5746 cb->Info.dwSize.X, coord, &dwDummy); | |
5747 /* | |
5748 * The following is just for aesthetics. If we are exiting without | |
5749 * restoring the screen, then we want to have a prompt string | |
5750 * appear at the bottom line. However, the command interpreter | |
5751 * seems to always advance the cursor one line before displaying | |
5752 * the prompt string, which causes the screen to scroll. To | |
5753 * counter this, move the cursor up one line before exiting. | |
5754 */ | |
5755 if (exiting && !p_rs) | |
5756 coord.Y--; | |
5757 /* | |
5758 * Position the cursor at the leftmost column of the desired row. | |
5759 */ | |
5760 SetConsoleCursorPosition(g_hConOut, coord); | |
5761 } | |
5762 | |
5763 g_fTermcapMode = FALSE; | |
5764 } | |
5765 #endif /* FEAT_GUI_W32 */ | |
5766 | |
5767 | |
5768 #ifdef FEAT_GUI_W32 | |
5769 void | |
5770 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
|
5771 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
|
5772 int len UNUSED) |
7 | 5773 { |
5774 /* never used */ | |
5775 } | |
5776 | |
5777 #else | |
5778 | |
5779 /* | |
5780 * clear `n' chars, starting from `coord' | |
5781 */ | |
5782 static void | |
5783 clear_chars( | |
5784 COORD coord, | |
5785 DWORD n) | |
5786 { | |
5787 DWORD dwDummy; | |
5788 | |
5789 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
|
5790 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5791 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
|
5792 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
|
5793 else |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5794 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5795 set_console_color_rgb(); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5796 gotoxy(coord.X + 1, coord.Y + 1); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5797 vtp_printf("\033[%dX", n); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5798 } |
7 | 5799 } |
5800 | |
5801 | |
5802 /* | |
5803 * Clear the screen | |
5804 */ | |
5805 static void | |
5806 clear_screen(void) | |
5807 { | |
5808 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
|
5809 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5810 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
|
5811 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
|
5812 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5813 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5814 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
|
5815 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
|
5816 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
|
5817 } |
7 | 5818 } |
5819 | |
5820 | |
5821 /* | |
5822 * Clear to end of display | |
5823 */ | |
5824 static void | |
5825 clear_to_end_of_display(void) | |
5826 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5827 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
|
5828 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5829 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
|
5830 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5831 * 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
|
5832 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5833 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5834 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
|
5835 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
|
5836 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
|
5837 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5838 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
|
5839 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
|
5840 } |
7 | 5841 } |
5842 | |
5843 | |
5844 /* | |
5845 * Clear to end of line | |
5846 */ | |
5847 static void | |
5848 clear_to_end_of_line(void) | |
5849 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5850 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
|
5851 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5852 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
|
5853 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
|
5854 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5855 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5856 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
|
5857 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
|
5858 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
|
5859 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5860 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
|
5861 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
|
5862 } |
7 | 5863 } |
5864 | |
5865 | |
5866 /* | |
5867 * Scroll the scroll region up by `cLines' lines | |
5868 */ | |
5869 static void | |
26 | 5870 scroll(unsigned cLines) |
7 | 5871 { |
5872 COORD oldcoord = g_coord; | |
5873 | |
5874 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5875 delete_lines(cLines); | |
5876 | |
5877 g_coord = oldcoord; | |
5878 } | |
5879 | |
5880 | |
5881 /* | |
5882 * Set the scroll region | |
5883 */ | |
5884 static void | |
5885 set_scroll_region( | |
5886 unsigned left, | |
5887 unsigned top, | |
5888 unsigned right, | |
5889 unsigned bottom) | |
5890 { | |
5891 if (left >= right | |
5892 || top >= bottom | |
5893 || right > (unsigned) Columns - 1 | |
5894 || bottom > (unsigned) Rows - 1) | |
5895 return; | |
5896 | |
5897 g_srScrollRegion.Left = left; | |
5898 g_srScrollRegion.Top = top; | |
5899 g_srScrollRegion.Right = right; | |
5900 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
|
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 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
|
5903 vtp_printf("\033[%d;%dr", top + 1, bottom + 1); |
7 | 5904 } |
5905 | |
5906 | |
5907 /* | |
5908 * Insert `cLines' lines at the current cursor position | |
5909 */ | |
5910 static void | |
26 | 5911 insert_lines(unsigned cLines) |
7 | 5912 { |
5913 SMALL_RECT source; | |
5914 COORD dest; | |
5915 CHAR_INFO fill; | |
5916 | |
5917 dest.X = 0; | |
5918 dest.Y = g_coord.Y + cLines; | |
5919 | |
5920 source.Left = 0; | |
5921 source.Top = g_coord.Y; | |
5922 source.Right = g_srScrollRegion.Right; | |
5923 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5924 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5925 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
|
5926 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5927 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
|
5928 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
|
5929 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5930 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
|
5931 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5932 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5933 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5934 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
|
5935 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5936 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
|
5937 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
|
5938 } |
7 | 5939 |
5940 /* Here we have to deal with a win32 console flake: If the scroll | |
5941 * region looks like abc and we scroll c to a and fill with d we get | |
5942 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5943 * vim expects cdd consistently... So we have to deal with that | |
5944 * here... (this also occurs scrolling the same way in the other | |
5945 * direction). */ | |
5946 | |
5947 if (source.Bottom < dest.Y) | |
5948 { | |
5949 COORD coord; | |
5950 | |
5951 coord.X = 0; | |
5952 coord.Y = source.Bottom; | |
5953 clear_chars(coord, Columns * (dest.Y - source.Bottom)); | |
5954 } | |
5955 } | |
5956 | |
5957 | |
5958 /* | |
5959 * Delete `cLines' lines at the current cursor position | |
5960 */ | |
5961 static void | |
26 | 5962 delete_lines(unsigned cLines) |
7 | 5963 { |
5964 SMALL_RECT source; | |
5965 COORD dest; | |
5966 CHAR_INFO fill; | |
5967 int nb; | |
5968 | |
5969 dest.X = 0; | |
5970 dest.Y = g_coord.Y; | |
5971 | |
5972 source.Left = 0; | |
5973 source.Top = g_coord.Y + cLines; | |
5974 source.Right = g_srScrollRegion.Right; | |
5975 source.Bottom = g_srScrollRegion.Bottom; | |
5976 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5977 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
|
5978 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5979 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
|
5980 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
|
5981 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5982 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
|
5983 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5984 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5985 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5986 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
|
5987 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5988 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
|
5989 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
|
5990 } |
7 | 5991 |
5992 /* Here we have to deal with a win32 console flake: If the scroll | |
5993 * region looks like abc and we scroll c to a and fill with d we get | |
5994 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5995 * vim expects cdd consistently... So we have to deal with that | |
5996 * here... (this also occurs scrolling the same way in the other | |
5997 * direction). */ | |
5998 | |
5999 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
6000 | |
6001 if (nb < source.Top) | |
6002 { | |
6003 COORD coord; | |
6004 | |
6005 coord.X = 0; | |
6006 coord.Y = nb; | |
6007 clear_chars(coord, Columns * (source.Top - nb)); | |
6008 } | |
6009 } | |
6010 | |
6011 | |
6012 /* | |
6013 * Set the cursor position | |
6014 */ | |
6015 static void | |
6016 gotoxy( | |
6017 unsigned x, | |
6018 unsigned y) | |
6019 { | |
6020 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
6021 return; | |
6022 | |
6023 /* external cursor coords are 1-based; internal are 0-based */ | |
6024 g_coord.X = x - 1; | |
6025 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
|
6026 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6027 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
|
6028 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
|
6029 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6030 vtp_printf("\033[%d;%dH", y, x); |
7 | 6031 } |
6032 | |
6033 | |
6034 /* | |
6035 * Set the current text attribute = (foreground | background) | |
6036 * See ../doc/os_win32.txt for the numbers. | |
6037 */ | |
6038 static void | |
26 | 6039 textattr(WORD wAttr) |
7 | 6040 { |
6710 | 6041 g_attrCurrent = wAttr & 0xff; |
7 | 6042 |
6043 SetConsoleTextAttribute(g_hConOut, wAttr); | |
6044 } | |
6045 | |
6046 | |
6047 static void | |
26 | 6048 textcolor(WORD wAttr) |
7 | 6049 { |
6710 | 6050 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 6051 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6052 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
|
6053 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
|
6054 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6055 vtp_sgr_bulk(wAttr); |
7 | 6056 } |
6057 | |
6058 | |
6059 static void | |
26 | 6060 textbackground(WORD wAttr) |
7 | 6061 { |
6710 | 6062 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 6063 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6064 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
|
6065 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
|
6066 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6067 vtp_sgr_bulk(wAttr); |
7 | 6068 } |
6069 | |
6070 | |
6071 /* | |
6072 * restore the default text attribute (whatever we started with) | |
6073 */ | |
6074 static void | |
26 | 6075 normvideo(void) |
7 | 6076 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6077 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
|
6078 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
|
6079 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6080 vtp_sgr_bulk(0); |
7 | 6081 } |
6082 | |
6083 | |
6084 static WORD g_attrPreStandout = 0; | |
6085 | |
6086 /* | |
6087 * Make the text standout, by brightening it | |
6088 */ | |
6089 static void | |
6090 standout(void) | |
6091 { | |
6092 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
|
6093 |
7 | 6094 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
6095 } | |
6096 | |
6097 | |
6098 /* | |
6099 * Turn off standout mode | |
6100 */ | |
6101 static void | |
26 | 6102 standend(void) |
7 | 6103 { |
6104 if (g_attrPreStandout) | |
6105 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
|
6106 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6107 g_attrPreStandout = 0; |
7 | 6108 } |
6109 | |
6110 | |
6111 /* | |
1199 | 6112 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 6113 */ |
6114 void | |
26 | 6115 mch_set_normal_colors(void) |
7 | 6116 { |
6117 char_u *p; | |
6118 int n; | |
6119 | |
6120 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
6121 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
|
6122 if ( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6123 #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
|
6124 !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
|
6125 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6126 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 6127 { |
6128 p = T_ME + 2; | |
6129 n = getdigits(&p); | |
6130 if (*p == 'm' && n > 0) | |
6131 { | |
6132 cterm_normal_fg_color = (n & 0xf) + 1; | |
6133 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
6134 } | |
6135 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6136 #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
|
6137 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
|
6138 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
|
6139 #endif |
7 | 6140 } |
6141 | |
6142 | |
6143 /* | |
6144 * visual bell: flash the screen | |
6145 */ | |
6146 static void | |
26 | 6147 visual_bell(void) |
7 | 6148 { |
6149 COORD coordOrigin = {0, 0}; | |
6150 WORD attrFlash = ~g_attrCurrent & 0xff; | |
6151 | |
6152 DWORD dwDummy; | |
6153 LPWORD oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD)); | |
6154 | |
6155 if (oldattrs == NULL) | |
6156 return; | |
6157 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
6158 coordOrigin, &dwDummy); | |
6159 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
6160 coordOrigin, &dwDummy); | |
6161 | |
6162 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
|
6163 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
|
6164 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 6165 coordOrigin, &dwDummy); |
6166 vim_free(oldattrs); | |
6167 } | |
6168 | |
6169 | |
6170 /* | |
6171 * Make the cursor visible or invisible | |
6172 */ | |
6173 static void | |
26 | 6174 cursor_visible(BOOL fVisible) |
7 | 6175 { |
6176 s_cursor_visible = fVisible; | |
6177 #ifdef MCH_CURSOR_SHAPE | |
6178 mch_update_cursor(); | |
6179 #endif | |
6180 } | |
6181 | |
6182 | |
6183 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6184 * 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
|
6185 * Returns the number of bytes actually written (at least one). |
7 | 6186 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6187 static DWORD |
7 | 6188 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6189 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6190 DWORD cbToWrite) |
7 | 6191 { |
6192 COORD coord = g_coord; | |
6193 DWORD written; | |
6194 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6195 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6196 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
|
6197 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6198 static WCHAR *unicodebuf = NULL; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6199 static int unibuflen = 0; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6200 int length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6201 DWORD n, cchwritten, cells; |
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 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
|
6204 if (unicodebuf == NULL || length > unibuflen) |
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 vim_free(unicodebuf); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6207 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
|
6208 unibuflen = length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6209 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6210 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
|
6211 unicodebuf, unibuflen); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6212 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6213 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
|
6214 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6215 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
|
6216 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6217 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
|
6218 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
|
6219 /* 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
|
6220 * 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
|
6221 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
|
6222 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
|
6223 || 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
|
6224 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
|
6225 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6226 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6227 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6228 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
|
6229 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
|
6230 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
|
6231 } |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6232 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6233 if (cchwritten == length) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6234 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6235 written = cbToWrite; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6236 g_coord.X += (SHORT)cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6237 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6238 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6239 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6240 char_u *p = pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6241 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
|
6242 MB_CPTR_ADV(p); |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6243 written = p - pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6244 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
|
6245 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6246 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6247 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6248 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6249 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6250 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
|
6251 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6252 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
|
6253 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
|
6254 /* 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
|
6255 * 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
|
6256 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
|
6257 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
|
6258 || 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
|
6259 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
|
6260 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6261 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6262 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6263 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
|
6264 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
|
6265 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
|
6266 } |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6267 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6268 g_coord.X += (SHORT) written; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6269 } |
7 | 6270 |
6271 while (g_coord.X > g_srScrollRegion.Right) | |
6272 { | |
6273 g_coord.X -= (SHORT) Columns; | |
6274 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6275 g_coord.Y++; | |
6276 } | |
6277 | |
6278 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6279 | |
6280 return written; | |
6281 } | |
6282 | |
6283 | |
6284 /* | |
6285 * mch_write(): write the output buffer to the screen, translating ESC | |
6286 * sequences into calls to console output routines. | |
6287 */ | |
6288 void | |
6289 mch_write( | |
6290 char_u *s, | |
6291 int len) | |
6292 { | |
6293 s[len] = NUL; | |
6294 | |
6295 if (!term_console) | |
6296 { | |
6297 write(1, s, (unsigned)len); | |
6298 return; | |
6299 } | |
6300 | |
6301 /* translate ESC | sequences into faked bios calls */ | |
6302 while (len--) | |
6303 { | |
6304 /* optimization: use one single write_chars for runs of text, | |
6305 * 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
|
6306 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 6307 |
6308 if (p_wd) | |
6309 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6310 WaitForChar(p_wd, FALSE); |
7 | 6311 if (prefix != 0) |
6312 prefix = 1; | |
6313 } | |
6314 | |
6315 if (prefix != 0) | |
6316 { | |
6317 DWORD nWritten; | |
6318 | |
6319 nWritten = write_chars(s, prefix); | |
6320 #ifdef MCH_WRITE_DUMP | |
6321 if (fdDump) | |
6322 { | |
6323 fputc('>', fdDump); | |
6324 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6325 fputs("<\n", fdDump); | |
6326 } | |
6327 #endif | |
6328 len -= (nWritten - 1); | |
6329 s += nWritten; | |
6330 } | |
6331 else if (s[0] == '\n') | |
6332 { | |
6333 /* \n, newline: go to the beginning of the next line or scroll */ | |
6334 if (g_coord.Y == g_srScrollRegion.Bottom) | |
6335 { | |
6336 scroll(1); | |
6337 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6338 } | |
6339 else | |
6340 { | |
6341 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6342 } | |
6343 #ifdef MCH_WRITE_DUMP | |
6344 if (fdDump) | |
6345 fputs("\\n\n", fdDump); | |
6346 #endif | |
6347 s++; | |
6348 } | |
6349 else if (s[0] == '\r') | |
6350 { | |
6351 /* \r, carriage return: go to beginning of line */ | |
6352 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
6353 #ifdef MCH_WRITE_DUMP | |
6354 if (fdDump) | |
6355 fputs("\\r\n", fdDump); | |
6356 #endif | |
6357 s++; | |
6358 } | |
6359 else if (s[0] == '\b') | |
6360 { | |
6361 /* \b, backspace: move cursor one position left */ | |
6362 if (g_coord.X > g_srScrollRegion.Left) | |
6363 g_coord.X--; | |
6364 else if (g_coord.Y > g_srScrollRegion.Top) | |
6365 { | |
6366 g_coord.X = g_srScrollRegion.Right; | |
6367 g_coord.Y--; | |
6368 } | |
6369 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6370 #ifdef MCH_WRITE_DUMP | |
6371 if (fdDump) | |
6372 fputs("\\b\n", fdDump); | |
6373 #endif | |
6374 s++; | |
6375 } | |
6376 else if (s[0] == '\a') | |
6377 { | |
6378 /* \a, bell */ | |
6379 MessageBeep(0xFFFFFFFF); | |
6380 #ifdef MCH_WRITE_DUMP | |
6381 if (fdDump) | |
6382 fputs("\\a\n", fdDump); | |
6383 #endif | |
6384 s++; | |
6385 } | |
6386 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6387 { | |
6388 #ifdef MCH_WRITE_DUMP | |
24 | 6389 char_u *old_s = s; |
7 | 6390 #endif |
24 | 6391 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
|
6392 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
7 | 6393 |
6394 switch (s[2]) | |
6395 { | |
6396 case '0': case '1': case '2': case '3': case '4': | |
6397 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
|
6398 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
|
6399 do |
7 | 6400 { |
6401 ++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
|
6402 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
|
6403 argc += (argc < 15) ? 1 : 0; |
7 | 6404 if (p > s + len) |
6405 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
|
6406 } 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
|
6407 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6408 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
|
6409 break; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6410 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6411 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
|
6412 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
|
6413 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
|
6414 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6415 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
|
6416 normvideo(); |
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) |
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 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
|
6420 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
|
6421 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6422 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
|
6423 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6424 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
|
6425 vtp_sgr_bulks(argc, args); |
7 | 6426 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6427 else if (argc == 2 && *p == 'H') |
7 | 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 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
|
6430 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6431 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
|
6432 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6433 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
|
6434 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6435 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
|
6436 { |
7 | 6437 gotoxy(g_coord.X + 1, |
6438 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6439 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6440 else if (argc == 1 && *p == 'b') |
7 | 6441 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6442 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
|
6443 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6444 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
|
6445 { |
7 | 6446 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6447 g_coord.Y + 1); | |
6448 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6449 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
|
6450 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6451 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
|
6452 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6453 else if (argc == 1 && *p == 'H') |
7 | 6454 { |
6455 gotoxy(1, arg1); | |
6456 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6457 else if (argc == 1 && *p == 'L') |
7 | 6458 { |
6459 insert_lines(arg1); | |
6460 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6461 else if (argc == 1 && *p == 'M') |
7 | 6462 { |
6463 delete_lines(arg1); | |
6464 } | |
6465 | |
835 | 6466 len -= (int)(p - s); |
7 | 6467 s = p + 1; |
6468 break; | |
6469 | |
6470 case 'A': | |
6471 gotoxy(g_coord.X + 1, | |
6472 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6473 goto got3; | |
6474 | |
6475 case 'B': | |
6476 visual_bell(); | |
6477 goto got3; | |
6478 | |
6479 case 'C': | |
6480 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6481 g_coord.Y + 1); | |
6482 goto got3; | |
6483 | |
6484 case 'E': | |
6485 termcap_mode_end(); | |
6486 goto got3; | |
6487 | |
6488 case 'F': | |
6489 standout(); | |
6490 goto got3; | |
6491 | |
6492 case 'f': | |
6493 standend(); | |
6494 goto got3; | |
6495 | |
6496 case 'H': | |
6497 gotoxy(1, 1); | |
6498 goto got3; | |
6499 | |
6500 case 'j': | |
6501 clear_to_end_of_display(); | |
6502 goto got3; | |
6503 | |
6504 case 'J': | |
6505 clear_screen(); | |
6506 goto got3; | |
6507 | |
6508 case 'K': | |
6509 clear_to_end_of_line(); | |
6510 goto got3; | |
6511 | |
6512 case 'L': | |
6513 insert_lines(1); | |
6514 goto got3; | |
6515 | |
6516 case 'M': | |
6517 delete_lines(1); | |
6518 goto got3; | |
6519 | |
6520 case 'S': | |
6521 termcap_mode_start(); | |
6522 goto got3; | |
6523 | |
6524 case 'V': | |
6525 cursor_visible(TRUE); | |
6526 goto got3; | |
6527 | |
6528 case 'v': | |
6529 cursor_visible(FALSE); | |
6530 goto got3; | |
6531 | |
6532 got3: | |
6533 s += 3; | |
6534 len -= 2; | |
6535 } | |
6536 | |
6537 #ifdef MCH_WRITE_DUMP | |
6538 if (fdDump) | |
6539 { | |
6540 fputs("ESC | ", fdDump); | |
6541 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6542 fputc('\n', fdDump); | |
6543 } | |
6544 #endif | |
6545 } | |
6546 else | |
6547 { | |
6548 /* Write a single character */ | |
6549 DWORD nWritten; | |
6550 | |
6551 nWritten = write_chars(s, 1); | |
6552 #ifdef MCH_WRITE_DUMP | |
6553 if (fdDump) | |
6554 { | |
6555 fputc('>', fdDump); | |
6556 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6557 fputs("<\n", fdDump); | |
6558 } | |
6559 #endif | |
6560 | |
6561 len -= (nWritten - 1); | |
6562 s += nWritten; | |
6563 } | |
6564 } | |
6565 | |
6566 #ifdef MCH_WRITE_DUMP | |
6567 if (fdDump) | |
6568 fflush(fdDump); | |
6569 #endif | |
6570 } | |
6571 | |
6572 #endif /* FEAT_GUI_W32 */ | |
6573 | |
6574 | |
6575 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6576 * Delay for "msec" milliseconds. |
7 | 6577 */ |
6578 void | |
6579 mch_delay( | |
6580 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
|
6581 int ignoreinput UNUSED) |
7 | 6582 { |
6583 #ifdef FEAT_GUI_W32 | |
6584 Sleep((int)msec); /* never wait for input */ | |
14 | 6585 #else /* Console */ |
7 | 6586 if (ignoreinput) |
14 | 6587 # ifdef FEAT_MZSCHEME |
6588 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6589 { | |
6590 int towait = p_mzq; | |
6591 | |
6592 /* if msec is large enough, wait by portions in p_mzq */ | |
6593 while (msec > 0) | |
6594 { | |
6595 mzvim_check_threads(); | |
6596 if (msec < towait) | |
6597 towait = msec; | |
6598 Sleep(towait); | |
6599 msec -= towait; | |
6600 } | |
6601 } | |
6602 else | |
6603 # endif | |
6604 Sleep((int)msec); | |
7 | 6605 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6606 WaitForChar(msec, FALSE); |
7 | 6607 #endif |
6608 } | |
6609 | |
6610 | |
6611 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6612 * 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
|
6613 * This can also remove a symbolic link like Unix. |
7 | 6614 * Return 0 for success, -1 for failure. |
6615 */ | |
6616 int | |
6617 mch_remove(char_u *name) | |
6618 { | |
6619 #ifdef FEAT_MBYTE | |
6620 WCHAR *wn = NULL; | |
6621 int n; | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6622 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6623 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6624 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6625 * 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
|
6626 * 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
|
6627 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6628 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
|
6629 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6630 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6631 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6632 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6633 #ifdef FEAT_MBYTE |
7 | 6634 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6635 { | |
1752 | 6636 wn = enc_to_utf16(name, NULL); |
7 | 6637 if (wn != NULL) |
6638 { | |
6639 n = DeleteFileW(wn) ? 0 : -1; | |
6640 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6641 return n; |
7 | 6642 } |
6643 } | |
6644 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6645 return DeleteFile((LPCSTR)name) ? 0 : -1; |
7 | 6646 } |
6647 | |
6648 | |
6649 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6650 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6651 */ |
6652 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6653 mch_breakcheck(int force) |
7 | 6654 { |
6655 #ifndef FEAT_GUI_W32 /* never used */ | |
6656 if (g_fCtrlCPressed || g_fCBrkPressed) | |
6657 { | |
12066
8ad282dee649
patch 8.0.0913: MS-Windows: CTRL-C kills shell in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12050
diff
changeset
|
6658 ctrl_break_was_pressed = g_fCBrkPressed; |
7 | 6659 g_fCtrlCPressed = g_fCBrkPressed = FALSE; |
6660 got_int = TRUE; | |
6661 } | |
6662 #endif | |
6663 } | |
6664 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6665 /* 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
|
6666 #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
|
6667 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6668 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6669 * 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
|
6670 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6671 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
|
6672 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
|
6673 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6674 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6675 |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6676 PlatformId(); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6677 /* 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
|
6678 * 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
|
6679 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6680 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6681 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6682 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6683 /* 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
|
6684 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
|
6685 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6686 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
|
6687 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6688 /* 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
|
6689 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
|
6690 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6691 /* 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
|
6692 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
|
6693 } |
7 | 6694 |
6695 #ifdef FEAT_MBYTE | |
6696 /* | |
6697 * Same code as below, but with wide functions and no comments. | |
6698 * Return 0 for success, non-zero for failure. | |
6699 */ | |
6700 int | |
6701 mch_wrename(WCHAR *wold, WCHAR *wnew) | |
6702 { | |
6703 WCHAR *p; | |
6704 int i; | |
6705 WCHAR szTempFile[_MAX_PATH + 1]; | |
6706 WCHAR szNewPath[_MAX_PATH + 1]; | |
6707 HANDLE hf; | |
6708 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6709 p = wold; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6710 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
|
6711 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
|
6712 && wold[i + 1] != 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6713 p = wold + i + 1; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6714 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
|
6715 return (MoveFileW(wold, wnew) == 0); |
7 | 6716 |
6717 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) | |
6718 return -1; | |
6719 *p = NUL; | |
6720 | |
6721 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) | |
6722 return -2; | |
6723 | |
6724 if (!DeleteFileW(szTempFile)) | |
6725 return -3; | |
6726 | |
6727 if (!MoveFileW(wold, szTempFile)) | |
6728 return -4; | |
6729 | |
6730 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6731 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6732 return -5; | |
6733 if (!CloseHandle(hf)) | |
6734 return -6; | |
6735 | |
6736 if (!MoveFileW(szTempFile, wnew)) | |
6737 { | |
6738 (void)MoveFileW(szTempFile, wold); | |
6739 return -7; | |
6740 } | |
6741 | |
6742 DeleteFileW(szTempFile); | |
6743 | |
6744 if (!DeleteFileW(wold)) | |
6745 return -8; | |
6746 | |
6747 return 0; | |
6748 } | |
6749 #endif | |
6750 | |
6751 | |
6752 /* | |
6753 * mch_rename() works around a bug in rename (aka MoveFile) in | |
6754 * Windows 95: rename("foo.bar", "foo.bar~") will generate a | |
6755 * file whose short file name is "FOO.BAR" (its long file name will | |
6756 * be correct: "foo.bar~"). Because a file can be accessed by | |
6757 * either its SFN or its LFN, "foo.bar" has effectively been | |
6758 * renamed to "foo.bar", which is not at all what was wanted. This | |
6759 * seems to happen only when renaming files with three-character | |
6760 * extensions by appending a suffix that does not include ".". | |
6761 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6762 * | |
6763 * There is another problem, which isn't really a bug but isn't right either: | |
6764 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6765 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6766 * service pack 6. Doesn't seem to happen on Windows 98. | |
6767 * | |
6768 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6769 * Should probably set errno appropriately when errors occur. | |
6770 */ | |
6771 int | |
6772 mch_rename( | |
6773 const char *pszOldFile, | |
6774 const char *pszNewFile) | |
6775 { | |
6776 char szTempFile[_MAX_PATH+1]; | |
6777 char szNewPath[_MAX_PATH+1]; | |
6778 char *pszFilePart; | |
6779 HANDLE hf; | |
6780 #ifdef FEAT_MBYTE | |
6781 WCHAR *wold = NULL; | |
6782 WCHAR *wnew = NULL; | |
6783 int retval = -1; | |
6784 | |
6785 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
6786 { | |
1752 | 6787 wold = enc_to_utf16((char_u *)pszOldFile, NULL); |
6788 wnew = enc_to_utf16((char_u *)pszNewFile, NULL); | |
7 | 6789 if (wold != NULL && wnew != NULL) |
6790 retval = mch_wrename(wold, wnew); | |
6791 vim_free(wold); | |
6792 vim_free(wnew); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6793 return retval; |
7 | 6794 } |
6795 #endif | |
6796 | |
6797 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6798 * 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
|
6799 * seventh character. |
7 | 6800 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6801 pszFilePart = (char *)gettail((char_u *)pszOldFile); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6802 if (STRLEN(pszFilePart) < 8 || pszFilePart[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6803 return rename(pszOldFile, pszNewFile); |
7 | 6804 |
6805 /* Get base path of new file name. Undocumented feature: If pszNewFile is | |
6806 * a directory, no error is returned and pszFilePart will be NULL. */ | |
6807 if (GetFullPathName(pszNewFile, _MAX_PATH, szNewPath, &pszFilePart) == 0 | |
6808 || pszFilePart == NULL) | |
6809 return -1; | |
6810 *pszFilePart = NUL; | |
6811 | |
6812 /* Get (and create) a unique temporary file name in directory of new file */ | |
6813 if (GetTempFileName(szNewPath, "VIM", 0, szTempFile) == 0) | |
6814 return -2; | |
6815 | |
6816 /* blow the temp file away */ | |
6817 if (!DeleteFile(szTempFile)) | |
6818 return -3; | |
6819 | |
6820 /* rename old file to the temp file */ | |
6821 if (!MoveFile(pszOldFile, szTempFile)) | |
6822 return -4; | |
6823 | |
6824 /* now create an empty file called pszOldFile; this prevents the operating | |
6825 * system using pszOldFile as an alias (SFN) if we're renaming within the | |
6826 * same directory. For example, we're editing a file called | |
6827 * filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt | |
6828 * to filena~1.txt~ (i.e., we're making a backup while writing it), the | |
6829 * SFN for filena~1.txt~ will be filena~1.txt, by default, which will | |
39 | 6830 * cause all sorts of problems later in buf_write(). So, we create an |
6831 * empty file called filena~1.txt and the system will have to find some | |
6832 * other SFN for filena~1.txt~, such as filena~2.txt | |
7 | 6833 */ |
6834 if ((hf = CreateFile(pszOldFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6835 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6836 return -5; | |
6837 if (!CloseHandle(hf)) | |
6838 return -6; | |
6839 | |
6840 /* rename the temp file to the new file */ | |
6841 if (!MoveFile(szTempFile, pszNewFile)) | |
6842 { | |
6843 /* Renaming failed. Rename the file back to its old name, so that it | |
6844 * looks like nothing happened. */ | |
6845 (void)MoveFile(szTempFile, pszOldFile); | |
6846 | |
6847 return -7; | |
6848 } | |
6849 | |
6850 /* Seems to be left around on Novell filesystems */ | |
6851 DeleteFile(szTempFile); | |
6852 | |
6853 /* finally, remove the empty old file */ | |
6854 if (!DeleteFile(pszOldFile)) | |
6855 return -8; | |
6856 | |
6857 return 0; /* success */ | |
6858 } | |
6859 | |
6860 /* | |
6861 * Get the default shell for the current hardware platform | |
6862 */ | |
6863 char * | |
26 | 6864 default_shell(void) |
7 | 6865 { |
6866 PlatformId(); | |
6867 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6868 return "cmd.exe"; |
7 | 6869 } |
6870 | |
6871 /* | |
6872 * mch_access() extends access() to do more detailed check on network drives. | |
6873 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6874 */ | |
6875 int | |
6876 mch_access(char *n, int p) | |
6877 { | |
6878 HANDLE hFile; | |
6879 int retval = -1; /* default: fail */ | |
6880 #ifdef FEAT_MBYTE | |
6881 WCHAR *wn = NULL; | |
6882 | |
6883 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
|
6884 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
|
6885 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6886 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6887 if (mch_isdir((char_u *)n)) |
7 | 6888 { |
6889 char TempName[_MAX_PATH + 16] = ""; | |
6890 #ifdef FEAT_MBYTE | |
6891 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6892 #endif | |
6893 | |
6894 if (p & R_OK) | |
6895 { | |
6896 /* Read check is performed by seeing if we can do a find file on | |
6897 * the directory for any file. */ | |
6898 #ifdef FEAT_MBYTE | |
6899 if (wn != NULL) | |
6900 { | |
6901 int i; | |
6902 WIN32_FIND_DATAW d; | |
6903 | |
6904 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) | |
6905 TempNameW[i] = wn[i]; | |
6906 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/') | |
6907 TempNameW[i++] = '\\'; | |
6908 TempNameW[i++] = '*'; | |
6909 TempNameW[i++] = 0; | |
6910 | |
6911 hFile = FindFirstFileW(TempNameW, &d); | |
6912 if (hFile == INVALID_HANDLE_VALUE) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6913 goto getout; |
7 | 6914 else |
6915 (void)FindClose(hFile); | |
6916 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6917 else |
7 | 6918 #endif |
6919 { | |
6920 char *pch; | |
6921 WIN32_FIND_DATA d; | |
6922 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6923 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH); |
7 | 6924 pch = TempName + STRLEN(TempName) - 1; |
6925 if (*pch != '\\' && *pch != '/') | |
6926 *++pch = '\\'; | |
6927 *++pch = '*'; | |
6928 *++pch = NUL; | |
6929 | |
6930 hFile = FindFirstFile(TempName, &d); | |
6931 if (hFile == INVALID_HANDLE_VALUE) | |
6932 goto getout; | |
6933 (void)FindClose(hFile); | |
6934 } | |
6935 } | |
6936 | |
6937 if (p & W_OK) | |
6938 { | |
6939 /* Trying to create a temporary file in the directory should catch | |
6940 * directories on read-only network shares. However, in | |
6941 * directories whose ACL allows writes but denies deletes will end | |
6942 * up keeping the temporary file :-(. */ | |
6943 #ifdef FEAT_MBYTE | |
6944 if (wn != NULL) | |
6945 { | |
6946 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
|
6947 goto getout; |
7 | 6948 else |
6949 DeleteFileW(TempNameW); | |
6950 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6951 else |
7 | 6952 #endif |
6953 { | |
6954 if (!GetTempFileName(n, "VIM", 0, TempName)) | |
6955 goto getout; | |
6956 mch_remove((char_u *)TempName); | |
6957 } | |
6958 } | |
6959 } | |
6960 else | |
6961 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6962 // Don't consider a file read-only if another process has opened it. |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6963 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6964 |
7 | 6965 /* Trying to open the file for the required access does ACL, read-only |
6966 * network share, and file attribute checks. */ | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6967 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6968 | ((p & R_OK) ? GENERIC_READ : 0); |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6969 |
7 | 6970 #ifdef FEAT_MBYTE |
6971 if (wn != NULL) | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6972 hFile = CreateFileW(wn, access_mode, share_mode, |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6973 NULL, OPEN_EXISTING, 0, NULL); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6974 else |
7 | 6975 #endif |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6976 hFile = CreateFile(n, access_mode, share_mode, |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6977 NULL, OPEN_EXISTING, 0, NULL); |
7 | 6978 if (hFile == INVALID_HANDLE_VALUE) |
6979 goto getout; | |
6980 CloseHandle(hFile); | |
6981 } | |
6982 | |
6983 retval = 0; /* success */ | |
6984 getout: | |
6985 #ifdef FEAT_MBYTE | |
6986 vim_free(wn); | |
6987 #endif | |
6988 return retval; | |
6989 } | |
6990 | |
6991 #if defined(FEAT_MBYTE) || defined(PROTO) | |
6992 /* | |
1752 | 6993 * Version of open() that may use UTF-16 file name. |
7 | 6994 */ |
6995 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6996 mch_open(const char *name, int flags, int mode) |
7 | 6997 { |
39 | 6998 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */ |
6999 # ifndef __BORLANDC__ | |
7 | 7000 WCHAR *wn; |
7001 int f; | |
7002 | |
39 | 7003 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 7004 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7005 wn = enc_to_utf16((char_u *)name, NULL); |
7 | 7006 if (wn != NULL) |
7007 { | |
7008 f = _wopen(wn, flags, mode); | |
7009 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7010 return f; |
7 | 7011 } |
7012 } | |
39 | 7013 # endif |
7 | 7014 |
6345 | 7015 /* open() can open a file which name is longer than _MAX_PATH bytes |
7016 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
7017 * causes unexpected error in another part. We make it an error explicitly | |
7018 * here. */ | |
7019 if (strlen(name) >= _MAX_PATH) | |
7020 return -1; | |
7021 | |
7 | 7022 return open(name, flags, mode); |
7023 } | |
7024 | |
7025 /* | |
1752 | 7026 * Version of fopen() that may use UTF-16 file name. |
7 | 7027 */ |
7028 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7029 mch_fopen(const char *name, const char *mode) |
7 | 7030 { |
7031 WCHAR *wn, *wm; | |
7032 FILE *f = NULL; | |
7033 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7034 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 7035 { |
1686 | 7036 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 7037 /* Work around an annoying assertion in the Microsoft debug CRT |
7038 * when mode's text/binary setting doesn't match _get_fmode(). */ | |
7039 char newMode = mode[strlen(mode) - 1]; | |
7040 int oldMode = 0; | |
7041 | |
7042 _get_fmode(&oldMode); | |
7043 if (newMode == 't') | |
7044 _set_fmode(_O_TEXT); | |
7045 else if (newMode == 'b') | |
7046 _set_fmode(_O_BINARY); | |
7047 # endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7048 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
|
7049 wm = enc_to_utf16((char_u *)mode, NULL); |
7 | 7050 if (wn != NULL && wm != NULL) |
7051 f = _wfopen(wn, wm); | |
7052 vim_free(wn); | |
7053 vim_free(wm); | |
1569 | 7054 |
1686 | 7055 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 7056 _set_fmode(oldMode); |
7057 # endif | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7058 return f; |
7 | 7059 } |
7060 | |
6345 | 7061 /* fopen() can open a file which name is longer than _MAX_PATH bytes |
7062 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
7063 * causes unexpected error in another part. We make it an error explicitly | |
7064 * here. */ | |
7065 if (strlen(name) >= _MAX_PATH) | |
7066 return NULL; | |
7067 | |
7 | 7068 return fopen(name, mode); |
7069 } | |
7070 #endif | |
7071 | |
7072 #ifdef FEAT_MBYTE | |
7073 /* | |
7074 * SUB STREAM (aka info stream) handling: | |
7075 * | |
7076 * NTFS can have sub streams for each file. Normal contents of file is | |
7077 * stored in the main stream, and extra contents (author information and | |
7078 * title and so on) can be stored in sub stream. After Windows 2000, user | |
7079 * can access and store those informations in sub streams via explorer's | |
7080 * property menuitem in right click menu. Those informations in sub streams | |
7081 * were lost when copying only the main stream. So we have to copy sub | |
7082 * streams. | |
7083 * | |
7084 * Incomplete explanation: | |
7085 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
7086 * More useful info and an example: | |
7087 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
7088 */ | |
7089 | |
7090 /* | |
7091 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
7092 * and write to stream "substream" of file "to". | |
7093 * Errors are ignored. | |
7094 */ | |
7095 static void | |
7096 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
7097 { | |
7098 HANDLE hTo; | |
7099 WCHAR *to_name; | |
7100 | |
7101 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
7102 wcscpy(to_name, to); | |
7103 wcscat(to_name, substream); | |
7104 | |
7105 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
7106 FILE_ATTRIBUTE_NORMAL, NULL); | |
7107 if (hTo != INVALID_HANDLE_VALUE) | |
7108 { | |
7109 long done; | |
7110 DWORD todo; | |
7111 DWORD readcnt, written; | |
7112 char buf[4096]; | |
7113 | |
7114 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
7115 for (done = 0; done < len; done += written) | |
7116 { | |
7117 /* (size_t) cast for Borland C 5.5 */ | |
835 | 7118 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
7119 : (size_t)(len - done)); | |
7 | 7120 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
7121 FALSE, FALSE, context) | |
7122 || readcnt != todo | |
7123 || !WriteFile(hTo, buf, todo, &written, NULL) | |
7124 || written != todo) | |
7125 break; | |
7126 } | |
7127 CloseHandle(hTo); | |
7128 } | |
7129 | |
7130 free(to_name); | |
7131 } | |
7132 | |
7133 /* | |
7134 * Copy info streams from file "from" to file "to". | |
7135 */ | |
7136 static void | |
7137 copy_infostreams(char_u *from, char_u *to) | |
7138 { | |
7139 WCHAR *fromw; | |
7140 WCHAR *tow; | |
7141 HANDLE sh; | |
7142 WIN32_STREAM_ID sid; | |
7143 int headersize; | |
7144 WCHAR streamname[_MAX_PATH]; | |
7145 DWORD readcount; | |
7146 void *context = NULL; | |
7147 DWORD lo, hi; | |
7148 int len; | |
7149 | |
7150 /* Convert the file names to wide characters. */ | |
1752 | 7151 fromw = enc_to_utf16(from, NULL); |
7152 tow = enc_to_utf16(to, NULL); | |
7 | 7153 if (fromw != NULL && tow != NULL) |
7154 { | |
7155 /* Open the file for reading. */ | |
7156 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
7157 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
7158 if (sh != INVALID_HANDLE_VALUE) | |
7159 { | |
7160 /* Use BackupRead() to find the info streams. Repeat until we | |
7161 * have done them all.*/ | |
7162 for (;;) | |
7163 { | |
7164 /* Get the header to find the length of the stream name. If | |
7165 * the "readcount" is zero we have done all info streams. */ | |
7166 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 7167 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 7168 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
7169 &readcount, FALSE, FALSE, &context) | |
7170 || readcount == 0) | |
7171 break; | |
7172 | |
7173 /* We only deal with streams that have a name. The normal | |
7174 * file data appears to be without a name, even though docs | |
7175 * suggest it is called "::$DATA". */ | |
7176 if (sid.dwStreamNameSize > 0) | |
7177 { | |
7178 /* Read the stream name. */ | |
7179 if (!BackupRead(sh, (LPBYTE)streamname, | |
7180 sid.dwStreamNameSize, | |
7181 &readcount, FALSE, FALSE, &context)) | |
7182 break; | |
7183 | |
7184 /* Copy an info stream with a name ":anything:$DATA". | |
7185 * Skip "::$DATA", it has no stream name (examples suggest | |
7186 * it might be used for the normal file contents). | |
7187 * Note that BackupRead() counts bytes, but the name is in | |
7188 * wide characters. */ | |
7189 len = readcount / sizeof(WCHAR); | |
7190 streamname[len] = 0; | |
7191 if (len > 7 && wcsicmp(streamname + len - 6, | |
7192 L":$DATA") == 0) | |
7193 { | |
7194 streamname[len - 6] = 0; | |
7195 copy_substream(sh, &context, tow, streamname, | |
10 | 7196 (long)sid.Size.u.LowPart); |
7 | 7197 } |
7198 } | |
7199 | |
7200 /* Advance to the next stream. We might try seeking too far, | |
7201 * but BackupSeek() doesn't skip over stream borders, thus | |
7202 * that's OK. */ | |
323 | 7203 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 7204 &lo, &hi, &context); |
7205 } | |
7206 | |
7207 /* Clear the context. */ | |
7208 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
7209 | |
7210 CloseHandle(sh); | |
7211 } | |
7212 } | |
7213 vim_free(fromw); | |
7214 vim_free(tow); | |
7215 } | |
7216 #endif | |
7217 | |
7218 /* | |
7219 * Copy file attributes from file "from" to file "to". | |
7220 * For Windows NT and later we copy info streams. | |
7221 * Always returns zero, errors are ignored. | |
7222 */ | |
7223 int | |
7224 mch_copy_file_attribute(char_u *from, char_u *to) | |
7225 { | |
7226 #ifdef FEAT_MBYTE | |
7227 /* File streams only work on Windows NT and later. */ | |
7228 PlatformId(); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7229 copy_infostreams(from, to); |
7 | 7230 #endif |
7231 return 0; | |
7232 } | |
7233 | |
7234 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
7235 /* | |
7236 * Recreate a destroyed stack guard page in win32. | |
7237 * Written by Benjamin Peterson. | |
7238 */ | |
7239 | |
7240 /* These magic numbers are from the MS header files */ | |
7241 #define MIN_STACK_WINNT 2 | |
7242 | |
7243 /* | |
7244 * This function does the same thing as _resetstkoflw(), which is only | |
7245 * available in DevStudio .net and later. | |
7246 * Returns 0 for failure, 1 for success. | |
7247 */ | |
7248 int | |
7249 myresetstkoflw(void) | |
7250 { | |
7251 BYTE *pStackPtr; | |
7252 BYTE *pGuardPage; | |
7253 BYTE *pStackBase; | |
7254 BYTE *pLowestPossiblePage; | |
7255 MEMORY_BASIC_INFORMATION mbi; | |
7256 SYSTEM_INFO si; | |
7257 DWORD nPageSize; | |
7258 DWORD dummy; | |
7259 | |
7260 PlatformId(); | |
7261 | |
7262 /* We need to know the system page size. */ | |
7263 GetSystemInfo(&si); | |
7264 nPageSize = si.dwPageSize; | |
7265 | |
7266 /* ...and the current stack pointer */ | |
7267 pStackPtr = (BYTE*)_alloca(1); | |
7268 | |
7269 /* ...and the base of the stack. */ | |
7270 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
7271 return 0; | |
7272 pStackBase = (BYTE*)mbi.AllocationBase; | |
7273 | |
7274 /* ...and the page thats min_stack_req pages away from stack base; this is | |
7275 * 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
|
7276 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7277 |
7 | 7278 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7279 /* 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
|
7280 * 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
|
7281 */ |
7 | 7282 BYTE *pBlock = pStackBase; |
7283 | |
406 | 7284 for (;;) |
7 | 7285 { |
7286 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
7287 return 0; | |
7288 | |
7289 pBlock += mbi.RegionSize; | |
7290 | |
7291 if (mbi.State & MEM_COMMIT) | |
7292 break; | |
7293 } | |
7294 | |
7295 /* mbi now describes the first committed block in the stack. */ | |
7296 if (mbi.Protect & PAGE_GUARD) | |
7297 return 1; | |
7298 | |
7299 /* decide where the guard page should start */ | |
7300 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
7301 pGuardPage = pLowestPossiblePage; | |
7302 else | |
7303 pGuardPage = (BYTE*)mbi.BaseAddress; | |
7304 | |
7305 /* allocate the guard page */ | |
7306 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
7307 return 0; | |
7308 | |
7309 /* apply the guard attribute to the page */ | |
7310 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
7311 &dummy)) | |
7312 return 0; | |
7313 } | |
7314 | |
7315 return 1; | |
7316 } | |
7317 #endif | |
26 | 7318 |
7319 | |
7320 #if defined(FEAT_MBYTE) || defined(PROTO) | |
7321 /* | |
7322 * The command line arguments in UCS2 | |
7323 */ | |
344 | 7324 static int nArgsW = 0; |
26 | 7325 static LPWSTR *ArglistW = NULL; |
7326 static int global_argc = 0; | |
7327 static char **global_argv; | |
7328 | |
7329 static int used_file_argc = 0; /* last argument in global_argv[] used | |
7330 for the argument list. */ | |
7331 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
7332 command line arguments added to | |
7333 the argument list */ | |
7334 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
7335 static int used_file_literal = FALSE; /* take file names literally */ | |
7336 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 7337 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 7338 static int used_alist_count = 0; |
7339 | |
7340 | |
7341 /* | |
7342 * Get the command line arguments. Unicode version. | |
7343 * Returns argc. Zero when something fails. | |
7344 */ | |
7345 int | |
7346 get_cmd_argsW(char ***argvp) | |
7347 { | |
7348 char **argv = NULL; | |
7349 int argc = 0; | |
7350 int i; | |
7351 | |
6193 | 7352 free_cmd_argsW(); |
26 | 7353 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7354 if (ArglistW != NULL) | |
7355 { | |
7356 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7357 if (argv != NULL) | |
7358 { | |
7359 argc = nArgsW; | |
7360 argv[argc] = NULL; | |
7361 for (i = 0; i < argc; ++i) | |
7362 { | |
7363 int len; | |
7364 | |
7365 /* Convert each Unicode argument to the current codepage. */ | |
7366 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 7367 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7368 (LPSTR *)&argv[i], &len, 0, 0); |
7369 if (argv[i] == NULL) | |
7370 { | |
7371 /* Out of memory, clear everything. */ | |
7372 while (i > 0) | |
7373 free(argv[--i]); | |
7374 free(argv); | |
5529 | 7375 argv = NULL; |
26 | 7376 argc = 0; |
7377 } | |
7378 } | |
7379 } | |
7380 } | |
7381 | |
7382 global_argc = argc; | |
7383 global_argv = argv; | |
7384 if (argc > 0) | |
6193 | 7385 { |
7386 if (used_file_indexes != NULL) | |
7387 free(used_file_indexes); | |
26 | 7388 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7389 } |
26 | 7390 |
7391 if (argvp != NULL) | |
7392 *argvp = argv; | |
7393 return argc; | |
7394 } | |
7395 | |
7396 void | |
7397 free_cmd_argsW(void) | |
7398 { | |
7399 if (ArglistW != NULL) | |
7400 { | |
7401 GlobalFree(ArglistW); | |
7402 ArglistW = NULL; | |
7403 } | |
7404 } | |
7405 | |
7406 /* | |
7407 * Remember "name" is an argument that was added to the argument list. | |
7408 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7409 * is called. | |
7410 */ | |
7411 void | |
819 | 7412 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7413 { |
7414 int i; | |
7415 | |
7416 if (used_file_indexes == NULL) | |
7417 return; | |
7418 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7419 if (STRCMP(global_argv[i], name) == 0) | |
7420 { | |
7421 used_file_argc = i; | |
7422 used_file_indexes[used_file_count++] = i; | |
7423 break; | |
7424 } | |
7425 used_file_literal = literal; | |
7426 used_file_full_path = full_path; | |
819 | 7427 used_file_diff_mode = diff_mode; |
26 | 7428 } |
7429 | |
7430 /* | |
7431 * Remember the length of the argument list as it was. If it changes then we | |
7432 * leave it alone when 'encoding' is set. | |
7433 */ | |
7434 void | |
7435 set_alist_count(void) | |
7436 { | |
7437 used_alist_count = GARGCOUNT; | |
7438 } | |
7439 | |
7440 /* | |
7441 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
7442 * has been changed while starting up. Use the UCS-2 command line arguments | |
7443 * and convert them to 'encoding'. | |
7444 */ | |
7445 void | |
7446 fix_arg_enc(void) | |
7447 { | |
7448 int i; | |
7449 int idx; | |
7450 char_u *str; | |
41 | 7451 int *fnum_list; |
26 | 7452 |
7453 /* Safety checks: | |
7454 * - if argument count differs between the wide and non-wide argument | |
7455 * list, something must be wrong. | |
7456 * - the file name arguments must have been located. | |
7457 * - the length of the argument list wasn't changed by the user. | |
7458 */ | |
344 | 7459 if (global_argc != nArgsW |
26 | 7460 || ArglistW == NULL |
7461 || used_file_indexes == NULL | |
7462 || used_file_count == 0 | |
7463 || used_alist_count != GARGCOUNT) | |
7464 return; | |
7465 | |
41 | 7466 /* Remember the buffer numbers for the arguments. */ |
7467 fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT); | |
7468 if (fnum_list == NULL) | |
7469 return; /* out of memory */ | |
7470 for (i = 0; i < GARGCOUNT; ++i) | |
7471 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7472 | |
26 | 7473 /* Clear the argument list. Make room for the new arguments. */ |
7474 alist_clear(&global_alist); | |
7475 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 7476 return; /* out of memory */ |
26 | 7477 |
7478 for (i = 0; i < used_file_count; ++i) | |
7479 { | |
7480 idx = used_file_indexes[i]; | |
1752 | 7481 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7482 if (str != NULL) |
41 | 7483 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7484 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
|
7485 |
819 | 7486 #ifdef FEAT_DIFF |
7487 /* When using diff mode may need to concatenate file name to | |
7488 * directory name. Just like it's done in main(). */ | |
7489 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
7490 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7491 { | |
7492 char_u *r; | |
7493 | |
7494 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7495 if (r != NULL) | |
7496 { | |
7497 vim_free(str); | |
7498 str = r; | |
7499 } | |
7500 } | |
7501 #endif | |
41 | 7502 /* Re-use the old buffer by renaming it. When not using literal |
7503 * names it's done by alist_expand() below. */ | |
7504 if (used_file_literal) | |
7505 buf_set_name(fnum_list[i], str); | |
7506 | |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7507 /* 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
|
7508 * 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
|
7509 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
|
7510 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7511 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
|
7512 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7513 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
|
7514 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7515 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7516 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7517 } |
26 | 7518 } |
7519 | |
7520 if (!used_file_literal) | |
7521 { | |
7522 /* Now expand wildcards in the arguments. */ | |
7523 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
7524 * 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
|
7525 * "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
|
7526 * 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
|
7527 * 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
|
7528 * encoding options were changed. */ |
26 | 7529 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
|
7530 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); |
41 | 7531 alist_expand(fnum_list, used_alist_count); |
26 | 7532 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
|
7533 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); |
26 | 7534 } |
7535 | |
7536 /* If wildcard expansion failed, we are editing the first file of the | |
7537 * arglist and there is no file name: Edit the first argument now. */ | |
7538 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
7539 { | |
7540 do_cmdline_cmd((char_u *)":rewind"); | |
7541 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
|
7542 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); |
26 | 7543 } |
41 | 7544 |
7545 set_alist_count(); | |
26 | 7546 } |
7547 #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
|
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 int |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7550 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
|
7551 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7552 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
|
7553 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7554 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
|
7555 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
|
7556 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
|
7557 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7558 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
|
7559 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7560 #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
|
7561 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
|
7562 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7563 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
|
7564 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7565 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
|
7566 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
|
7567 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
|
7568 _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
|
7569 # 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
|
7570 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
|
7571 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7572 /* 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
|
7573 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
|
7574 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7575 else |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7576 #endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7577 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7578 _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
|
7579 # 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
|
7580 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
|
7581 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7582 /* 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
|
7583 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
|
7584 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7585 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7586 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
|
7587 } |
13314
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 #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
|
7590 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7591 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7592 * 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
|
7593 * 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
|
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 # 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
|
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 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
|
7598 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
|
7599 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7600 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
|
7601 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
|
7602 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
|
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 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
|
7605 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
|
7606 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
|
7607 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
|
7608 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
|
7609 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
|
7610 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7611 /* 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
|
7612 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
|
7613 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
|
7614 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7615 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7616 (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
|
7617 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
|
7618 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7619 (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
|
7620 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
|
7621 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
|
7622 && 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
|
7623 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
|
7624 } |
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 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
|
7627 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
|
7628 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
|
7629 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
|
7630 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
|
7631 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7632 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
|
7633 } |
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 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
|
7636 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
|
7637 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7638 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
|
7639 } |
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 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
|
7642 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
|
7643 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
|
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 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7646 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
|
7647 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
|
7648 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
|
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 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
|
7651 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
|
7652 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
|
7653 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
|
7654 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
|
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 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7657 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
|
7658 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
|
7659 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
|
7660 { |
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 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
|
7662 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7663 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
|
7664 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
|
7665 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7666 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7667 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
|
7668 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
|
7669 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
|
7670 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
|
7671 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7672 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7673 /* 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
|
7674 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
|
7675 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
|
7676 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
|
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 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
|
7679 *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
|
7680 *p++ = '['; |
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 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
|
7683 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7684 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
|
7685 *p++ = ';'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7686 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7687 p--; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7688 *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
|
7689 *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
|
7690 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
|
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 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7693 # ifdef FEAT_TERMGUICOLORS |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7694 static int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7695 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7696 int cterm) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7697 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
7698 char_u r, g, b, idx; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7699 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7700 cterm_color2rgb(cterm, &r, &g, &b, &idx); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7701 return (((int)r << 16) | ((int)g << 8) | (int)b); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7702 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7703 # endif |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7704 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7705 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
|
7706 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
|
7707 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7708 # 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
|
7709 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
|
7710 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
|
7711 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
|
7712 guicolor_T bg = INVALCOLOR; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7713 int ctermfg; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7714 int ctermbg; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7715 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7716 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
|
7717 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7718 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7719 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
|
7720 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
|
7721 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
|
7722 if (fg == INVALCOLOR) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7723 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7724 ctermfg = -1; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7725 if (id > 0) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7726 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7727 fg = ctermfg != -1 ? ctermtoxterm(ctermfg) : 0xc0c0c0; /* white */ |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7728 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7729 if (bg == INVALCOLOR) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7730 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7731 ctermbg = -1; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7732 if (id > 0) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7733 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7734 bg = ctermbg != -1 ? ctermtoxterm(ctermbg) : 0x000000; /* black */ |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7735 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7736 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
|
7737 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
|
7738 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7739 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
|
7740 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
|
7741 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
|
7742 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7743 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
|
7744 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
|
7745 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
|
7746 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
|
7747 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
|
7748 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
|
7749 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
|
7750 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7751 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7752 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7753 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
|
7754 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
|
7755 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7756 # 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
|
7757 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
|
7758 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7759 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
|
7760 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
|
7761 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
|
7762 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7763 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
|
7764 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
|
7765 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
|
7766 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
|
7767 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
|
7768 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
|
7769 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
|
7770 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7771 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7772 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7773 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7774 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
|
7775 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7776 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
|
7777 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
|
7778 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7779 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
|
7780 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7781 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7782 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7783 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
|
7784 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7785 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
|
7786 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7787 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7788 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7789 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
|
7790 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7791 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
|
7792 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7793 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7794 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7795 is_term_win32(void) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7796 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7797 return T_NAME != NULL && STRCMP(T_NAME, "win32") == 0; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7798 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7799 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7800 #endif |