annotate src/os_win32.c @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents 30498a07e7ab
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7 * See README.txt for an overview of the Vim source code.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
10 * os_win32.c
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
11 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
12 * Used for both the console version and the Win32 GUI. A lot of code is for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
13 * the console version only, so there is a lot of "#ifndef FEAT_GUI_MSWIN".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
14 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
15 * Win32 (Windows NT and Windows 95) system-dependent routines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
16 * Portions lifted from the Win32 SDK samples, the MSDOS-dependent code,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
17 * NetHack 3.1.3, GNU Emacs 19.30, and Vile 5.5.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
18 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
19 * George V. Reilly <george@reilly.org> wrote most of this.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
20 * Roger Knobbe <rogerk@wonderware.com> did the initial port of Vim 3.0.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
21 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
22
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
23 #include "vim.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
24
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
25 #ifdef FEAT_MZSCHEME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
26 # include "if_mzsch.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
27 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
28
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
29 #include <sys/types.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
30 #include <signal.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
31 #include <limits.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
32
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
33 // cproto fails on missing include files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
34 #ifndef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
35 # include <process.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
36 # include <winternl.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
37 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
38
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
39 #undef chdir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
40 #ifdef __GNUC__
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
41 # ifndef __MINGW32__
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
42 # include <dirent.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
43 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
44 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
45 # include <direct.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
46 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
47
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
48 #ifndef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
49 # if !defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
50 # include <shellapi.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
51 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
52 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
53
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
54 #ifdef FEAT_JOB_CHANNEL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
55 # include <tlhelp32.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
56 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
57
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
58 #ifdef __MINGW32__
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
59 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
60 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
61 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
62 # ifndef RIGHTMOST_BUTTON_PRESSED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
63 # define RIGHTMOST_BUTTON_PRESSED 0x0002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
64 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
65 # ifndef FROM_LEFT_2ND_BUTTON_PRESSED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
66 # define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
67 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
68 # ifndef FROM_LEFT_3RD_BUTTON_PRESSED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
69 # define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
70 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
71 # ifndef FROM_LEFT_4TH_BUTTON_PRESSED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
72 # define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
73 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
74
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
75 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
76 * EventFlags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
77 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
78 # ifndef MOUSE_MOVED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
79 # define MOUSE_MOVED 0x0001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
80 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
81 # ifndef DOUBLE_CLICK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
82 # define DOUBLE_CLICK 0x0002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
83 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
84 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
85
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
86 // Record all output and all keyboard & mouse input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
87 // #define MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
88
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
89 #ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
90 FILE* fdDump = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
91 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
92
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
93 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
94 * When generating prototypes for Win32 on Unix, these lines make the syntax
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
95 * errors disappear. They do not need to be correct.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
96 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
97 #ifdef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
98 # define WINAPI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
99 typedef char * LPCSTR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
100 typedef char * LPWSTR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
101 typedef int ACCESS_MASK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
102 typedef int BOOL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
103 typedef int BOOLEAN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
104 typedef int CALLBACK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
105 typedef int COLORREF;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
106 typedef int CONSOLE_CURSOR_INFO;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
107 typedef int COORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
108 typedef int DWORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
109 typedef int HANDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
110 typedef int LPHANDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
111 typedef int HDC;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
112 typedef int HFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
113 typedef int HICON;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
114 typedef int HINSTANCE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
115 typedef int HWND;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
116 typedef int INPUT_RECORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
117 typedef int INT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
118 typedef int KEY_EVENT_RECORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
119 typedef int LOGFONT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
120 typedef int LPBOOL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
121 typedef int LPCTSTR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
122 typedef int LPDWORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
123 typedef int LPSTR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
124 typedef int LPTSTR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
125 typedef int LPVOID;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
126 typedef int MOUSE_EVENT_RECORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
127 typedef int PACL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
128 typedef int PDWORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
129 typedef int PHANDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
130 typedef int PRINTDLG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
131 typedef int PSECURITY_DESCRIPTOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
132 typedef int PSID;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
133 typedef int SECURITY_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
134 typedef int SHORT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
135 typedef int SMALL_RECT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
136 typedef int TEXTMETRIC;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
137 typedef int TOKEN_INFORMATION_CLASS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
138 typedef int TRUSTEE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
139 typedef int WORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
140 typedef int WCHAR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
141 typedef void VOID;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
142 typedef int BY_HANDLE_FILE_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
143 typedef int SE_OBJECT_TYPE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
144 typedef int PSNSECINFO;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
145 typedef int PSNSECINFOW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
146 typedef int STARTUPINFO;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
147 typedef int PROCESS_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
148 typedef int LPSECURITY_ATTRIBUTES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
149 # define __stdcall // empty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
150 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
152 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
153 // Win32 Console handles for input and output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
154 static HANDLE g_hConIn = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
155 static HANDLE g_hConOut = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
156
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
157 // Win32 Screen buffer,coordinate,console I/O information
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
158 static SMALL_RECT g_srScrollRegion;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
159 static COORD g_coord; // 0-based, but external coords are 1-based
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
160
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
161 // The attribute of the screen when the editor was started
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
162 static WORD g_attrDefault = 7; // lightgray text on black background
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
163 static WORD g_attrCurrent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
165 static int g_fCBrkPressed = FALSE; // set by ctrl-break interrupt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
166 static int g_fCtrlCPressed = FALSE; // set when ctrl-C or ctrl-break detected
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
167 static int g_fForceExit = FALSE; // set when forcefully exiting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
168
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
169 static void scroll(unsigned cLines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
170 static void set_scroll_region(unsigned left, unsigned top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
171 unsigned right, unsigned bottom);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
172 static void set_scroll_region_tb(unsigned top, unsigned bottom);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
173 static void set_scroll_region_lr(unsigned left, unsigned right);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
174 static void insert_lines(unsigned cLines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
175 static void delete_lines(unsigned cLines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
176 static void gotoxy(unsigned x, unsigned y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
177 static void standout(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
178 static int s_cursor_visible = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
179 static int did_create_conin = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
180 // The 'input_record_buffer' is an internal dynamic fifo queue of MS-Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
181 // console INPUT_RECORD events that are normally read from the console input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
182 // buffer. This provides an injection point for testing the low-level handling
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
183 // of INPUT_RECORDs.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
184 typedef struct input_record_buffer_node_S
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
185 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
186 INPUT_RECORD ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
187 struct input_record_buffer_node_S *next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
188 } input_record_buffer_node_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
189 typedef struct input_record_buffer_S
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
191 input_record_buffer_node_T *head;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
192 input_record_buffer_node_T *tail;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
193 int length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
194 } input_record_buffer_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
195 static input_record_buffer_T input_record_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
196 static int read_input_record_buffer(INPUT_RECORD* irEvents, int nMaxLength);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
197 static int write_input_record_buffer(INPUT_RECORD* irEvents, int nLength);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
198 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
199 #ifdef FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
200 static int s_dont_use_vimrun = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
201 static int need_vimrun_warning = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
202 static char *vimrun_path = "vimrun ";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
203 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
204
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
205 static int win32_getattrs(char_u *name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
206 static int win32_setattrs(char_u *name, int attrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
207 static int win32_set_archive(char_u *name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
209 static int conpty_working = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
210 static int conpty_type = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
211 static int conpty_stable = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
212 static int conpty_fix_type = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
213 static void vtp_flag_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
214
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
215 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
216 static int vtp_working = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
217 static void vtp_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
218 static void vtp_exit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
219 static void vtp_sgr_bulk(int arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
220 static void vtp_sgr_bulks(int argc, int *argv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
221
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
222 static int wt_working = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
223 static void wt_init(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
224
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
225 static int g_color_index_bg = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
226 static int g_color_index_fg = 7;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
227
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
228 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
229 static guicolor_T save_console_bg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
230 static guicolor_T save_console_fg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
231 static guicolor_T store_console_bg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
232 static guicolor_T store_console_fg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
233 static int default_console_color_bg = 0x000000; // black
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
234 static int default_console_color_fg = 0xc0c0c0; // white
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
235 # define USE_VTP (vtp_working && is_term_win32() \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
236 && (p_tgc || t_colors >= 256))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
237 # define USE_WT (wt_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
238 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
239 # define USE_VTP 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
240 # define USE_WT 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
241 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
243 static void set_console_color_rgb(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
244 static void reset_console_color_rgb(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
245 static void restore_console_color_rgb(void);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
246 #endif // !FEAT_GUI_MSWIN || VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
248 // This flag is newly created from Windows 10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
249 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
250 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
251 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
253 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
254 static int suppress_winsize = 1; // don't fiddle with console
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
255 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
257 static WCHAR *exe_pathw = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
259 static BOOL win8_or_later = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
260 static BOOL win10_22H2_or_later = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
261 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
262 static BOOL use_alternate_screen_buffer = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
263 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
265 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
266 * Get version number including build number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
267 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
268 typedef BOOL (WINAPI *PfnRtlGetVersion)(LPOSVERSIONINFOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
269 #define MAKE_VER(major, minor, build) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
270 (((major) << 24) | ((minor) << 16) | (build))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
271
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
272 static DWORD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
273 get_build_number(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
274 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
275 OSVERSIONINFOW osver;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
276 HMODULE hNtdll;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
277 PfnRtlGetVersion pRtlGetVersion;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
278 DWORD ver = MAKE_VER(0, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
279
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
280 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
281 hNtdll = GetModuleHandle("ntdll.dll");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
282 if (hNtdll == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
283 return ver;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
285 pRtlGetVersion =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
286 (PfnRtlGetVersion)GetProcAddress(hNtdll, "RtlGetVersion");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
287 pRtlGetVersion(&osver);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
288 ver = MAKE_VER(min(osver.dwMajorVersion, 255),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
289 min(osver.dwMinorVersion, 255),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
290 min(osver.dwBuildNumber, 32767));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
291 return ver;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
292 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
293
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
294 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
295 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
296 is_ambiwidth_event(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
297 INPUT_RECORD *ir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
298 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
299 return ir->EventType == KEY_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
300 && ir->Event.KeyEvent.bKeyDown
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
301 && ir->Event.KeyEvent.wRepeatCount == 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
302 && ir->Event.KeyEvent.wVirtualKeyCode == 0x12
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
303 && ir->Event.KeyEvent.wVirtualScanCode == 0x38
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
304 && ir->Event.KeyEvent.uChar.UnicodeChar == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
305 && ir->Event.KeyEvent.dwControlKeyState == 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
306 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
307
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
308 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
309 make_ambiwidth_event(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
310 INPUT_RECORD *down,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
311 INPUT_RECORD *up)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
312 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
313 down->Event.KeyEvent.wVirtualKeyCode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
314 down->Event.KeyEvent.wVirtualScanCode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
315 down->Event.KeyEvent.uChar.UnicodeChar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
316 = up->Event.KeyEvent.uChar.UnicodeChar;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
317 down->Event.KeyEvent.dwControlKeyState = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
318 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
319
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
320 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
321 * Version of ReadConsoleInput() that works with IME.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
322 * Works around problems on Windows 8.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
323 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
324 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
325 read_console_input(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
326 HANDLE hInput,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
327 INPUT_RECORD *lpBuffer,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
328 int nLength,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
329 LPDWORD lpEvents)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
330 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
331 enum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
332 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
333 IRSIZE = 10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
334 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
335 static INPUT_RECORD s_irCache[IRSIZE];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
336 static DWORD s_dwIndex = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
337 static DWORD s_dwMax = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
338 DWORD dwEvents;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
339 int head;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
340 int tail;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
341 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
342 static INPUT_RECORD s_irPseudo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
344 if (s_dwMax == 0 && input_record_buffer.length > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
345 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
346 dwEvents = read_input_record_buffer(s_irCache, IRSIZE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
347 s_dwIndex = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
348 s_dwMax = dwEvents;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
349 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
351 if (nLength == -2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
352 return (s_dwMax > 0) ? TRUE : FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
354 if (!win8_or_later)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
355 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
356 if (nLength == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
357 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
358 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
359 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
360
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
361 if (s_dwMax == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
362 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
363 if (!vtp_working && nLength == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
364 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
365 GetNumberOfConsoleInputEvents(hInput, &dwEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
366 if (dwEvents == 0 && nLength == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
367 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
368 ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
369 s_dwIndex = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
370 s_dwMax = dwEvents;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
371 if (dwEvents == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
372 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
373 *lpEvents = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
374 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
375 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
377 for (i = s_dwIndex; i < (int)s_dwMax - 1; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
378 if (is_ambiwidth_event(&s_irCache[i]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
379 make_ambiwidth_event(&s_irCache[i], &s_irCache[i + 1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
381 if (s_dwMax > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
382 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
383 head = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
384 tail = s_dwMax - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
385 while (head != tail)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
386 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
387 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
388 && s_irCache[head + 1].EventType
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
389 == WINDOW_BUFFER_SIZE_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
390 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
391 // Remove duplicate event to avoid flicker.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
392 for (i = head; i < tail; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
393 s_irCache[i] = s_irCache[i + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
394 --tail;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
395 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
396 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
397 head++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
398 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
399 s_dwMax = tail + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
400 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
401 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
402
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
403 if (s_irCache[s_dwIndex].EventType == KEY_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
404 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
405 if (s_irCache[s_dwIndex].Event.KeyEvent.wRepeatCount > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
406 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
407 s_irPseudo = s_irCache[s_dwIndex];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
408 s_irPseudo.Event.KeyEvent.wRepeatCount = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
409 s_irCache[s_dwIndex].Event.KeyEvent.wRepeatCount--;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
410 *lpBuffer = s_irPseudo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
411 *lpEvents = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
412 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
413 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
414 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
416 *lpBuffer = s_irCache[s_dwIndex];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
417 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
418 s_dwMax = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
419 *lpEvents = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
420 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
421 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
422
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
423 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
424 * Version of PeekConsoleInput() that works with IME.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
425 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
426 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
427 peek_console_input(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
428 HANDLE hInput,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
429 INPUT_RECORD *lpBuffer,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
430 DWORD nLength UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
431 LPDWORD lpEvents)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
432 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
433 return read_console_input(hInput, lpBuffer, -1, lpEvents);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
434 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
435
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
436 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
437 static DWORD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
438 msg_wait_for_multiple_objects(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
439 DWORD nCount,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
440 LPHANDLE pHandles,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
441 BOOL fWaitAll,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
442 DWORD dwMilliseconds,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
443 DWORD dwWakeMask)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
444 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
445 if (read_console_input(NULL, NULL, -2, NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
446 return WAIT_OBJECT_0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
447 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
448 dwMilliseconds, dwWakeMask);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
450 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
451
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
452 # ifndef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
453 static DWORD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
454 wait_for_single_object(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
455 HANDLE hHandle,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
456 DWORD dwMilliseconds)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
457 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
458 if (read_console_input(NULL, NULL, -2, NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
459 return WAIT_OBJECT_0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
460 return WaitForSingleObject(hHandle, dwMilliseconds);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
461 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
462 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
463 #endif // !FEAT_GUI_MSWIN || VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
465 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
466 mch_get_exe_name(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
467 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
468 // Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
469 // as the maximum length that works. Add 1 for a NUL byte and 5 for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
470 // "PATH=".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
471 #define MAX_ENV_PATH_LEN (8191 + 1 + 5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
472 WCHAR temp[MAX_ENV_PATH_LEN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
473 WCHAR buf[MAX_PATH];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
474 int updated = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
475 static int enc_prev = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
476
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
477 if (exe_name == NULL || exe_pathw == NULL || enc_prev != enc_codepage)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
478 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
479 // store the name of the executable, may be used for $VIM
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
480 GetModuleFileNameW(NULL, buf, MAX_PATH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
481 if (*buf != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
482 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
483 if (enc_codepage == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
484 enc_codepage = GetACP();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
485 vim_free(exe_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
486 exe_name = utf16_to_enc(buf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
487 enc_prev = enc_codepage;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
488
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
489 WCHAR *wp = wcsrchr(buf, '\\');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
490 if (wp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
491 *wp = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
492 vim_free(exe_pathw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
493 exe_pathw = _wcsdup(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
494 updated = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
495 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
496 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
498 if (exe_pathw == NULL || !updated)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
499 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
501 // Append our starting directory to $PATH, so that when doing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
502 // "!xxd" it's found in our starting directory. Needed because
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
503 // SearchPath() also looks there.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
504 WCHAR *p = _wgetenv(L"PATH");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
505 if (p == NULL || wcslen(p) + wcslen(exe_pathw) + 2 + 5 < MAX_ENV_PATH_LEN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
506 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
507 wcscpy(temp, L"PATH=");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
508
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
509 if (p == NULL || *p == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
510 wcscat(temp, exe_pathw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
511 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
512 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
513 wcscat(temp, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
514
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
515 // Check if exe_path is already included in $PATH.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
516 if (wcsstr(temp, exe_pathw) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
517 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
518 // Append ';' if $PATH doesn't end with it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
519 size_t len = wcslen(temp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
520 if (temp[len - 1] != L';')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
521 wcscat(temp, L";");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
523 wcscat(temp, exe_pathw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
524 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
525 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
526 _wputenv(temp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
527 #ifdef libintl_wputenv
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
528 libintl_wputenv(temp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
529 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
530 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
531 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
533 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
534 * Unescape characters in "p" that appear in "escaped".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
535 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
536 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
537 unescape_shellxquote(char_u *p, char_u *escaped)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
538 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
539 int l = (int)STRLEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
540 int n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
542 while (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
543 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
544 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
545 mch_memmove(p, p + 1, l--);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
546 n = (*mb_ptr2len)(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
547 p += n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
548 l -= n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
549 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
550 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
551
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
552 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
553 * Load library "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
554 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
555 HINSTANCE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
556 vimLoadLib(const char *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
557 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
558 HINSTANCE dll = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
560 // No need to load any library when registering OLE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
561 if (found_register_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
562 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
563
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
564 // NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
565 // vimLoadLib() recursively, which causes a stack overflow.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
566 if (exe_pathw == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
567 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
568 mch_get_exe_name();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
569 if (exe_pathw == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
570 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
571 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
572
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
573 WCHAR old_dirw[MAXPATHL];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
574
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
575 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
576 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
577
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
578 // Change directory to where the executable is, both to make
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
579 // sure we find a .dll there and to avoid looking for a .dll
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
580 // in the current directory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
581 SetCurrentDirectoryW(exe_pathw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
582 dll = LoadLibrary(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
583 SetCurrentDirectoryW(old_dirw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
584 return dll;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
587 #if defined(VIMDLL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
588 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
589 * Check if the current executable file is for the GUI subsystem.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
590 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
591 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
592 mch_is_gui_executable(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
593 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
594 PBYTE pImage = (PBYTE)GetModuleHandle(NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
595 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)pImage;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
596 PIMAGE_NT_HEADERS pPE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
597
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
598 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
599 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
600 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
601 if (pPE->Signature != IMAGE_NT_SIGNATURE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
602 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
603 if (pPE->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
604 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
605 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
606 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
607 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
608
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
609 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
610 || defined(FEAT_PYTHON3) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
611 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
612 * Get related information about 'funcname' which is imported by 'hInst'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
613 * If 'info' is 0, return the function address.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
614 * If 'info' is 1, return the module name which the function is imported from.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
615 * If 'info' is 2, hook the function with 'ptr', and return the original
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
616 * function address.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
617 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
618 static void *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
619 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
620 const void *ptr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
621 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
622 PBYTE pImage = (PBYTE)hInst;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
623 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
624 PIMAGE_NT_HEADERS pPE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
625 PIMAGE_IMPORT_DESCRIPTOR pImpDesc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
626 PIMAGE_THUNK_DATA pIAT; // Import Address Table
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
627 PIMAGE_THUNK_DATA pINT; // Import Name Table
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
628 PIMAGE_IMPORT_BY_NAME pImpName;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
629
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
630 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
631 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
632 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
633 if (pPE->Signature != IMAGE_NT_SIGNATURE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
634 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
635 pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR)(pImage
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
636 + pPE->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
637 .VirtualAddress);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
638 for (; pImpDesc->FirstThunk; ++pImpDesc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
639 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
640 if (!pImpDesc->OriginalFirstThunk)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
641 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
642 pIAT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->FirstThunk);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
643 pINT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->OriginalFirstThunk);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
644 for (; pIAT->u1.Function; ++pIAT, ++pINT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
645 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
646 if (IMAGE_SNAP_BY_ORDINAL(pINT->u1.Ordinal))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
647 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
648 pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
649 + (UINT_PTR)(pINT->u1.AddressOfData));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
650 if (strcmp((char *)pImpName->Name, funcname) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
651 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
652 void *original;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
653 DWORD old, new = PAGE_READWRITE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
654
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
655 switch (info)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
656 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
657 case 0:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
658 return (void *)pIAT->u1.Function;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
659 case 1:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
660 return (void *)(pImage + pImpDesc->Name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
661 case 2:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
662 original = (void *)pIAT->u1.Function;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
663 VirtualProtect(&pIAT->u1.Function, sizeof(void *),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
664 new, &old);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
665 pIAT->u1.Function = (UINT_PTR)ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
666 VirtualProtect(&pIAT->u1.Function, sizeof(void *),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
667 old, &new);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
668 return original;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
669 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
670 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
671 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
673 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
674 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
675 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
676 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
678 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
679 * Get the module handle which 'funcname' in 'hInst' is imported from.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
680 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
681 HINSTANCE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
682 find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
683 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
684 char *modulename;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
685
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
686 modulename = (char *)get_imported_func_info(hInst, funcname, 1, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
687 if (modulename != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
688 return GetModuleHandleA(modulename);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
689 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
690 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
691
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
692 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
693 * Get the address of 'funcname' which is imported by 'hInst' DLL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
694 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
695 void *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
696 get_dll_import_func(HINSTANCE hInst, const char *funcname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
697 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
698 return get_imported_func_info(hInst, funcname, 0, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
699 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
700
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
701 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
702 * Hook the function named 'funcname' which is imported by 'hInst' DLL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
703 * and return the original function address.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
704 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
705 void *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
706 hook_dll_import_func(HINSTANCE hInst, const char *funcname, const void *hook)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
707 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
708 return get_imported_func_info(hInst, funcname, 2, hook);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
709 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
710 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
711
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
712 #if defined(DYNAMIC_GETTEXT) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
713 # ifndef GETTEXT_DLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
714 # define GETTEXT_DLL "libintl.dll"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
715 # define GETTEXT_DLL_ALT1 "libintl-8.dll"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
716 # define GETTEXT_DLL_ALT2 "intl.dll"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
717 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
718 // Dummy functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
719 static char *null_libintl_gettext(const char *);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
720 static char *null_libintl_ngettext(const char *, const char *, unsigned long n);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
721 static char *null_libintl_textdomain(const char *);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
722 static char *null_libintl_bindtextdomain(const char *, const char *);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
723 static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
724 static int null_libintl_wputenv(const wchar_t *);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
726 static HINSTANCE hLibintlDLL = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
727 char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
728 char *(*dyn_libintl_ngettext)(const char *, const char *, unsigned long n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
729 = null_libintl_ngettext;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
730 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
731 char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
732 = null_libintl_bindtextdomain;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
733 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
734 = null_libintl_bind_textdomain_codeset;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
735 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
736
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
737 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
738 dyn_libintl_init(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
739 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
740 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
741 static struct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
742 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
743 char *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
744 FARPROC *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
745 } libintl_entry[] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
746 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
747 {"gettext", (FARPROC*)&dyn_libintl_gettext},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
748 {"ngettext", (FARPROC*)&dyn_libintl_ngettext},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
749 {"textdomain", (FARPROC*)&dyn_libintl_textdomain},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
750 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
751 {NULL, NULL}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
752 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
753 HINSTANCE hmsvcrt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
754
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
755 // No need to initialize twice.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
756 if (hLibintlDLL != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
757 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
758 // Load gettext library (libintl.dll and other names).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
759 hLibintlDLL = vimLoadLib(GETTEXT_DLL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
760 # ifdef GETTEXT_DLL_ALT1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
761 if (!hLibintlDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
762 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
763 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
764 # ifdef GETTEXT_DLL_ALT2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
765 if (!hLibintlDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
766 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
767 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
768 if (!hLibintlDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
769 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
770 if (p_verbose > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
771 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
772 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
773 semsg(_(e_could_not_load_library_str_str), GETTEXT_DLL, GetWin32Error());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
774 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
775 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
776 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
777 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
778 for (i = 0; libintl_entry[i].name != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
779 && libintl_entry[i].ptr != NULL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
780 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
781 if ((*libintl_entry[i].ptr = GetProcAddress(hLibintlDLL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
782 libintl_entry[i].name)) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
783 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
784 dyn_libintl_end();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
785 if (p_verbose > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
786 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
787 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
788 semsg(_(e_could_not_load_library_function_str), libintl_entry[i].name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
789 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
790 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
791 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
792 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
793 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
794
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
795 // The bind_textdomain_codeset() function is optional.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
796 dyn_libintl_bind_textdomain_codeset = (char *(*)(const char *, const char *))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
797 GetProcAddress(hLibintlDLL, "bind_textdomain_codeset");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
798 if (dyn_libintl_bind_textdomain_codeset == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
799 dyn_libintl_bind_textdomain_codeset =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
800 null_libintl_bind_textdomain_codeset;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
801
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
802 // _wputenv() function for the libintl.dll is optional.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
803 hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
804 if (hmsvcrt != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
805 dyn_libintl_wputenv = (int (*)(const wchar_t *))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
806 GetProcAddress(hmsvcrt, "_wputenv");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
807 if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
808 dyn_libintl_wputenv = null_libintl_wputenv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
809
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
810 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
811 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
812
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
813 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
814 dyn_libintl_end(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
815 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
816 if (hLibintlDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
817 FreeLibrary(hLibintlDLL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
818 hLibintlDLL = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
819 dyn_libintl_gettext = null_libintl_gettext;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
820 dyn_libintl_ngettext = null_libintl_ngettext;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
821 dyn_libintl_textdomain = null_libintl_textdomain;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
822 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
823 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
824 dyn_libintl_wputenv = null_libintl_wputenv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
825 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
826
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
827 static char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
828 null_libintl_gettext(const char *msgid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
829 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
830 return (char*)msgid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
831 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
832
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
833 static char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
834 null_libintl_ngettext(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
835 const char *msgid,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
836 const char *msgid_plural,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
837 unsigned long n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
838 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
839 return (char *)(n == 1 ? msgid : msgid_plural);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
840 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
842 static char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
843 null_libintl_bindtextdomain(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
844 const char *domainname UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
845 const char *dirname UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
846 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
847 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
848 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
849
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
850 static char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
851 null_libintl_bind_textdomain_codeset(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
852 const char *domainname UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
853 const char *codeset UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
854 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
855 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
856 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
857
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
858 static char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
859 null_libintl_textdomain(const char *domainname UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
860 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
861 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
862 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
863
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
864 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
865 null_libintl_wputenv(const wchar_t *envstring UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
866 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
867 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
868 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
870 #endif // DYNAMIC_GETTEXT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
872 // This symbol is not defined in older versions of the SDK or Visual C++
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
874 #ifndef VER_PLATFORM_WIN32_WINDOWS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
875 # define VER_PLATFORM_WIN32_WINDOWS 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
876 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
877
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
878 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
879 # ifndef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
880 # include <aclapi.h>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
881 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
882 # ifndef PROTECTED_DACL_SECURITY_INFORMATION
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
883 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
884 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
885 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
886
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
887 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
888 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
889 * Enables or disables the specified privilege.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
890 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
891 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
892 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
893 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
894 BOOL bResult;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
895 LUID luid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
896 HANDLE hToken;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
897 TOKEN_PRIVILEGES tokenPrivileges;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
899 if (!OpenProcessToken(GetCurrentProcess(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
900 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
901 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
902
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
903 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
904 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
905 CloseHandle(hToken);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
906 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
907 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
908
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
909 tokenPrivileges.PrivilegeCount = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
910 tokenPrivileges.Privileges[0].Luid = luid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
911 tokenPrivileges.Privileges[0].Attributes = bEnable ?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
912 SE_PRIVILEGE_ENABLED : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
913
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
914 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
915 sizeof(TOKEN_PRIVILEGES), NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
917 CloseHandle(hToken);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
918
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
919 return bResult && GetLastError() == ERROR_SUCCESS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
920 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
921 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
922
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
923 #ifdef _MSC_VER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
924 // Suppress the deprecation warning for using GetVersionEx().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
925 // It is needed for implementing "windowsversion()".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
926 # pragma warning(push)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
927 # pragma warning(disable: 4996)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
928 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
929 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
930 * Set "win8_or_later" and fill in "windowsVersion" if possible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
931 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
932 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
933 PlatformId(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
934 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
935 static int done = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
936
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
937 if (done)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
938 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
939
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
940 OSVERSIONINFO ovi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
942 ovi.dwOSVersionInfoSize = sizeof(ovi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
943 GetVersionEx(&ovi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
944
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
945 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
946 vim_snprintf(windowsVersion, sizeof(windowsVersion), "%d.%d",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
947 (int)ovi.dwMajorVersion, (int)ovi.dwMinorVersion);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
948 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
949 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
950 || ovi.dwMajorVersion > 6)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
951 win8_or_later = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
953 if ((ovi.dwMajorVersion == 10 && ovi.dwBuildNumber >= 19045)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
954 || ovi.dwMajorVersion > 10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
955 win10_22H2_or_later = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
956
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
957 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
958 // Enable privilege for getting or setting SACLs.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
959 win32_enable_privilege(SE_SECURITY_NAME, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
960 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
961 done = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
962 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
963 #ifdef _MSC_VER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
964 # pragma warning(pop)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
965 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
966
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
967 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
968
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
969 # define SHIFT (SHIFT_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
970 # define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
971 # define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
972 # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
973
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
975 // When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
976 // We map function keys to their ANSI terminal equivalents, as produced
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
977 // by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
978 // ANSI key with a value >= '\300' is nonstandard, but provided anyway
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
979 // so that the user can have access to all SHIFT-, CTRL-, and ALT-
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
980 // combinations of function/arrow/etc keys.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
981
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
982 static const struct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
983 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
984 WORD wVirtKey;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
985 BOOL fAnsiKey;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
986 int chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
987 int chShift;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
988 int chCtrl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
989 int chAlt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
990 } VirtKeyMap[] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
991 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
992 // Key ANSI alone shift ctrl alt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
993 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
994
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
995 { VK_F1, TRUE, ';', 'T', '^', 'h', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
996 { VK_F2, TRUE, '<', 'U', '_', 'i', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
997 { VK_F3, TRUE, '=', 'V', '`', 'j', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
998 { VK_F4, TRUE, '>', 'W', 'a', 'k', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
999 { VK_F5, TRUE, '?', 'X', 'b', 'l', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1000 { VK_F6, TRUE, '@', 'Y', 'c', 'm', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1001 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1002 { VK_F8, TRUE, 'B', '[', 'e', 'o', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1003 { VK_F9, TRUE, 'C', '\\', 'f', 'p', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1004 { VK_F10, TRUE, 'D', ']', 'g', 'q', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1005 { VK_F11, TRUE, '\205', '\207', '\211', '\213', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1006 { VK_F12, TRUE, '\206', '\210', '\212', '\214', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1008 { VK_HOME, TRUE, 'G', '\302', 'w', '\303', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1009 { VK_UP, TRUE, 'H', '\304', '\305', '\306', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1010 { VK_PRIOR, TRUE, 'I', '\307', '\204', '\310', }, // PgUp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1011 { VK_LEFT, TRUE, 'K', '\311', 's', '\312', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1012 { VK_RIGHT, TRUE, 'M', '\313', 't', '\314', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1013 { VK_END, TRUE, 'O', '\315', 'u', '\316', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1014 { VK_DOWN, TRUE, 'P', '\317', '\320', '\321', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1015 { VK_NEXT, TRUE, 'Q', '\322', 'v', '\323', }, // PgDn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1016 { VK_INSERT,TRUE, 'R', '\324', '\325', '\326', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1017 { VK_DELETE,TRUE, 'S', '\327', '\330', '\331', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1018 { VK_BACK, TRUE, 'x', 'y', 'z', '{', }, // Backspace
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1019
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1020 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, // PrtScrn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1022 # if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1023 // Most people don't have F13-F20, but what the hell...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1024 { VK_F13, TRUE, '\332', '\333', '\334', '\335', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1025 { VK_F14, TRUE, '\336', '\337', '\340', '\341', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1026 { VK_F15, TRUE, '\342', '\343', '\344', '\345', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1027 { VK_F16, TRUE, '\346', '\347', '\350', '\351', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1028 { VK_F17, TRUE, '\352', '\353', '\354', '\355', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1029 { VK_F18, TRUE, '\356', '\357', '\360', '\361', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1030 { VK_F19, TRUE, '\362', '\363', '\364', '\365', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1031 { VK_F20, TRUE, '\366', '\367', '\370', '\371', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1032 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1033 { VK_ADD, TRUE, 'N', 'N', 'N', 'N', }, // keyp '+'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1034 { VK_SUBTRACT, TRUE,'J', 'J', 'J', 'J', }, // keyp '-'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1035 // { VK_DIVIDE, TRUE,'N', 'N', 'N', 'N', }, // keyp '/'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1036 { VK_MULTIPLY, TRUE,'7', '7', '7', '7', }, // keyp '*'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1037
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1038 { VK_NUMPAD0,TRUE, '\332', '\333', '\334', '\335', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1039 { VK_NUMPAD1,TRUE, '\336', '\337', '\340', '\341', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1040 { VK_NUMPAD2,TRUE, '\342', '\343', '\344', '\345', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1041 { VK_NUMPAD3,TRUE, '\346', '\347', '\350', '\351', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1042 { VK_NUMPAD4,TRUE, '\352', '\353', '\354', '\355', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1043 { VK_NUMPAD5,TRUE, '\356', '\357', '\360', '\361', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1044 { VK_NUMPAD6,TRUE, '\362', '\363', '\364', '\365', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1045 { VK_NUMPAD7,TRUE, '\366', '\367', '\370', '\371', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1046 { VK_NUMPAD8,TRUE, '\372', '\373', '\374', '\375', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1047 // Sorry, out of number space! <negri>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1048 { VK_NUMPAD9,TRUE, '\376', '\377', '|', '}', },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1049 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1051
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1052 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1053 * The return code indicates key code size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1054 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1055 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1056 win32_kbd_patch_key(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1057 KEY_EVENT_RECORD *pker)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1058 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1059 UINT uMods = pker->dwControlKeyState;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1060 static int s_iIsDead = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1061 static WORD awAnsiCode[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1062 static BYTE abKeystate[256];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1063
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1064
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1065 if (s_iIsDead == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1066 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1067 pker->uChar.UnicodeChar = (WCHAR) awAnsiCode[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1068 s_iIsDead = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1069 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1070 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1072 // check if it already has a valid unicode character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1073 if (pker->uChar.UnicodeChar != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1074 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1076 CLEAR_FIELD(abKeystate);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1077
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1078 // Clear any pending dead keys
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1079 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1081 if (uMods & SHIFT_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1082 abKeystate[VK_SHIFT] = 0x80;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1083 if (uMods & CAPSLOCK_ON)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1084 abKeystate[VK_CAPITAL] = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1086 if ((uMods & ALT_GR) == ALT_GR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1087 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1088 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1089 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1090 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1091
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1092 s_iIsDead = ToUnicode(pker->wVirtualKeyCode, pker->wVirtualScanCode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1093 abKeystate, awAnsiCode, 2, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1094
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1095 if (s_iIsDead > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1096 pker->uChar.UnicodeChar = (WCHAR) awAnsiCode[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1097
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1098 return s_iIsDead;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1099 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1101 static BOOL g_fJustGotFocus = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1103 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1104 * Decode a KEY_EVENT into one or two keystrokes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1105 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1106 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1107 decode_key_event(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1108 KEY_EVENT_RECORD *pker,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1109 WCHAR *pch,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1110 WCHAR *pch2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1111 int *pmodifiers,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1112 BOOL fDoPost UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1113 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1114 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1115 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1117 *pch = *pch2 = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1118 g_fJustGotFocus = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1119
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1120 // ignore key up events
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1121 if (!pker->bKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1122 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1124 // ignore some keystrokes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1125 switch (pker->wVirtualKeyCode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1126 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1127 // modifiers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1128 case VK_SHIFT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1129 case VK_CONTROL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1130 case VK_MENU: // Alt key
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1131 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1133 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1134 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1135 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1136
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1137 // Shift-TAB
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1138 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1139 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1140 *pch = K_NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1141 *pch2 = '\017';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1142 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1143 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1144
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1145 for (i = ARRAY_LENGTH(VirtKeyMap); --i >= 0; )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1146 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1147 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1148 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1149 *pch = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1150 if ((nModifs & SHIFT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1151 *pch = VirtKeyMap[i].chShift;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1152 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1153 *pch = VirtKeyMap[i].chCtrl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1154 else if ((nModifs & ALT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1155 *pch = VirtKeyMap[i].chAlt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1156
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1157 if (*pch != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1158 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1159 if (VirtKeyMap[i].fAnsiKey)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1160 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1161 *pch2 = *pch;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1162 *pch = K_NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1163 if (pmodifiers)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1164 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1165 if (pker->wVirtualKeyCode >= VK_F1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1166 && pker->wVirtualKeyCode <= VK_F12)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1167 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1168 if ((nModifs & ALT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1169 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1170 *pmodifiers |= MOD_MASK_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1171 if ((nModifs & SHIFT) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1172 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1173 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1174 if ((nModifs & CTRL) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1175 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1176 *pmodifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1177 if ((nModifs & SHIFT) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1178 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1179 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1180 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1181 else if (pker->wVirtualKeyCode >= VK_END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1182 && pker->wVirtualKeyCode <= VK_DOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1183 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1184 // (0x23 - 0x28): VK_END, VK_HOME,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1185 // VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1187 *pmodifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1188 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1189 if ((nModifs & SHIFT) != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1190 && (nModifs & ~SHIFT) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1191 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1192 *pch2 = VirtKeyMap[i].chShift;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1193 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1194 if ((nModifs & CTRL) != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1195 && (nModifs & ~CTRL) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1196 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1197 *pch2 = VirtKeyMap[i].chCtrl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1198 if (pker->wVirtualKeyCode == VK_UP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1199 || pker->wVirtualKeyCode == VK_DOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1200 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1201 *pmodifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1202 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1203 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1204 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1205 if ((nModifs & SHIFT) != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1206 && (nModifs & CTRL) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1207 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1208 *pmodifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1209 *pch2 = VirtKeyMap[i].chShift;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1210 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1211 if ((nModifs & ALT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1212 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1213 *pch2 = VirtKeyMap[i].chAlt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1214 *pmodifiers |= MOD_MASK_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1215 if ((nModifs & ~ALT) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1216 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1217 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1218 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1219 else if ((nModifs & SHIFT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1220 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1221 *pch2 = VirtKeyMap[i].chShift;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1222 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1223 else if ((nModifs & CTRL) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1224 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1225 if (pker->wVirtualKeyCode == VK_UP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1226 || pker->wVirtualKeyCode == VK_DOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1227 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1228 *pmodifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1229 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1230 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1231 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1233 *pch2 = VirtKeyMap[i].chCtrl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1234 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1235 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1236 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1237 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1238 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1239 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1240 *pch2 = VirtKeyMap[i].chAlone;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1241 if ((nModifs & SHIFT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1242 *pmodifiers |= MOD_MASK_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1243 if ((nModifs & CTRL) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1244 *pmodifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1245 if ((nModifs & ALT) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1246 *pmodifiers |= MOD_MASK_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1247 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1248 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1249 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1250
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1251 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1252 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1253 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1254 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1256 i = win32_kbd_patch_key(pker);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1257
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1258 if (i < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1259 *pch = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1260 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1261 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1262 *pch = (i > 0) ? pker->uChar.UnicodeChar : NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1263
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1264 if (pmodifiers != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1265 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1266 // Pass on the ALT key as a modifier, but only when not combined
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1267 // with CTRL (which is ALTGR).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1268 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1269 *pmodifiers |= MOD_MASK_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1270
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1271 // Pass on SHIFT only for special keys, because we don't know when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1272 // it's already included with the character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1273 if ((nModifs & SHIFT) != 0 && *pch <= 0x20)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1274 *pmodifiers |= MOD_MASK_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1275
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1276 // Pass on CTRL only for non-special keys, because we don't know
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1277 // when it's already included with the character. And not when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1278 // combined with ALT (which is ALTGR).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1279 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1280 && *pch >= 0x20 && *pch < 0x80)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1281 *pmodifiers |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1282 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1283 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1285 return (*pch != NUL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1286 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1288 # if defined(FEAT_EVAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1289 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1290 encode_key_event(dict_T *args, INPUT_RECORD *ir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1291 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1292 static int s_dwMods = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1293
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1294 char_u *action = dict_get_string(args, "event", TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1295 if (action && (STRICMP(action, "keydown") == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1296 || STRICMP(action, "keyup") == 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1297 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1298 BOOL isKeyDown = STRICMP(action, "keydown") == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1299 WORD vkCode = dict_get_number_def(args, "keycode", 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1300 if (vkCode <= 0 || vkCode >= 0xFF)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1301 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1302 semsg(_(e_invalid_argument_nr), (long)vkCode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1303 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1304 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1306 ir->EventType = KEY_EVENT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1307 KEY_EVENT_RECORD ker;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1308 ZeroMemory(&ker, sizeof(ker));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1309 ker.bKeyDown = isKeyDown;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1310 ker.wRepeatCount = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1311 ker.wVirtualScanCode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1312 ker.dwControlKeyState = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1313 int mods = (int)dict_get_number(args, "modifiers");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1314 // Encode the win32 console key modifiers from Vim keyboard modifiers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1315 if (mods)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1316 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1317 // If "modifiers" is explicitly set in the args, then we reset any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1318 // remembered modifier key state that may have been set from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1319 // earlier mod-key-down events, even if they are not yet unset by
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1320 // earlier mod-key-up events.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1321 s_dwMods = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1322 if (mods & MOD_MASK_SHIFT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1323 ker.dwControlKeyState |= SHIFT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1324 if (mods & MOD_MASK_CTRL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1325 ker.dwControlKeyState |= LEFT_CTRL_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1326 if (mods & MOD_MASK_ALT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1327 ker.dwControlKeyState |= LEFT_ALT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1328 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1329
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1330 if (vkCode == VK_LSHIFT || vkCode == VK_RSHIFT || vkCode == VK_SHIFT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1331 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1332 if (isKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1333 s_dwMods |= SHIFT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1334 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1335 s_dwMods &= ~SHIFT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1336 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1337 else if (vkCode == VK_LCONTROL || vkCode == VK_CONTROL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1338 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1339 if (isKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1340 s_dwMods |= LEFT_CTRL_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1341 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1342 s_dwMods &= ~LEFT_CTRL_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1343 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1344 else if (vkCode == VK_RCONTROL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1345 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1346 if (isKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1347 s_dwMods |= RIGHT_CTRL_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1348 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1349 s_dwMods &= ~RIGHT_CTRL_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1350 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1351 else if (vkCode == VK_LMENU || vkCode == VK_MENU)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1352 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1353 if (isKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1354 s_dwMods |= LEFT_ALT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1355 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1356 s_dwMods &= ~LEFT_ALT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1357 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1358 else if (vkCode == VK_RMENU)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1359 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1360 if (isKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1361 s_dwMods |= RIGHT_ALT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1362 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1363 s_dwMods &= ~RIGHT_ALT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1364 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1365 ker.dwControlKeyState |= s_dwMods;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1366 ker.wVirtualKeyCode = vkCode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1367 ker.uChar.UnicodeChar = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1368 ir->Event.KeyEvent = ker;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1369 vim_free(action);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1370 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1371 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1372 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1373 if (action == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1374 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1375 semsg(_(e_missing_argument_str), "event");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1376 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1377 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1378 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1379 semsg(_(e_invalid_value_for_argument_str_str), "event", action);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1380 vim_free(action);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1381 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1382 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1383 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1384 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1385 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1386 # endif // FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1387 #endif // !FEAT_GUI_MSWIN || VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1388
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1390 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1391 * For the GUI the mouse handling is in gui_w32.c.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1392 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1393 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1394 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1395 mch_setmouse(int on UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1396 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1397 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1398 #else // !FEAT_GUI_MSWIN || VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1399 static int g_fMouseAvail = FALSE; // mouse present
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1400 static int g_fMouseActive = FALSE; // mouse enabled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1401 static int g_nMouseClick = -1; // mouse status
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1402 static int g_xMouse; // mouse x coordinate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1403 static int g_yMouse; // mouse y coordinate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1404 static DWORD g_cmodein = 0; // Original console input mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1405 static DWORD g_cmodeout = 0; // Original console output mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1406
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1407 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1408 * Enable or disable mouse input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1409 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1410 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1411 mch_setmouse(int on)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1412 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1413 DWORD cmodein;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1414
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1415 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1416 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1417 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1418 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1419 if (!g_fMouseAvail)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1420 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1422 g_fMouseActive = on;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1423 GetConsoleMode(g_hConIn, &cmodein);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1424
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1425 if (g_fMouseActive)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1426 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1427 cmodein |= ENABLE_MOUSE_INPUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1428 cmodein &= ~ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1429 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1430 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1431 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1432 cmodein &= ~ENABLE_MOUSE_INPUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1433 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1434 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1435
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1436 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1437 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1438
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1440 # if defined(FEAT_BEVAL_TERM) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1441 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1442 * Called when 'balloonevalterm' changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1443 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1444 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1445 mch_bevalterm_changed(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1446 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1447 mch_setmouse(g_fMouseActive);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1448 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1449 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1451 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1452 * Win32 console mouse scroll event handler.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1453 * Console version of the _OnMouseWheel() function in gui_w32.c
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1454 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1455 * This encodes the mouse scroll direction and keyboard modifiers into
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1456 * g_nMouseClick, and the mouse position into g_xMouse and g_yMouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1457 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1458 * The direction of the scroll is decoded from two fields of the win32 console
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1459 * mouse event record;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1460 * 1. The orientation - vertical or horizontal flag - from dwEventFlags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1461 * 2. The sign - positive or negative (aka delta flag) - from dwButtonState
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1462 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1463 * When scroll orientation is HORIZONTAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1464 * - If the high word of the dwButtonState member contains a positive
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1465 * value, the wheel was rotated to the right.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1466 * - Otherwise, the wheel was rotated to the left.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1467 * When scroll orientation is VERTICAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1468 * - If the high word of the dwButtonState member contains a positive value,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1469 * the wheel was rotated forward, away from the user.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1470 * - Otherwise, the wheel was rotated backward, toward the user.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1471 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1472 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1473 decode_mouse_wheel(MOUSE_EVENT_RECORD *pmer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1474 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1475 int horizontal = (pmer->dwEventFlags == MOUSE_HWHEELED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1476 int zDelta = pmer->dwButtonState;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1478 g_xMouse = pmer->dwMousePosition.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1479 g_yMouse = pmer->dwMousePosition.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1481 # ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1482 int lcol = g_xMouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1483 int lrow = g_yMouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1484 win_T *wp = mouse_find_win(&lrow, &lcol, FIND_POPUP);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1485 if (wp != NULL && popup_is_popup(wp))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1486 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1487 g_nMouseClick = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1488 cmdarg_T cap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1489 oparg_T oa;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1490 CLEAR_FIELD(cap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1491 clear_oparg(&oa);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1492 cap.oap = &oa;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1493 if (horizontal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1494 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1495 cap.arg = zDelta < 0 ? MSCR_LEFT : MSCR_RIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1496 cap.cmdchar = zDelta < 0 ? K_MOUSELEFT : K_MOUSERIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1497 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1498 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1499 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1500 cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1501 cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1502 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1503
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1504 // Mouse hovers over popup window, scroll it if possible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1505 mouse_row = wp->w_winrow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1506 mouse_col = wp->w_wincol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1507 nv_mousescroll(&cap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1508 update_screen(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1509 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1510 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1511 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1512 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1513 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1514 mouse_col = g_xMouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1515 mouse_row = g_yMouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1516
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1517 char_u modifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1518 char_u direction = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1519
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1520 // Decode the direction into an event that Vim can process
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1521 if (horizontal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1522 direction = zDelta >= 0 ? KE_MOUSELEFT : KE_MOUSERIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1523 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1524 direction = zDelta >= 0 ? KE_MOUSEDOWN : KE_MOUSEUP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1525
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1526 // Decode the win32 console key modifiers into Vim mouse modifiers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1527 if (pmer->dwControlKeyState & SHIFT_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1528 modifiers |= MOD_MASK_SHIFT; // MOUSE_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1529 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1530 modifiers |= MOD_MASK_CTRL; // MOUSE_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1531 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1532 modifiers |= MOD_MASK_ALT; // MOUSE_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1533
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1534 // add (bitwise or) the scroll direction and the key modifier chars
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1535 // together.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1536 g_nMouseClick = ((direction << 8) | modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1538 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1539 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1540
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1541 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1542 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1543 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1544 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1545 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1546 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1547 * and we return the mouse position in g_xMouse and g_yMouse.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1548 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1549 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1550 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1551 * by MOUSE_LEFT, _MIDDLE, or _RIGHT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1552 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1553 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1554 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, ....
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1555 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1556 * Windows will send us MOUSE_MOVED notifications whenever the mouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1557 * moves, even if it stays within the same character cell. We ignore
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1558 * all MOUSE_MOVED messages if the position hasn't really changed, and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1559 * we ignore all MOUSE_MOVED messages where no button is held down (i.e.,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1560 * we're only interested in MOUSE_DRAG).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1561 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1562 * All of this is complicated by the code that fakes MOUSE_MIDDLE on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1563 * 2-button mouses by pressing the left & right buttons simultaneously.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1564 * In practice, it's almost impossible to click both at the same time,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1565 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1566 * in such cases, if the user is clicking quickly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1567 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1568 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1569 decode_mouse_event(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1570 MOUSE_EVENT_RECORD *pmer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1571 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1572 static int s_nOldButton = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1573 static int s_nOldMouseClick = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1574 static int s_xOldMouse = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1575 static int s_yOldMouse = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1576 static linenr_T s_old_topline = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1577 # ifdef FEAT_DIFF
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1578 static int s_old_topfill = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1579 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1580 static int s_cClicks = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1581 static BOOL s_fReleased = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1582 static DWORD s_dwLastClickTime = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1583 static BOOL s_fNextIsMiddle = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1584
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1585 static DWORD cButtons = 0; // number of buttons supported
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1587 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1588 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1589 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1590 const DWORD LEFT_RIGHT = LEFT | RIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1591
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1592 int nButton;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1594 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1595 cButtons = 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1597 if (!g_fMouseAvail || !g_fMouseActive)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1598 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1599 g_nMouseClick = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1600 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1602
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1603 // get a spurious MOUSE_EVENT immediately after receiving focus; ignore
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1604 if (g_fJustGotFocus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1605 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1606 g_fJustGotFocus = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1607 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1608 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1609
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1610 // If there is an unprocessed mouse click drop this one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1611 if (g_nMouseClick != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1612 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1614 if (pmer->dwEventFlags == MOUSE_WHEELED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1615 || pmer->dwEventFlags == MOUSE_HWHEELED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1616 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1617 decode_mouse_wheel(pmer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1618 return TRUE; // we now should have a mouse scroll in g_nMouseClick
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1619 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1621 nButton = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1622 g_xMouse = pmer->dwMousePosition.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1623 g_yMouse = pmer->dwMousePosition.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1624
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1625 if (pmer->dwEventFlags == MOUSE_MOVED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1626 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1627 // Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1628 // events even when the mouse moves only within a char cell.)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1629 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1630 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1631 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1632
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1633 // If no buttons are pressed...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1634 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1635 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1636 nButton = MOUSE_RELEASE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1637
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1638 // If the last thing returned was MOUSE_RELEASE, ignore this
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1639 if (s_fReleased)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1640 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1641 # ifdef FEAT_BEVAL_TERM
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1642 // do return mouse move events when we want them
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1643 if (p_bevalterm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1644 nButton = MOUSE_DRAG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1645 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1646 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1647 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1648 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1649
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1650 s_fReleased = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1651 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1652 else // one or more buttons pressed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1653 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1654 // on a 2-button mouse, hold down left and right buttons
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1655 // simultaneously to get MIDDLE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1656
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1657 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1658 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1659 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1661 // if either left or right button only is pressed, see if the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1662 // next mouse event has both of them pressed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1663 if (dwLR == LEFT || dwLR == RIGHT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1664 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1665 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1666 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1667 // wait a short time for next input event
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1668 if (WaitForSingleObject(g_hConIn, p_mouset / 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1669 != WAIT_OBJECT_0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1670 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1671 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1672 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1673 DWORD cRecords = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1674 INPUT_RECORD ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1675 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1676
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1677 peek_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1679 if (cRecords == 0 || ir.EventType != MOUSE_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1680 || !(pmer2->dwButtonState & LEFT_RIGHT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1681 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1682 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1683 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1684 if (pmer2->dwEventFlags != MOUSE_MOVED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1685 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1686 read_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1687
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1688 return decode_mouse_event(pmer2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1689 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1690 else if (s_xOldMouse == pmer2->dwMousePosition.X &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1691 s_yOldMouse == pmer2->dwMousePosition.Y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1692 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1693 // throw away spurious mouse move
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1694 read_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1696 // are there any more mouse events in queue?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1697 peek_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1698
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1699 if (cRecords==0 || ir.EventType != MOUSE_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1700 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1701 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1702 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1703 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1704 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1705 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1706 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1707 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1708 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1709
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1710 if (s_fNextIsMiddle)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1711 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1712 nButton = (pmer->dwEventFlags == MOUSE_MOVED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1713 ? MOUSE_DRAG : MOUSE_MIDDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1714 s_fNextIsMiddle = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1715 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1716 else if (cButtons == 2 &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1717 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1718 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1719 nButton = MOUSE_MIDDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1720
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1721 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1722 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1723 s_fNextIsMiddle = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1724 nButton = MOUSE_RELEASE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1725 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1726 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1727 else if ((pmer->dwButtonState & LEFT) == LEFT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1728 nButton = MOUSE_LEFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1729 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1730 nButton = MOUSE_MIDDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1731 else if ((pmer->dwButtonState & RIGHT) == RIGHT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1732 nButton = MOUSE_RIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1733
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1734 if (! s_fReleased && ! s_fNextIsMiddle
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1735 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1736 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1737
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1738 s_fReleased = s_fNextIsMiddle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1739 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1741 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1742 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1743 // button pressed or released, without mouse moving
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1744 if (nButton != -1 && nButton != MOUSE_RELEASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1745 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1746 DWORD dwCurrentTime = GetTickCount();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1748 if (s_xOldMouse != g_xMouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1749 || s_yOldMouse != g_yMouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1750 || s_nOldButton != nButton
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1751 || s_old_topline != curwin->w_topline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1752 # ifdef FEAT_DIFF
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1753 || s_old_topfill != curwin->w_topfill
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1754 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1755 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1756 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1757 s_cClicks = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1758 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1759 else if (++s_cClicks > 4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1760 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1761 s_cClicks = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1762 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1763
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1764 s_dwLastClickTime = dwCurrentTime;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1765 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1766 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1767 else if (pmer->dwEventFlags == MOUSE_MOVED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1768 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1769 if (nButton != -1 && nButton != MOUSE_RELEASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1770 nButton = MOUSE_DRAG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1771
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1772 s_cClicks = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1773 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1774
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1775 if (nButton == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1776 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1778 if (nButton != MOUSE_RELEASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1779 s_nOldButton = nButton;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1781 g_nMouseClick = nButton;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1782
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1783 if (pmer->dwControlKeyState & SHIFT_PRESSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1784 g_nMouseClick |= MOUSE_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1785 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1786 g_nMouseClick |= MOUSE_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1787 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1788 g_nMouseClick |= MOUSE_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1789
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1790 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1791 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1793 // only pass on interesting (i.e., different) mouse events
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1794 if (s_xOldMouse == g_xMouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1795 && s_yOldMouse == g_yMouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1796 && s_nOldMouseClick == g_nMouseClick)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1797 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1798 g_nMouseClick = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1799 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1800 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1801
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1802 s_xOldMouse = g_xMouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1803 s_yOldMouse = g_yMouse;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1804 s_old_topline = curwin->w_topline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1805 # ifdef FEAT_DIFF
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1806 s_old_topfill = curwin->w_topfill;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1807 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1808 s_nOldMouseClick = g_nMouseClick;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1809
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1810 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1811 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1812
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1813 # ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1814 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1815 encode_mouse_event(dict_T *args, INPUT_RECORD *ir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1816 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1817 int button;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1818 int row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1819 int col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1820 int repeated_click;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1821 int_u mods = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1822 int move;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1823
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1824 if (!dict_has_key(args, "row") || !dict_has_key(args, "col"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1825 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1826
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1827 // Note: "move" is optional, requires fewer arguments
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1828 move = (int)dict_get_bool(args, "move", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1829 if (!move && (!dict_has_key(args, "button")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1830 || !dict_has_key(args, "multiclick")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1831 || !dict_has_key(args, "modifiers")))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1832 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1833
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1834 row = (int)dict_get_number(args, "row") - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1835 col = (int)dict_get_number(args, "col") - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1836
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1837 ir->EventType = MOUSE_EVENT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1838 MOUSE_EVENT_RECORD mer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1839 ZeroMemory(&mer, sizeof(mer));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1840 mer.dwMousePosition.X = col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1841 mer.dwMousePosition.Y = row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1843 if (move)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1844 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1845 mer.dwButtonState = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1846 mer.dwEventFlags = MOUSE_MOVED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1847 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1848 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1849 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1850 button = (int)dict_get_number(args, "button");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1851 repeated_click = (int)dict_get_number(args, "multiclick");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1852 mods = (int)dict_get_number(args, "modifiers");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1853 // Reset the scroll values to known values.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1854 // XXX: Remove this when/if the scroll step is made configurable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1855 mouse_set_hor_scroll_step(6);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1856 mouse_set_vert_scroll_step(3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1857
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1858 switch (button)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1859 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1860 case MOUSE_LEFT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1861 mer.dwButtonState = FROM_LEFT_1ST_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1862 mer.dwEventFlags = repeated_click == 1 ? DOUBLE_CLICK : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1863 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1864 case MOUSE_MIDDLE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1865 mer.dwButtonState = FROM_LEFT_2ND_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1866 mer.dwEventFlags = repeated_click == 1 ? DOUBLE_CLICK : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1867 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1868 case MOUSE_RIGHT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1869 mer.dwButtonState = RIGHTMOST_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1870 mer.dwEventFlags = repeated_click == 1 ? DOUBLE_CLICK : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1871 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1872 case MOUSE_RELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1873 // umm? Assume Left Release?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1874 mer.dwEventFlags = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1875
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1876 case MOUSE_MOVE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1877 mer.dwButtonState = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1878 mer.dwEventFlags = MOUSE_MOVED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1879 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1880 case MOUSE_X1:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1881 mer.dwButtonState = FROM_LEFT_3RD_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1882 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1883 case MOUSE_X2:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1884 mer.dwButtonState = FROM_LEFT_4TH_BUTTON_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1885 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1886 case MOUSE_4: // KE_MOUSEDOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1887 mer.dwButtonState = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1888 mer.dwEventFlags = MOUSE_WHEELED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1889 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1890 case MOUSE_5: // KE_MOUSEUP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1891 mer.dwButtonState = +1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1892 mer.dwEventFlags = MOUSE_WHEELED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1893 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1894 case MOUSE_6: // KE_MOUSELEFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1895 mer.dwButtonState = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1896 mer.dwEventFlags = MOUSE_HWHEELED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1897 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1898 case MOUSE_7: // KE_MOUSERIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1899 mer.dwButtonState = +1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1900 mer.dwEventFlags = MOUSE_HWHEELED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1901 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1902 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1903 semsg(_(e_invalid_argument_str), "button");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1904 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1905 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1906 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1907
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1908 mer.dwControlKeyState = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1909 if (mods != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1910 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1911 // Encode the win32 console key modifiers from Vim MOUSE modifiers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1912 if (mods & MOUSE_SHIFT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1913 mer.dwControlKeyState |= SHIFT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1914 if (mods & MOUSE_CTRL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1915 mer.dwControlKeyState |= LEFT_CTRL_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1916 if (mods & MOUSE_ALT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1917 mer.dwControlKeyState |= LEFT_ALT_PRESSED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1918 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1919 ir->Event.MouseEvent = mer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1920 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1921 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1922 # endif // FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1923
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1924 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1925 write_input_record_buffer(INPUT_RECORD* irEvents, int nLength)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1926 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1927 int nCount = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1928 while (nCount < nLength)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1929 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1930 input_record_buffer.length++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1931 input_record_buffer_node_T *event_node =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1932 malloc(sizeof(input_record_buffer_node_T));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1933 event_node->ir = irEvents[nCount++];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1934 event_node->next = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1935 if (input_record_buffer.tail == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1936 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1937 input_record_buffer.head = event_node;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1938 input_record_buffer.tail = event_node;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1939 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1940 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1941 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1942 input_record_buffer.tail->next = event_node;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1943 input_record_buffer.tail = input_record_buffer.tail->next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1944 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1945 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1946 return nCount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1947 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1948
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1949 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1950 read_input_record_buffer(INPUT_RECORD* irEvents, int nMaxLength)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1951 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1952 int nCount = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1953 while (nCount < nMaxLength && input_record_buffer.head != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1954 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1955 input_record_buffer.length--;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1956 input_record_buffer_node_T *pop_head = input_record_buffer.head;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1957 irEvents[nCount++] = pop_head->ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1958 input_record_buffer.head = pop_head->next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1959 vim_free(pop_head);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1960 if (input_record_buffer.length == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1961 input_record_buffer.tail = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1962 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1963 return nCount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1964 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1965 #endif // !FEAT_GUI_MSWIN || VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1966
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1967 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1968 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1969 * The 'test_mswin_event' function is for testing Vim's low-level handling of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1970 * user input events. ie, this manages the encoding of INPUT_RECORD events
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1971 * so that we have a way to test how Vim decodes INPUT_RECORD events in Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1972 * consoles.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1973 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1974 * The 'test_mswin_event' function is based on 'test_gui_event'. In fact, when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1975 * the Windows GUI is running, the arguments; 'event' and 'args', are the same.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1976 * So, it acts as an alias for 'test_gui_event' for the Windows GUI.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1977 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1978 * When the Windows console is running, the arguments; 'event' and 'args', are
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1979 * a subset of what 'test_gui_event' handles, ie, only "key" and "mouse"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1980 * events are encoded as INPUT_RECORD events.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1981 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1982 * Note: INPUT_RECORDs are only used by the Windows console, not the GUI. The
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1983 * GUI sends MSG structs instead.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1984 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1985 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1986 test_mswin_event(char_u *event, dict_T *args)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1987 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1988 int lpEventsWritten = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1990 # if defined(VIMDLL) || defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1991 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1992 return test_gui_w32_sendevent(event, args);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1993 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1994
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1995 # if defined(VIMDLL) || !defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1997 // Currently implemented event record types are; KEY_EVENT and MOUSE_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1998 // Potentially could also implement: FOCUS_EVENT and WINDOW_BUFFER_SIZE_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
1999 // Maybe also: MENU_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2001 INPUT_RECORD ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2002 BOOL input_encoded = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2003 BOOL execute = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2004 if (STRCMP(event, "key") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2005 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2006 execute = dict_get_bool(args, "execute", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2007 if (dict_has_key(args, "event"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2008 input_encoded = encode_key_event(args, &ir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2009 else if (!execute)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2010 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2011 semsg(_(e_missing_argument_str), "event");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2012 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2013 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2014 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2015 else if (STRCMP(event, "mouse") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2016 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2017 execute = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2018 input_encoded = encode_mouse_event(args, &ir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2019 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2020 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2021 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2022 semsg(_(e_invalid_value_for_argument_str_str), "event", event);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2023 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2024 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2026 // Ideally, WriteConsoleInput would be used to inject these low-level
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2027 // events. But, this doesn't work well in the CI test environment. So
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2028 // implementing an input_record_buffer instead.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2029 if (input_encoded)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2030 lpEventsWritten = write_input_record_buffer(&ir, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2031
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2032 // Set flags to execute the event, ie. like feedkeys mode X.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2033 if (execute)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2035 int save_msg_scroll = msg_scroll;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2036 // Avoid a 1 second delay when the keys start Insert mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2037 msg_scroll = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2038 ch_log(NULL, "test_mswin_event() executing");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2039 exec_normal(TRUE, TRUE, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2040 msg_scroll |= save_msg_scroll;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2041 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2043 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2044 return lpEventsWritten;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2045 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2046 #endif // FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2047
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2048 #ifdef MCH_CURSOR_SHAPE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2049 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2050 * Set the shape of the cursor.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2051 * 'thickness' can be from 1 (thin) to 99 (block)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2052 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2053 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2054 mch_set_cursor_shape(int thickness)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2055 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2056 if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2057 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2058 if (*T_CSI == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2059 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2060 // If 't_SI' is not set, use the default cursor styles.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2061 if (thickness < 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2062 vtp_printf("\033[3 q"); // underline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2063 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2064 vtp_printf("\033[0 q"); // default
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2065 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2066 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2067 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2068 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2069 CONSOLE_CURSOR_INFO ConsoleCursorInfo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2070 ConsoleCursorInfo.dwSize = thickness;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2071 ConsoleCursorInfo.bVisible = s_cursor_visible;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2073 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2074 if (s_cursor_visible)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2075 SetConsoleCursorPosition(g_hConOut, g_coord);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2076 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2077 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2078
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2079 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2080 mch_update_cursor(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2081 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2082 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2083 int thickness;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2084
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2085 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2086 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2087 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2088 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2089
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2090 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2091 * How the cursor is drawn depends on the current mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2092 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2093 idx = get_shape_idx(FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2094
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2095 if (shape_table[idx].shape == SHAPE_BLOCK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2096 thickness = 99; // 100 doesn't work on W95
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2097 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2098 thickness = shape_table[idx].percentage;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2099 mch_set_cursor_shape(thickness);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2100 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2101 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2103 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2104 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2105 * Handle FOCUS_EVENT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2106 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2107 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2108 handle_focus_event(INPUT_RECORD ir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2109 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2110 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2111 ui_focus_change((int)g_fJustGotFocus);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2112 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2114 static void ResizeConBuf(HANDLE hConsole, COORD coordScreen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2115
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2116 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2117 * Wait until console input from keyboard or mouse is available,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2118 * or the time is up.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2119 * When "ignore_input" is TRUE even wait when input is available.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2120 * Return TRUE if something is available FALSE if not.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2121 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2122 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2123 WaitForChar(long msec, int ignore_input)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2124 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2125 DWORD dwNow = 0, dwEndTime = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2126 INPUT_RECORD ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2127 DWORD cRecords;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2128 WCHAR ch, ch2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2129 # ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2130 int tb_change_cnt = typebuf.tb_change_cnt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2131 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2133 if (msec > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2134 // Wait until the specified time has elapsed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2135 dwEndTime = GetTickCount() + msec;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2136 else if (msec < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2137 // Wait forever.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2138 dwEndTime = INFINITE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2139
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2140 // We need to loop until the end of the time period, because
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2141 // we might get multiple unusable mouse events in that time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2142 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2143 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2144 // Only process messages when waiting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2145 if (msec != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2146 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2147 # ifdef MESSAGE_QUEUE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2148 parse_queued_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2149 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2150 # ifdef FEAT_MZSCHEME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2151 mzvim_check_threads();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2152 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2153 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2154 serverProcessPendingMessages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2155 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2156 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2157
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2158 if (g_nMouseClick != -1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2159 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2160 || (!ignore_input && input_available())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2161 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2162 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2163 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2165 if (msec > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2166 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2167 // If the specified wait time has passed, return. Beware that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2168 // GetTickCount() may wrap around (overflow).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2169 dwNow = GetTickCount();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2170 if ((int)(dwNow - dwEndTime) >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2171 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2172 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2173 if (msec != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2174 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2175 DWORD dwWaitTime = dwEndTime - dwNow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2177 // Don't wait for more than 11 msec to avoid dropping characters,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2178 // check channel while waiting for input and handle a callback from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2179 // 'balloonexpr'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2180 if (dwWaitTime > 11)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2181 dwWaitTime = 11;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2182
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2183 # ifdef FEAT_MZSCHEME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2184 if (mzthreads_allowed() && p_mzq > 0 && (long)dwWaitTime > p_mzq)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2185 dwWaitTime = p_mzq; // don't wait longer than 'mzquantum'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2186 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2187 # ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2188 // When waiting very briefly don't trigger timers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2189 if (dwWaitTime > 10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2191 long due_time;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2193 // Trigger timers and then get the time in msec until the next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2194 // one is due. Wait up to that time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2195 due_time = check_due_timer();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2196 if (typebuf.tb_change_cnt != tb_change_cnt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2197 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2198 // timer may have used feedkeys().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2199 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2200 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2201 if (due_time > 0 && dwWaitTime > (DWORD)due_time)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2202 dwWaitTime = due_time;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2203 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2204 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2205 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2206 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2207 // Wait for either an event on the console input or a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2208 // message in the client-server window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2209 msg_wait_for_multiple_objects(1, &g_hConIn, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2210 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2211 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2212 wait_for_single_object(g_hConIn, dwWaitTime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2213 != WAIT_OBJECT_0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2214 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2215 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2216 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2217 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2219 cRecords = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2220 peek_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2221
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2222 # ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2223 // May have to redraw if the cursor ends up in the wrong place.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2224 // Only when not peeking.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2225 if (State == MODE_CMDLINE && msg_row == Rows - 1 && msec != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2226 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2227 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2228
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2229 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2230 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2231 if (csbi.dwCursorPosition.Y != msg_row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2233 // The screen is now messed up, must redraw the command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2234 // line and later all the windows.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2235 redraw_all_later(UPD_CLEAR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2236 compute_cmdrow();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2237 redrawcmd();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2238 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2239 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2240 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2241 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2243 if (cRecords > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2244 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2245 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2246 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2247 # ifdef FEAT_MBYTE_IME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2248 // Windows IME sends two '\n's with only one 'ENTER'. First:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2249 // wVirtualKeyCode == 13. second: wVirtualKeyCode == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2250 if (ir.Event.KeyEvent.uChar.UnicodeChar == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2251 && ir.Event.KeyEvent.wVirtualKeyCode == 13)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2252 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2253 read_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2254 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2255 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2256 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2257 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2258 NULL, FALSE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2259 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2260 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2261
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2262 read_console_input(g_hConIn, &ir, 1, &cRecords);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2263
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2264 if (ir.EventType == FOCUS_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2265 handle_focus_event(ir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2266 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2267 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2268 COORD dwSize = ir.Event.WindowBufferSizeEvent.dwSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2270 // Only call shell_resized() when the size actually changed to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2271 // avoid the screen is cleared.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2272 if (dwSize.X != Columns || dwSize.Y != Rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2273 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2274 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2275 GetConsoleScreenBufferInfo(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2276 dwSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2277 dwSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2278 if (dwSize.X != Columns || dwSize.Y != Rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2279 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2280 ResizeConBuf(g_hConOut, dwSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2281 shell_resized();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2282 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2283 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2284 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2285 else if (ir.EventType == MOUSE_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2286 && decode_mouse_event(&ir.Event.MouseEvent))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2287 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2288 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2289 else if (msec == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2290 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2291 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2292
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2293 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2294 // Something might have been received while we were waiting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2295 if (input_available())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2296 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2297 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2298
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2299 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2300 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2302 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2303 * return non-zero if a character is available
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2304 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2305 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2306 mch_char_avail(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2307 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2308 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2309 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2310 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2311 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2312 return WaitForChar(0L, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2313 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2314
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2315 # if defined(FEAT_TERMINAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2316 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2317 * Check for any pending input or messages.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2318 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2319 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2320 mch_check_messages(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2321 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2322 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2323 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2324 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2325 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2326 return WaitForChar(0L, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2327 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2328 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2329
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2330 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2331 * Create the console input. Used when reading stdin doesn't work.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2332 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2333 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2334 create_conin(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2335 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2336 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2337 FILE_SHARE_READ|FILE_SHARE_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2338 (LPSECURITY_ATTRIBUTES) NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2339 OPEN_EXISTING, 0, (HANDLE)NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2340 did_create_conin = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2341 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2342
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2343 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2344 * Get a keystroke or a mouse event, use a blocking wait.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2345 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2346 static WCHAR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2347 tgetch(int *pmodifiers, WCHAR *pch2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2348 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2349 WCHAR ch;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2351 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2352 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2353 INPUT_RECORD ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2354 DWORD cRecords = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2355
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2356 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2357 (void)WaitForChar(-1L, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2358 if (input_available())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2359 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2360 if (g_nMouseClick != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2361 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2362 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2363 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2364 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2365 if (did_create_conin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2366 read_error_exit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2367 create_conin();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2368 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2371 if (ir.EventType == KEY_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2372 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2373 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2374 pmodifiers, TRUE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2375 return ch;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2376 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2377 else if (ir.EventType == FOCUS_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2378 handle_focus_event(ir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2379 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2380 shell_resized();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2381 else if (ir.EventType == MOUSE_EVENT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2382 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2383 if (decode_mouse_event(&ir.Event.MouseEvent))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2384 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2385 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2386 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2387 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2388 #endif // !FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2391 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2392 * mch_inchar(): low-level input function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2393 * Get one or more characters from the keyboard or the mouse.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2394 * If time == 0, do not wait for characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2395 * If time == n, wait a short time for characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2396 * If time == -1, wait forever for characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2397 * Returns the number of characters read into buf.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2398 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2399 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2400 mch_inchar(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2401 char_u *buf UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2402 int maxlen UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2403 long time UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2404 int tb_change_cnt UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2405 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2406 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2407
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2408 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2409 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2410 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2411 // Extra space for maximum three CSIs. E.g. U+1B6DB -> 0xF0 0x9B 0x9B 0x9B.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2412 # define TYPEAHEADSPACE 6
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2413 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2414 # define TYPEAHEADSPACE 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2415 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2416 # define TYPEAHEADLEN (20 + TYPEAHEADSPACE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2417 static char_u typeahead[TYPEAHEADLEN]; // previously typed bytes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2418 static int typeaheadlen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2419
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2420 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2421 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2422 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2423 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2424
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2425 // First use any typeahead that was kept because "buf" was too small.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2426 if (typeaheadlen > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2427 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2429 if (time >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2430 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2431 if (!WaitForChar(time, FALSE)) // no character available
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2432 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2433 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2434 else // time == -1, wait forever
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2435 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2436 mch_set_winsize_now(); // Allow winsize changes from now on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2437
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2438 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2439 * If there is no character available within 2 seconds (default)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2440 * write the autoscript file to disk. Or cause the CursorHold event
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2441 * to be triggered.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2442 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2443 if (!WaitForChar(p_ut, FALSE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2444 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2445 if (trigger_cursorhold() && maxlen >= 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2446 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2447 buf[0] = K_SPECIAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2448 buf[1] = KS_EXTRA;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2449 buf[2] = (int)KE_CURSORHOLD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2450 return 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2451 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2452 before_blocking();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2453 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2454 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2456 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2457 * Try to read as many characters as there are, until the buffer is full.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2458 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2459
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2460 // we will get at least one key. Get more if they are available.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2461 g_fCBrkPressed = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2463 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2464 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2465 fputc('[', fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2466 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2468 // Keep looping until there is something in the typeahead buffer and more
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2469 // to get and still room in the buffer (up to two bytes for a char and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2470 // three bytes for a modifier).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2471 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2472 && typeaheadlen + 5 + TYPEAHEADSPACE <= TYPEAHEADLEN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2473 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2474 if (typebuf_changed(tb_change_cnt))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2475 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2476 // "buf" may be invalid now if a client put something in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2477 // typeahead buffer and "buf" is in the typeahead buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2478 typeaheadlen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2479 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2480 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2481 if (g_nMouseClick != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2482 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2483 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2484 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2485 fprintf(fdDump, "{%02x @ %d, %d}",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2486 g_nMouseClick, g_xMouse, g_yMouse);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2487 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2488 char_u modifiers = ((char_u *)(&g_nMouseClick))[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2489 char_u scroll_dir = ((char_u *)(&g_nMouseClick))[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2491 if (scroll_dir == KE_MOUSEDOWN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2492 || scroll_dir == KE_MOUSEUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2493 || scroll_dir == KE_MOUSELEFT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2494 || scroll_dir == KE_MOUSERIGHT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2495 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2496 if (modifiers > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2497 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2498 // use K_SPECIAL instead of CSI to make mappings work
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2499 typeahead[typeaheadlen++] = K_SPECIAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2500 typeahead[typeaheadlen++] = KS_MODIFIER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2501 typeahead[typeaheadlen++] = modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2502 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2503 typeahead[typeaheadlen++] = CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2504 typeahead[typeaheadlen++] = KS_EXTRA;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2505 typeahead[typeaheadlen++] = scroll_dir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2506 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2507 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2508 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2509 typeahead[typeaheadlen++] = ESC + 128;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2510 typeahead[typeaheadlen++] = 'M';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2511 typeahead[typeaheadlen++] = g_nMouseClick;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2512 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2514 // Pass the pointer coordinates of the mouse event in 2 bytes,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2515 // allowing for > 223 columns. Both for click and scroll events.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2516 // This is the same as what is used for the GUI.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2517 typeahead[typeaheadlen++] = (char_u)(g_xMouse / 128 + ' ' + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2518 typeahead[typeaheadlen++] = (char_u)(g_xMouse % 128 + ' ' + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2519 typeahead[typeaheadlen++] = (char_u)(g_yMouse / 128 + ' ' + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2520 typeahead[typeaheadlen++] = (char_u)(g_yMouse % 128 + ' ' + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2522 g_nMouseClick = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2523 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2524 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2525 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2526 WCHAR ch2 = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2527 int modifiers = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2528
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2529 c = tgetch(&modifiers, &ch2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2530
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2531 c = simplify_key(c, &modifiers);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2533 // Some chars need adjustment when the Ctrl modifier is used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2534 ++no_reduce_keys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2535 c = may_adjust_key_for_ctrl(modifiers, c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2536 --no_reduce_keys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2538 // remove the SHIFT modifier for keys where it's already included,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2539 // e.g., '(' and '*'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2540 modifiers = may_remove_shift_modifier(modifiers, c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2542 if (typebuf_changed(tb_change_cnt))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2543 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2544 // "buf" may be invalid now if a client put something in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2545 // typeahead buffer and "buf" is in the typeahead buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2546 typeaheadlen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2547 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2548 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2550 if (c == Ctrl_C && ctrl_c_interrupts)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2551 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2552 # if defined(FEAT_CLIENTSERVER)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2553 trash_input_buf();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2554 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2555 got_int = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2556 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2557
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2558 if (g_nMouseClick == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2560 int n = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2561
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2562 if (ch2 == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2563 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2564 int i, j;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2565 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2566 WCHAR ch[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2567
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2568 ch[0] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2569 if (c >= 0xD800 && c <= 0xDBFF) // High surrogate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2570 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2571 ch[1] = tgetch(&modifiers, &ch2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2572 n++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2573 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2574 p = utf16_to_enc(ch, &n);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2575 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2576 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2577 for (i = 0, j = 0; i < n; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2578 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2579 typeahead[typeaheadlen + j++] = p[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2580 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2581 if (p[i] == CSI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2582 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2583 typeahead[typeaheadlen + j++] = KS_EXTRA;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2584 typeahead[typeaheadlen + j++] = KE_CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2586 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2587 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2588 n = j;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2589 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2590 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2591 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2592 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2593 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2594 typeahead[typeaheadlen] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2595 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2596 if (c == CSI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2597 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2598 typeahead[typeaheadlen + 1] = KS_EXTRA;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2599 typeahead[typeaheadlen + 2] = KE_CSI;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2600 n = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2602 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2603 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2604 if (ch2 != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2605 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2606 if (c == K_NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2607 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2608 switch (ch2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2609 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2610 case (WCHAR)'\324': // SHIFT+Insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2611 case (WCHAR)'\325': // CTRL+Insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2612 case (WCHAR)'\327': // SHIFT+Delete
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2613 case (WCHAR)'\330': // CTRL+Delete
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2614 typeahead[typeaheadlen + n] = (char_u)ch2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2615 n++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2616 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2617
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2618 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2619 typeahead[typeaheadlen + n] = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2620 typeahead[typeaheadlen + n + 1] = (char_u)ch2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2621 n += 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2622 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2623 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2624 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2625 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2626 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2627 typeahead[typeaheadlen + n] = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2628 typeahead[typeaheadlen + n + 1] = (char_u)ch2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2629 n += 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2630 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2631 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2632
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2633 // Use the ALT key to set the 8th bit of the character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2634 // when it's one byte, the 8th bit isn't set yet and not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2635 // using a double-byte encoding (would become a lead
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2636 // byte).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2637 if ((modifiers & MOD_MASK_ALT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2638 && n == 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2639 && (typeahead[typeaheadlen] & 0x80) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2640 && !enc_dbcs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2641 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2642 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2643 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2644 typeahead + typeaheadlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2645 modifiers &= ~MOD_MASK_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2646 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2647
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2648 if (modifiers != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2649 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2650 // Prepend modifiers to the character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2651 mch_memmove(typeahead + typeaheadlen + 3,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2652 typeahead + typeaheadlen, n);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2653 typeahead[typeaheadlen++] = K_SPECIAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2654 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2655 typeahead[typeaheadlen++] = modifiers;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2656 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2657
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2658 typeaheadlen += n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2659
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2660 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2661 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2662 fputc(c, fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2663 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2665 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2666 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2668 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2669 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2670 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2671 fputs("]\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2672 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2673 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2674 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2675
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2676 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2677 // Move typeahead to "buf", as much as fits.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2678 len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2679 while (len < maxlen && typeaheadlen > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2681 buf[len++] = typeahead[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2682 mch_memmove(typeahead, typeahead + 1, --typeaheadlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2683 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2684 # ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2685 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2686 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2687 buf[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2688 ch_log(NULL, "raw key input: \"%s\"", buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2689 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2690 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2691 return len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2693 #else // FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2694 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2695 #endif // FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2696 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2697
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2698 #ifndef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2699 # ifndef __MINGW32__
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2700 # include <shellapi.h> // required for FindExecutable()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2701 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2702 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2703
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2704 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2705 * Return TRUE if "name" is an executable file, FALSE if not or it doesn't exist.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2706 * When returning TRUE and "path" is not NULL save the path and set "*path" to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2707 * the allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2708 * TODO: Should somehow check if it's really executable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2709 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2710 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2711 executable_file(char *name, char_u **path)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2712 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2713 int attrs = win32_getattrs((char_u *)name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2714
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2715 // The file doesn't exist or is a folder.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2716 if (attrs == -1 || (attrs & FILE_ATTRIBUTE_DIRECTORY))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2717 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2718 // Check if the file is an AppExecLink, a special alias used by Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2719 // Store for its apps.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2720 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2721 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2722 char_u *res = resolve_appexeclink((char_u *)name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2723 if (res == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2724 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2725 // The path is already absolute.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2726 if (path != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2727 *path = res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2728 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2729 vim_free(res);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2730 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2731 else if (path != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2732 *path = FullName_save((char_u *)name, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2733 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2734 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2736 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2737 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2738 * If "use_path" is FALSE: Return TRUE if "name" exists.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2739 * If "use_pathext" is TRUE search "name" with extensions in $PATHEXT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2740 * When returning TRUE and "path" is not NULL save the path and set "*path" to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2741 * the allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2742 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2743 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2744 executable_exists(char *name, char_u **path, int use_path, int use_pathext)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2745 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2746 // WinNT and later can use _MAX_PATH wide characters for a pathname, which
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2747 // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2748 // UTF-8.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2749 char_u buf[_MAX_PATH * 3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2750 size_t len = STRLEN(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2751 size_t tmplen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2752 char_u *p, *e, *e2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2753 char_u *pathbuf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2754 char_u *pathext = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2755 char_u *pathextbuf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2756 char_u *shname = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2757 int noext = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2758 int retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2759
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2760 if (len >= sizeof(buf)) // safety check
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2761 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2762
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2763 // Using the name directly when a Unix-shell like 'shell'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2764 shname = gettail(p_sh);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2765 if (strstr((char *)shname, "sh") != NULL &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2766 !(strstr((char *)shname, "powershell") != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2767 || strstr((char *)shname, "pwsh") != NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2768 noext = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2769
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2770 if (use_pathext)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2771 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2772 pathext = mch_getenv("PATHEXT");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2773 if (pathext == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2774 pathext = (char_u *)".com;.exe;.bat;.cmd";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2775
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2776 if (noext == FALSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2777 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2778 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2779 * Loop over all extensions in $PATHEXT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2780 * Check "name" ends with extension.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2781 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2782 p = pathext;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2783 while (*p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2784 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2785 if (p[0] == ';'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2786 || (p[0] == '.' && (p[1] == NUL || p[1] == ';')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2787 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2788 // Skip empty or single ".".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2789 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2790 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2791 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2792 e = vim_strchr(p, ';');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2793 if (e == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2794 e = p + STRLEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2795 tmplen = e - p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2796
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2797 if (_strnicoll(name + len - tmplen, (char *)p, tmplen) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2798 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2799 noext = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2800 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2801 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2802
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2803 p = e;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2804 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2805 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2806 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2808 // Prepend single "." to pathext, it means no extension added.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2809 if (pathext == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2810 pathext = (char_u *)".";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2811 else if (noext == TRUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2812 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2813 if (pathextbuf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2814 pathextbuf = alloc(STRLEN(pathext) + 3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2815 if (pathextbuf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2816 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2817 retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2818 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2819 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2820 STRCPY(pathextbuf, ".;");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2821 STRCAT(pathextbuf, pathext);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2822 pathext = pathextbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2823 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2825 // Use $PATH when "use_path" is TRUE and "name" is basename.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2826 if (use_path && gettail((char_u *)name) == (char_u *)name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2827 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2828 p = mch_getenv("PATH");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2829 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2830 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2831 pathbuf = alloc(STRLEN(p) + 3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2832 if (pathbuf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2833 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2834 retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2835 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2836 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2838 if (mch_getenv("NoDefaultCurrentDirectoryInExePath") == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2839 STRCPY(pathbuf, ".;");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2840 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2841 *pathbuf = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2842 STRCAT(pathbuf, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2843 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2844 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2845
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2846 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2847 * Walk through all entries in $PATH to check if "name" exists there and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2848 * is an executable file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2849 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2850 p = (pathbuf != NULL) ? pathbuf : (char_u *)".";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2851 while (*p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2852 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2853 if (*p == ';') // Skip empty entry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2854 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2855 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2856 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2857 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2858 e = vim_strchr(p, ';');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2859 if (e == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2860 e = p + STRLEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2861
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2862 if (e - p + len + 2 > sizeof(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2863 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2864 retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2865 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2866 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2867 // A single "." that means current dir.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2868 if (e - p == 1 && *p == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2869 STRCPY(buf, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2870 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2871 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2872 vim_strncpy(buf, p, e - p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2873 add_pathsep(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2874 STRCAT(buf, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2875 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2876 tmplen = STRLEN(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2877
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2878 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2879 * Loop over all extensions in $PATHEXT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2880 * Check "name" with extension added.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2881 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2882 p = pathext;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2883 while (*p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2884 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2885 if (*p == ';')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2886 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2887 // Skip empty entry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2888 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2889 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2890 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2891 e2 = vim_strchr(p, (int)';');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2892 if (e2 == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2893 e2 = p + STRLEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2894
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2895 if (!(p[0] == '.' && (p[1] == NUL || p[1] == ';')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2896 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2897 // Not a single "." that means no extension is added.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2898 if (e2 - p + tmplen + 1 > sizeof(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2899 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2900 retval = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2901 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2902 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2903 vim_strncpy(buf + tmplen, p, e2 - p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2904 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2905 if (executable_file((char *)buf, path))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2906 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2907 retval = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2908 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2909 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2910
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2911 p = e2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2912 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2913
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2914 p = e;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2915 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2917 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2918 free(pathextbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2919 free(pathbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2920 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2921 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2922
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2923 #if (defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x800) || \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2924 (defined(_MSC_VER) && _MSC_VER >= 1400)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2925 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2926 * Bad parameter handler.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2927 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2928 * Certain MS CRT functions will intentionally crash when passed invalid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2929 * parameters to highlight possible security holes. Setting this function as
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2930 * the bad parameter handler will prevent the crash.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2931 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2932 * In debug builds the parameters contain CRT information that might help track
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2933 * down the source of a problem, but in non-debug builds the arguments are all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2934 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2935 * worth allowing these to make debugging of issues easier.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2936 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2937 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2938 bad_param_handler(const wchar_t *expression UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2939 const wchar_t *function UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2940 const wchar_t *file UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2941 unsigned int line UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2942 uintptr_t pReserved UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2943 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2944 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2946 # define SET_INVALID_PARAM_HANDLER \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2947 ((void)_set_invalid_parameter_handler(bad_param_handler))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2948 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2949 # define SET_INVALID_PARAM_HANDLER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2950 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2951
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2952 #ifdef FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2953
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2954 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2955 * GUI version of mch_init().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2956 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2957 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2958 mch_init_g(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2959 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2960 # ifndef __MINGW32__
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2961 extern int _fmode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2962 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2963
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2964 // Silently handle invalid parameters to CRT functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2965 SET_INVALID_PARAM_HANDLER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2966
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2967 // Let critical errors result in a failure, not in a dialog box. Required
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2968 // for the timestamp test to work on removed floppies.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2969 SetErrorMode(SEM_FAILCRITICALERRORS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2971 _fmode = O_BINARY; // we do our own CR-LF translation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2972
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2973 // Specify window size. Is there a place to get the default from?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2974 Rows = 25;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2975 Columns = 80;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2977 // Look for 'vimrun'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2978 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2979 char_u vimrun_location[_MAX_PATH + 4];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2980
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2981 // First try in same directory as gvim.exe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2982 STRCPY(vimrun_location, exe_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2983 STRCPY(gettail(vimrun_location), "vimrun.exe");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2984 if (mch_getperm(vimrun_location) >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2985 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2986 if (*skiptowhite(vimrun_location) != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2987 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2988 // Enclose path with white space in double quotes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2989 mch_memmove(vimrun_location + 1, vimrun_location,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2990 STRLEN(vimrun_location) + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2991 *vimrun_location = '"';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2992 STRCPY(gettail(vimrun_location), "vimrun\" ");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2993 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2994 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2995 STRCPY(gettail(vimrun_location), "vimrun ");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2997 vimrun_path = (char *)vim_strsave(vimrun_location);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2998 s_dont_use_vimrun = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
2999 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3000 else if (executable_exists("vimrun.exe", NULL, TRUE, FALSE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3001 s_dont_use_vimrun = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3003 // Don't give the warning for a missing vimrun.exe right now, but only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3004 // when vimrun was supposed to be used. Don't bother people that do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3005 // not need vimrun.exe.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3006 if (s_dont_use_vimrun)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3007 need_vimrun_warning = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3008 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3009
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3010 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3011 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3012 * Otherwise the default "findstr /n" is used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3013 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3014 if (!executable_exists("findstr.exe", NULL, TRUE, FALSE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3015 set_option_value_give_err((char_u *)"grepprg",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3016 0, (char_u *)"grep -n", 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3018 # ifdef FEAT_CLIPBOARD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3019 win_clip_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3020 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3022 vtp_flag_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3023 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3026 #endif // FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3028 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3030 # define SRWIDTH(sr) ((sr).Right - (sr).Left + 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3031 # define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3032
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3033 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3034 * ClearConsoleBuffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3035 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3036 * Clears the entire contents of the console screen buffer, using the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3037 * specified attribute.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3038 * Returns:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3039 * TRUE on success
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3040 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3041 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3042 ClearConsoleBuffer(WORD wAttribute)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3043 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3044 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3045 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3046 DWORD NumCells, dummy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3047
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3048 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3049 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3051 NumCells = csbi.dwSize.X * csbi.dwSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3052 coord.X = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3053 coord.Y = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3054 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3055 coord, &dummy))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3056 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3057 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3058 coord, &dummy))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3059 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3060
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3061 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3062 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3063
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3064 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3065 * FitConsoleWindow()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3066 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3067 * Checks if the console window will fit within given buffer dimensions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3068 * Also, if requested, will shrink the window to fit.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3069 * Returns:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3070 * TRUE on success
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3071 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3072 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3073 FitConsoleWindow(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3074 COORD dwBufferSize,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3075 BOOL WantAdjust)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3076 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3077 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3078 COORD dwWindowSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3079 BOOL NeedAdjust = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3081 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3082 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3084 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3085 * A buffer resize will fail if the current console window does
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3086 * not lie completely within that buffer. To avoid this, we might
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3087 * have to move and possibly shrink the window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3088 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3089 if (csbi.srWindow.Right >= dwBufferSize.X)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3090 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3091 dwWindowSize.X = SRWIDTH(csbi.srWindow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3092 if (dwWindowSize.X > dwBufferSize.X)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3093 dwWindowSize.X = dwBufferSize.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3094 csbi.srWindow.Right = dwBufferSize.X - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3095 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3096 NeedAdjust = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3097 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3098 if (csbi.srWindow.Bottom >= dwBufferSize.Y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3099 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3100 dwWindowSize.Y = SRHEIGHT(csbi.srWindow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3101 if (dwWindowSize.Y > dwBufferSize.Y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3102 dwWindowSize.Y = dwBufferSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3103 csbi.srWindow.Bottom = dwBufferSize.Y - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3104 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3105 NeedAdjust = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3106 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3107 if (NeedAdjust && WantAdjust)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3108 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3109 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3110 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3111 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3112 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3113 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3115 typedef struct ConsoleBufferStruct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3116 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3117 BOOL IsValid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3118 CONSOLE_SCREEN_BUFFER_INFO Info;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3119 PCHAR_INFO Buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3120 COORD BufferSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3121 PSMALL_RECT Regions;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3122 int NumRegions;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3123 } ConsoleBuffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3124
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3125 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3126 * SaveConsoleBuffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3127 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3128 * Saves important information about the console buffer, including the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3129 * actual buffer contents. The saved information is suitable for later
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3130 * restoration by RestoreConsoleBuffer().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3131 * Returns:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3132 * TRUE if all information was saved; FALSE otherwise
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3133 * If FALSE, still sets cb->IsValid if buffer characteristics were saved.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3134 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3135 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3136 SaveConsoleBuffer(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3137 ConsoleBuffer *cb)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3138 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3139 DWORD NumCells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3140 COORD BufferCoord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3141 SMALL_RECT ReadRegion;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3142 WORD Y, Y_incr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3143 int i, numregions;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3144
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3145 if (cb == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3146 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3147
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3148 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3149 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3150 cb->IsValid = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3151 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3152 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3153 cb->IsValid = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3155 // VTP uses alternate screen buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3156 // No need to save buffer contents for restoration.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3157 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3158 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3160 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3161 * Allocate a buffer large enough to hold the entire console screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3162 * buffer. If this ConsoleBuffer structure has already been initialized
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3163 * with a buffer of the correct size, then just use that one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3164 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3165 if (!cb->IsValid || cb->Buffer == NULL ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3166 cb->BufferSize.X != cb->Info.dwSize.X ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3167 cb->BufferSize.Y != cb->Info.dwSize.Y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3168 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3169 cb->BufferSize.X = cb->Info.dwSize.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3170 cb->BufferSize.Y = cb->Info.dwSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3171 NumCells = cb->BufferSize.X * cb->BufferSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3172 vim_free(cb->Buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3173 cb->Buffer = ALLOC_MULT(CHAR_INFO, NumCells);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3174 if (cb->Buffer == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3175 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3176 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3177
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3178 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3179 * We will now copy the console screen buffer into our buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3180 * ReadConsoleOutput() seems to be limited as far as how much you
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3181 * can read at a time. Empirically, this number seems to be about
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3182 * 12000 cells (rows * columns). Start at position (0, 0) and copy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3183 * in chunks until it is all copied. The chunks will all have the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3184 * same horizontal characteristics, so initialize them now. The
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3185 * height of each chunk will be (12000 / width).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3186 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3187 BufferCoord.X = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3188 ReadRegion.Left = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3189 ReadRegion.Right = cb->Info.dwSize.X - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3190 Y_incr = 12000 / cb->Info.dwSize.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3191
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3192 numregions = (cb->Info.dwSize.Y + Y_incr - 1) / Y_incr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3193 if (cb->Regions == NULL || numregions != cb->NumRegions)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3194 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3195 cb->NumRegions = numregions;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3196 vim_free(cb->Regions);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3197 cb->Regions = ALLOC_MULT(SMALL_RECT, cb->NumRegions);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3198 if (cb->Regions == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3199 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3200 VIM_CLEAR(cb->Buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3201 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3202 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3203 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3204
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3205 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3206 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3207 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3208 * Read into position (0, Y) in our buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3209 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3210 BufferCoord.Y = Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3211 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3212 * Read the region whose top left corner is (0, Y) and whose bottom
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3213 * right corner is (width - 1, Y + Y_incr - 1). This should define
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3214 * a region of size width by Y_incr. Don't worry if this region is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3215 * too large for the remaining buffer; it will be cropped.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3216 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3217 ReadRegion.Top = Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3218 ReadRegion.Bottom = Y + Y_incr - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3219 if (!ReadConsoleOutputW(g_hConOut, // output handle
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3220 cb->Buffer, // our buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3221 cb->BufferSize, // dimensions of our buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3222 BufferCoord, // offset in our buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3223 &ReadRegion)) // region to save
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3224 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3225 VIM_CLEAR(cb->Buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3226 VIM_CLEAR(cb->Regions);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3227 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3228 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3229 cb->Regions[i] = ReadRegion;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3230 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3231
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3232 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3233 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3234
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3235 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3236 * RestoreConsoleBuffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3237 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3238 * Restores important information about the console buffer, including the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3239 * actual buffer contents, if desired. The information to restore is in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3240 * the same format used by SaveConsoleBuffer().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3241 * Returns:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3242 * TRUE on success
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3243 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3244 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3245 RestoreConsoleBuffer(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3246 ConsoleBuffer *cb,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3247 BOOL RestoreScreen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3248 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3249 COORD BufferCoord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3250 SMALL_RECT WriteRegion;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3251 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3253 // VTP uses alternate screen buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3254 // No need to restore buffer contents.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3255 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3256 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3257
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3258 if (cb == NULL || !cb->IsValid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3259 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3261 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3262 * Before restoring the buffer contents, clear the current buffer, and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3263 * restore the cursor position and window information. Doing this now
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3264 * prevents old buffer contents from "flashing" onto the screen.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3265 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3266 if (RestoreScreen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3267 ClearConsoleBuffer(cb->Info.wAttributes);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3269 FitConsoleWindow(cb->Info.dwSize, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3270 if (!SetConsoleScreenBufferSize(g_hConOut, cb->Info.dwSize))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3271 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3272 if (!SetConsoleTextAttribute(g_hConOut, cb->Info.wAttributes))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3273 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3274
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3275 if (!RestoreScreen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3276 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3277 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3278 * No need to restore the screen buffer contents, so we're done.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3279 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3280 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3281 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3283 if (!SetConsoleCursorPosition(g_hConOut, cb->Info.dwCursorPosition))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3284 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3285 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &cb->Info.srWindow))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3286 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3288 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3289 * Restore the screen buffer contents.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3290 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3291 if (cb->Buffer != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3292 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3293 for (i = 0; i < cb->NumRegions; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3294 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3295 BufferCoord.X = cb->Regions[i].Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3296 BufferCoord.Y = cb->Regions[i].Top;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3297 WriteRegion = cb->Regions[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3298 if (!WriteConsoleOutputW(g_hConOut, // output handle
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3299 cb->Buffer, // our buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3300 cb->BufferSize, // dimensions of our buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3301 BufferCoord, // offset in our buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3302 &WriteRegion)) // region to restore
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3303 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3304 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3305 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3306
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3307 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3308 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3309
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3310 # define FEAT_RESTORE_ORIG_SCREEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3311 # ifdef FEAT_RESTORE_ORIG_SCREEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3312 static ConsoleBuffer g_cbOrig = { 0 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3313 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3314 static ConsoleBuffer g_cbNonTermcap = { 0 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3315 static ConsoleBuffer g_cbTermcap = { 0 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3317 char g_szOrigTitle[256] = { 0 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3318 HWND g_hWnd = NULL; // also used in os_mswin.c
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3319 static HICON g_hOrigIconSmall = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3320 static HICON g_hOrigIcon = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3321 static HICON g_hVimIcon = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3322 static BOOL g_fCanChangeIcon = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3324 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3325 * GetConsoleIcon()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3326 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3327 * Attempts to retrieve the small icon and/or the big icon currently in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3328 * use by a given window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3329 * Returns:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3330 * TRUE on success
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3331 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3332 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3333 GetConsoleIcon(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3334 HWND hWnd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3335 HICON *phIconSmall,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3336 HICON *phIcon)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3337 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3338 if (hWnd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3339 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3341 if (phIconSmall != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3342 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3343 (WPARAM)ICON_SMALL, (LPARAM)0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3344 if (phIcon != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3345 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3346 (WPARAM)ICON_BIG, (LPARAM)0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3347 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3348 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3349
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3350 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3351 * SetConsoleIcon()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3352 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3353 * Attempts to change the small icon and/or the big icon currently in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3354 * use by a given window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3355 * Returns:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3356 * TRUE on success
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3357 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3358 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3359 SetConsoleIcon(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3360 HWND hWnd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3361 HICON hIconSmall,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3362 HICON hIcon)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3363 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3364 if (hWnd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3365 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3367 if (hIconSmall != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3368 SendMessage(hWnd, WM_SETICON,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3369 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3370 if (hIcon != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3371 SendMessage(hWnd, WM_SETICON,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3372 (WPARAM)ICON_BIG, (LPARAM) hIcon);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3373 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3374 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3375
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3376 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3377 * SaveConsoleTitleAndIcon()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3378 * Description:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3379 * Saves the current console window title in g_szOrigTitle, for later
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3380 * restoration. Also, attempts to obtain a handle to the console window,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3381 * and use it to save the small and big icons currently in use by the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3382 * console window. This is not always possible on some versions of Windows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3383 * nor is it possible when running Vim remotely using Telnet (since the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3384 * console window the user sees is owned by a remote process).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3385 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3386 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3387 SaveConsoleTitleAndIcon(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3388 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3389 // Save the original title.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3390 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3391 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3393 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3394 * Obtain a handle to the console window using GetConsoleWindow() from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3395 * KERNEL32.DLL; we need to handle in order to change the window icon.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3396 * This function only exists on NT-based Windows, starting with Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3397 * 2000. On older operating systems, we can't change the window icon
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3398 * anyway.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3399 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3400 g_hWnd = GetConsoleWindow();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3401 if (g_hWnd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3402 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3404 // Save the original console window icon.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3405 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3406 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3407 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3408
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3409 // Extract the first icon contained in the Vim executable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3410 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3411 # ifdef FEAT_LIBCALL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3412 mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3413 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3414 g_hVimIcon == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3415 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3416 if (g_hVimIcon != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3417 g_fCanChangeIcon = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3418 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3419
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3420 static int g_fWindInitCalled = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3421 static int g_fTermcapMode = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3422 static CONSOLE_CURSOR_INFO g_cci;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3423
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3424 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3425 * non-GUI version of mch_init().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3426 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3427 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3428 mch_init_c(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3429 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3430 # ifndef FEAT_RESTORE_ORIG_SCREEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3431 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3432 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3433 # ifndef __MINGW32__
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3434 extern int _fmode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3435 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3437 // Silently handle invalid parameters to CRT functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3438 SET_INVALID_PARAM_HANDLER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3440 // Let critical errors result in a failure, not in a dialog box. Required
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3441 // for the timestamp test to work on removed floppies.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3442 SetErrorMode(SEM_FAILCRITICALERRORS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3443
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3444 _fmode = O_BINARY; // we do our own CR-LF translation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3445 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3447 // Obtain handles for the standard Console I/O devices
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3448 if (read_cmd_fd == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3449 g_hConIn = GetStdHandle(STD_INPUT_HANDLE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3450 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3451 create_conin();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3452 g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3453
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3454 wt_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3455 vtp_flag_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3456 # ifdef FEAT_RESTORE_ORIG_SCREEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3457 // Save the initial console buffer for later restoration
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3458 SaveConsoleBuffer(&g_cbOrig);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3459 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3460 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3461 // Get current text attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3462 GetConsoleScreenBufferInfo(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3463 g_attrCurrent = g_attrDefault = csbi.wAttributes;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3464 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3465 if (cterm_normal_fg_color == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3466 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3467 if (cterm_normal_bg_color == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3468 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3469
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3470 // Fg and Bg color index number at startup
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3471 g_color_index_fg = g_attrDefault & 0xf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3472 g_color_index_bg = (g_attrDefault >> 4) & 0xf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3473
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3474 // set termcap codes to current text attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3475 update_tcap(g_attrCurrent);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3476
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3477 GetConsoleCursorInfo(g_hConOut, &g_cci);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3478 GetConsoleMode(g_hConIn, &g_cmodein);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3479 GetConsoleMode(g_hConOut, &g_cmodeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3481 SaveConsoleTitleAndIcon();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3482 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3483 * Set both the small and big icons of the console window to Vim's icon.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3484 * Note that Vim presently only has one size of icon (32x32), but it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3485 * automatically gets scaled down to 16x16 when setting the small icon.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3486 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3487 if (g_fCanChangeIcon)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3488 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3489
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3490 ui_get_shellsize();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3491
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3492 vtp_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3493 // Switch to a new alternate screen buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3494 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3495 vtp_printf("\033[?1049h");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3496
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3497 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3498 fdDump = fopen("dump", "wt");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3499
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3500 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3501 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3502 time_t t;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3503
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3504 time(&t);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3505 fputs(ctime(&t), fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3506 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3507 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3508 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3509
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3510 g_fWindInitCalled = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3511
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3512 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3514 # ifdef FEAT_CLIPBOARD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3515 win_clip_init();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3516 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3517 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3518
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3519 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3520 * non-GUI version of mch_exit().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3521 * Shut down and exit with status `r'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3522 * Careful: mch_exit() may be called before mch_init()!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3523 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3524 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3525 mch_exit_c(int r)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3526 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3527 exiting = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3528
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3529 vtp_exit();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3530
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3531 stoptermcap();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3532 if (g_fWindInitCalled)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3533 settmode(TMODE_COOK);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3534
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3535 ml_close_all(TRUE); // remove all memfiles
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3537 if (g_fWindInitCalled)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3538 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3539 mch_restore_title(SAVE_RESTORE_BOTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3540 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3541 * Restore both the small and big icons of the console window to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3542 * what they were at startup. Don't do this when the window is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3543 * closed, Vim would hang here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3544 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3545 if (g_fCanChangeIcon && !g_fForceExit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3546 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3547
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3548 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3549 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3550 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3551 time_t t;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3553 time(&t);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3554 fputs(ctime(&t), fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3555 fclose(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3556 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3557 fdDump = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3558 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3559 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3560
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3561 SetConsoleCursorInfo(g_hConOut, &g_cci);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3562 SetConsoleMode(g_hConIn, g_cmodein | ENABLE_EXTENDED_FLAGS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3563 SetConsoleMode(g_hConOut, g_cmodeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3564
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3565 # ifdef DYNAMIC_GETTEXT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3566 dyn_libintl_end();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3567 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3569 exit(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3570 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3571 #endif // !FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3572
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3573 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3574 mch_init(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3575 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3576 #ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3577 if (gui.starting)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3578 mch_init_g();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3579 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3580 mch_init_c();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3581 #elif defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3582 mch_init_g();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3583 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3584 mch_init_c();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3585 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3586 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3587
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3588 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3589 mch_exit(int r)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3590 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3591 #ifdef FEAT_NETBEANS_INTG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3592 netbeans_send_disconnect();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3593 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3594
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3595 #ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3596 if (gui.in_use || gui.starting)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3597 mch_exit_g(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3598 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3599 mch_exit_c(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3600 #elif defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3601 mch_exit_g(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3602 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3603 mch_exit_c(r);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3604 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3605 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3606
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3607 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3608 * Do we have an interactive window?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3609 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3610 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3611 mch_check_win(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3612 int argc UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3613 char **argv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3614 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3615 mch_get_exe_name();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3617 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3618 return OK; // GUI always has a tty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3619 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3620 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3621 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3622 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3623 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3624 if (isatty(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3625 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3626 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3627 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3628 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3629
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3630 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3631 * Set the case of the file name, if it already exists.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3632 * When "len" is > 0, also expand short to long filenames.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3633 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3634 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3635 fname_case(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3636 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3637 int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3638 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3639 int flen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3640 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3641 WCHAR buf[_MAX_PATH + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3643 flen = (int)STRLEN(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3644 if (flen == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3645 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3646
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3647 slash_adjust(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3648
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3649 p = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3650 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3651 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3652
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3653 if (GetLongPathNameW(p, buf, _MAX_PATH))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3654 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3655 char_u *q = utf16_to_enc(buf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3656
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3657 if (q != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3658 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3659 if (len > 0 || flen >= (int)STRLEN(q))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3660 vim_strncpy(name, q, (len > 0) ? len - 1 : flen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3661 vim_free(q);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3662 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3663 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3664 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3665 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3666
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3668 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3669 * Insert user name in s[len].
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3670 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3671 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3672 mch_get_user_name(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3673 char_u *s,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3674 int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3675 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3676 WCHAR wszUserName[256 + 1]; // UNLEN is 256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3677 DWORD wcch = ARRAY_LENGTH(wszUserName);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3679 if (GetUserNameW(wszUserName, &wcch))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3681 char_u *p = utf16_to_enc(wszUserName, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3682
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3683 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3684 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3685 vim_strncpy(s, p, len - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3686 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3687 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3688 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3689 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3690 s[0] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3691 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3692 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3694
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3695 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3696 * Insert host name in s[len].
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3697 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3698 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3699 mch_get_host_name(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3700 char_u *s,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3701 int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3702 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3703 WCHAR wszHostName[256 + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3704 DWORD wcch = ARRAY_LENGTH(wszHostName);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3706 if (!GetComputerNameW(wszHostName, &wcch))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3707 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3709 char_u *p = utf16_to_enc(wszHostName, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3710 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3711 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3712
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3713 vim_strncpy(s, p, len - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3714 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3715 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3716
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3717
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3718 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3719 * return process ID
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3720 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3721 long
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3722 mch_get_pid(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3723 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3724 return (long)GetCurrentProcessId();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3725 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3726
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3727 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3728 * return TRUE if process "pid" is still running
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3729 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3730 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3731 mch_process_running(long pid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3732 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3733 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, (DWORD)pid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3734 DWORD status = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3735 int ret = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3736
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3737 if (hProcess == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3738 return FALSE; // might not have access
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3739 if (GetExitCodeProcess(hProcess, &status) )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3740 ret = status == STILL_ACTIVE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3741 CloseHandle(hProcess);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3742 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3743 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3744
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3745 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3746 * Get name of current directory into buffer 'buf' of length 'len' bytes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3747 * Return OK for success, FAIL for failure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3748 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3749 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3750 mch_dirname(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3751 char_u *buf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3752 int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3753 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3754 WCHAR wbuf[_MAX_PATH + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3755
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3756 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3757 * Originally this was:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3758 * return (getcwd(buf, len) != NULL ? OK : FAIL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3759 * But the Win32s known bug list says that getcwd() doesn't work
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3760 * so use the Win32 system call instead. <Negri>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3761 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3762 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3763 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3764
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3765 WCHAR wcbuf[_MAX_PATH + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3766 char_u *p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3768 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3769 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3770 p = utf16_to_enc(wcbuf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3771 if (STRLEN(p) >= (size_t)len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3772 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3773 // long path name is too long, fall back to short one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3774 VIM_CLEAR(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3775 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3776 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3777 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3778 p = utf16_to_enc(wbuf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3780 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3781 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3782
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3783 vim_strncpy(buf, p, len - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3784 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3785 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3786 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3788 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3789 * Get file permissions for "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3790 * Return mode_t or -1 for error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3791 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3792 long
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3793 mch_getperm(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3794 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3795 stat_T st;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3796 int n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3797
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3798 n = mch_stat((char *)name, &st);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3799 return n == 0 ? (long)(unsigned short)st.st_mode : -1L;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3800 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3801
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3802
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3803 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3804 * Set file permission for "name" to "perm".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3805 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3806 * Return FAIL for failure, OK otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3807 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3808 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3809 mch_setperm(char_u *name, long perm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3810 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3811 long n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3812 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3814 p = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3815 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3816 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3817
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3818 n = _wchmod(p, perm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3819 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3820 if (n == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3821 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3822
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3823 win32_set_archive(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3825 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3826 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3827
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3828 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3829 * Set hidden flag for "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3830 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3831 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3832 mch_hide(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3833 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3834 int attrs = win32_getattrs(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3835 if (attrs == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3836 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3838 attrs |= FILE_ATTRIBUTE_HIDDEN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3839 win32_setattrs(name, attrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3840 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3842 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3843 * Return TRUE if file "name" exists and is hidden.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3844 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3845 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3846 mch_ishidden(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3847 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3848 int f = win32_getattrs(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3849
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3850 if (f == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3851 return FALSE; // file does not exist at all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3852
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3853 return (f & FILE_ATTRIBUTE_HIDDEN) != 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3854 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3855
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3856 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3857 * return TRUE if "name" is a directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3858 * return FALSE if "name" is not a directory or upon error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3859 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3860 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3861 mch_isdir(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3862 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3863 int f = win32_getattrs(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3864
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3865 if (f == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3866 return FALSE; // file does not exist at all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3867
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3868 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3869 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3870
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3871 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3872 * return TRUE if "name" is a directory, NOT a symlink to a directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3873 * return FALSE if "name" is not a directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3874 * return FALSE for error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3875 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3876 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3877 mch_isrealdir(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3878 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3879 return mch_isdir(name) && !mch_is_symbolic_link(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3880 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3881
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3882 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3883 * Create directory "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3884 * Return 0 on success, -1 on error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3885 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3886 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3887 mch_mkdir(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3888 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3889 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3890 int retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3891
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3892 p = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3893 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3894 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3895 retval = _wmkdir(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3896 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3897 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3898 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3899
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3900 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3901 * Delete directory "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3902 * Return 0 on success, -1 on error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3903 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3904 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3905 mch_rmdir(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3906 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3907 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3908 int retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3909
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3910 p = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3911 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3912 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3913 retval = _wrmdir(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3914 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3915 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3916 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3917
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3918 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3919 * Return TRUE if file "fname" has more than one link.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3920 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3921 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3922 mch_is_hard_link(char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3923 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3924 BY_HANDLE_FILE_INFORMATION info;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3925
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3926 return win32_fileinfo(fname, &info) == FILEINFO_OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3927 && info.nNumberOfLinks > 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3928 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3929
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3930 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3931 * Return TRUE if "name" is a symbolic link (or a junction).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3932 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3933 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3934 mch_is_symbolic_link(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3935 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3936 HANDLE hFind;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3937 int res = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3938 DWORD fileFlags = 0, reparseTag = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3939 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3940 WIN32_FIND_DATAW findDataW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3942 wn = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3943 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3944 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3946 hFind = FindFirstFileW(wn, &findDataW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3947 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3948 if (hFind != INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3949 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3950 fileFlags = findDataW.dwFileAttributes;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3951 reparseTag = findDataW.dwReserved0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3952 FindClose(hFind);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3953 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3954
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3955 if ((fileFlags & FILE_ATTRIBUTE_REPARSE_POINT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3956 && (reparseTag == IO_REPARSE_TAG_SYMLINK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3957 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3958 res = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3959
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3960 return res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3961 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3962
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3963 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3964 * Return TRUE if file "fname" has more than one link or if it is a symbolic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3965 * link.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3966 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3967 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3968 mch_is_linked(char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3969 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3970 if (mch_is_hard_link(fname) || mch_is_symbolic_link(fname))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3971 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3972 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3975 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3976 * Get the by-handle-file-information for "fname".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3977 * Returns FILEINFO_OK when OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3978 * Returns FILEINFO_ENC_FAIL when enc_to_utf16() failed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3979 * Returns FILEINFO_READ_FAIL when CreateFile() failed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3980 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3981 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3982 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3983 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3984 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3985 HANDLE hFile;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3986 int res = FILEINFO_READ_FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3987 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3988
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3989 wn = enc_to_utf16(fname, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3990 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3991 return FILEINFO_ENC_FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3993 hFile = CreateFileW(wn, // file name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3994 GENERIC_READ, // access mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3995 FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3996 NULL, // security descriptor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3997 OPEN_EXISTING, // creation disposition
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3998 FILE_FLAG_BACKUP_SEMANTICS, // file attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
3999 NULL); // handle to template file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4000 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4002 if (hFile == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4003 return FILEINFO_READ_FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4004
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4005 if (GetFileInformationByHandle(hFile, info) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4006 res = FILEINFO_OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4007 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4008 res = FILEINFO_INFO_FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4009 CloseHandle(hFile);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4011 return res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4012 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4013
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4014 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4015 * get file attributes for `name'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4016 * -1 : error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4017 * else FILE_ATTRIBUTE_* defined in winnt.h
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4018 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4019 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4020 win32_getattrs(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4021 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4022 int attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4023 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4025 p = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4026 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4027 return INVALID_FILE_ATTRIBUTES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4028
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4029 attr = GetFileAttributesW(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4030 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4031
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4032 return attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4033 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4034
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4035 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4036 * set file attributes for `name' to `attrs'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4037 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4038 * return -1 for failure, 0 otherwise
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4039 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4040 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4041 win32_setattrs(char_u *name, int attrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4042 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4043 int res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4044 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4045
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4046 p = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4047 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4048 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4050 res = SetFileAttributesW(p, attrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4051 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4052
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4053 return res ? 0 : -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4054 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4056 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4057 * Set archive flag for "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4058 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4059 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4060 win32_set_archive(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4061 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4062 int attrs = win32_getattrs(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4063 if (attrs == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4064 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4065
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4066 attrs |= FILE_ATTRIBUTE_ARCHIVE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4067 return win32_setattrs(name, attrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4068 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4069
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4070 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4071 * Return TRUE if file or directory "name" is writable (not readonly).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4072 * Strange semantics of Win32: a readonly directory is writable, but you can't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4073 * delete a file. Let's say this means it is writable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4074 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4075 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4076 mch_writable(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4077 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4078 int attrs = win32_getattrs(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4079
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4080 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4081 || (attrs & FILE_ATTRIBUTE_DIRECTORY)));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4082 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4084 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4085 * Return TRUE if "name" can be executed, FALSE if not.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4086 * If "use_path" is FALSE only check if "name" is executable.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4087 * When returning TRUE and "path" is not NULL save the path and set "*path" to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4088 * the allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4089 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4090 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4091 mch_can_exe(char_u *name, char_u **path, int use_path UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4092 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4093 return executable_exists((char *)name, path, TRUE, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4094 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4095
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4096 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4097 * Check what "name" is:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4098 * NODE_NORMAL: file or directory (or doesn't exist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4099 * NODE_WRITABLE: writable device, socket, fifo, etc.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4100 * NODE_OTHER: non-writable things
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4101 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4102 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4103 mch_nodetype(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4104 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4105 HANDLE hFile;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4106 int type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4107 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4109 // We can't open a file with a name "\\.\con" or "\\.\prn" and trying to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4110 // read from it later will cause Vim to hang. Thus return NODE_WRITABLE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4111 // here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4112 if (STRNCMP(name, "\\\\.\\", 4) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4113 return NODE_WRITABLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4115 wn = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4116 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4117 return NODE_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4118
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4119 hFile = CreateFileW(wn, // file name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4120 GENERIC_WRITE, // access mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4121 0, // share mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4122 NULL, // security descriptor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4123 OPEN_EXISTING, // creation disposition
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4124 0, // file attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4125 NULL); // handle to template file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4126 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4127 if (hFile == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4128 return NODE_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4130 type = GetFileType(hFile);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4131 CloseHandle(hFile);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4132 if (type == FILE_TYPE_CHAR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4133 return NODE_WRITABLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4134 if (type == FILE_TYPE_DISK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4135 return NODE_NORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4136 return NODE_OTHER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4137 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4138
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4139 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4140 struct my_acl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4141 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4142 PSECURITY_DESCRIPTOR pSecurityDescriptor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4143 PSID pSidOwner;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4144 PSID pSidGroup;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4145 PACL pDacl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4146 PACL pSacl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4147 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4148 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4150 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4151 * Return a pointer to the ACL of file "fname" in allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4152 * Return NULL if the ACL is not available for whatever reason.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4153 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4154 vim_acl_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4155 mch_get_acl(char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4156 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4157 #ifndef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4158 return (vim_acl_T)NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4159 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4160 struct my_acl *p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4161 DWORD err;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4162
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4163 p = ALLOC_CLEAR_ONE(struct my_acl);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4164 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4165 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4166 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4168 wn = enc_to_utf16(fname, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4169 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4170 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4171 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4172 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4173 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4174
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4175 // Try to retrieve the entire security descriptor.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4176 err = GetNamedSecurityInfoW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4177 wn, // Abstract filename
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4178 SE_FILE_OBJECT, // File Object
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4179 OWNER_SECURITY_INFORMATION |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4180 GROUP_SECURITY_INFORMATION |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4181 DACL_SECURITY_INFORMATION |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4182 SACL_SECURITY_INFORMATION,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4183 &p->pSidOwner, // Ownership information.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4184 &p->pSidGroup, // Group membership.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4185 &p->pDacl, // Discretionary information.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4186 &p->pSacl, // For auditing purposes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4187 &p->pSecurityDescriptor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4188 if (err == ERROR_ACCESS_DENIED ||
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4189 err == ERROR_PRIVILEGE_NOT_HELD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4191 // Retrieve only DACL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4192 (void)GetNamedSecurityInfoW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4193 wn,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4194 SE_FILE_OBJECT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4195 DACL_SECURITY_INFORMATION,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4196 NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4197 NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4198 &p->pDacl,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4199 NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4200 &p->pSecurityDescriptor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4201 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4202 if (p->pSecurityDescriptor == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4203 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4204 mch_free_acl((vim_acl_T)p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4205 p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4206 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4207 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4208 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4209
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4210 return (vim_acl_T)p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4211 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4212 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4213
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4214 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4215 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4216 * Check if "acl" contains inherited ACE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4217 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4218 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4219 is_acl_inherited(PACL acl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4220 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4221 DWORD i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4222 ACL_SIZE_INFORMATION acl_info;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4223 PACCESS_ALLOWED_ACE ace;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4224
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4225 acl_info.AceCount = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4226 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4227 for (i = 0; i < acl_info.AceCount; i++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4228 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4229 GetAce(acl, i, (LPVOID *)&ace);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4230 if (ace->Header.AceFlags & INHERITED_ACE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4231 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4232 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4233 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4234 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4235 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4236
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4237 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4238 * Set the ACL of file "fname" to "acl" (unless it's NULL).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4239 * Errors are ignored.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4240 * This must only be called with "acl" equal to what mch_get_acl() returned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4241 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4242 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4243 mch_set_acl(char_u *fname, vim_acl_T acl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4244 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4245 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4246 struct my_acl *p = (struct my_acl *)acl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4247 SECURITY_INFORMATION sec_info = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4248 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4249
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4250 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4251 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4253 wn = enc_to_utf16(fname, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4254 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4255 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4257 // Set security flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4258 if (p->pSidOwner)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4259 sec_info |= OWNER_SECURITY_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4260 if (p->pSidGroup)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4261 sec_info |= GROUP_SECURITY_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4262 if (p->pDacl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4263 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4264 sec_info |= DACL_SECURITY_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4265 // Do not inherit its parent's DACL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4266 // If the DACL is inherited, Cygwin permissions would be changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4267 if (!is_acl_inherited(p->pDacl))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4268 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4269 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4270 if (p->pSacl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4271 sec_info |= SACL_SECURITY_INFORMATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4273 (void)SetNamedSecurityInfoW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4274 wn, // Abstract filename
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4275 SE_FILE_OBJECT, // File Object
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4276 sec_info,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4277 p->pSidOwner, // Ownership information.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4278 p->pSidGroup, // Group membership.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4279 p->pDacl, // Discretionary information.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4280 p->pSacl // For auditing purposes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4281 );
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4282 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4283 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4284 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4285
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4286 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4287 mch_free_acl(vim_acl_T acl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4288 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4289 #ifdef HAVE_ACL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4290 struct my_acl *p = (struct my_acl *)acl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4291
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4292 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4293 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4294 LocalFree(p->pSecurityDescriptor); // Free the memory just in case
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4295 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4296 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4297 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4298 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4300 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4302 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4303 * handler for ctrl-break, ctrl-c interrupts, and fatal events.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4304 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4305 static BOOL WINAPI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4306 handler_routine(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4307 DWORD dwCtrlType)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4308 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4309 INPUT_RECORD ir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4310 DWORD out;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4311
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4312 switch (dwCtrlType)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4313 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4314 case CTRL_C_EVENT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4315 if (ctrl_c_interrupts)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4316 g_fCtrlCPressed = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4317 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4319 case CTRL_BREAK_EVENT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4320 g_fCBrkPressed = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4321 ctrl_break_was_pressed = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4322 // ReadConsoleInput is blocking, send a key event to continue.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4323 ir.EventType = KEY_EVENT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4324 ir.Event.KeyEvent.bKeyDown = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4325 ir.Event.KeyEvent.wRepeatCount = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4326 ir.Event.KeyEvent.wVirtualKeyCode = VK_CANCEL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4327 ir.Event.KeyEvent.wVirtualScanCode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4328 ir.Event.KeyEvent.dwControlKeyState = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4329 ir.Event.KeyEvent.uChar.UnicodeChar = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4330 WriteConsoleInput(g_hConIn, &ir, 1, &out);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4331 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4333 // fatal events: shut down gracefully
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4334 case CTRL_CLOSE_EVENT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4335 case CTRL_LOGOFF_EVENT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4336 case CTRL_SHUTDOWN_EVENT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4337 windgoto((int)Rows - 1, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4338 g_fForceExit = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4339
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4340 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4341 (dwCtrlType == CTRL_CLOSE_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4342 ? _("close")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4343 : dwCtrlType == CTRL_LOGOFF_EVENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4344 ? _("logoff")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4345 : _("shutdown")));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4346 # ifdef DEBUG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4347 OutputDebugString(IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4348 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4349
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4350 preserve_exit(); // output IObuff, preserve files and exit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4351
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4352 return TRUE; // not reached
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4354 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4355 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4356 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4357 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4358
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4360 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4361 * set the tty in (raw) ? "raw" : "cooked" mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4362 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4363 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4364 mch_settmode(tmode_T tmode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4365 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4366 DWORD cmodein;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4367 DWORD cmodeout;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4368 BOOL bEnableHandler;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4369
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4370 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4371 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4372 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4373 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4374 GetConsoleMode(g_hConIn, &cmodein);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4375 GetConsoleMode(g_hConOut, &cmodeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4376 if (tmode == TMODE_RAW)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4377 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4378 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4379 ENABLE_ECHO_INPUT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4380 if (g_fMouseActive)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4381 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4382 cmodein |= ENABLE_MOUSE_INPUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4383 cmodein &= ~ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4384 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4385 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4386 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4387 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4388 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4389 cmodeout &= ~(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4390 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4391 // Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4392 // VTP.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4393 ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4394 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4395 ENABLE_PROCESSED_OUTPUT |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4396 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4397 ENABLE_WRAP_AT_EOL_OUTPUT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4398 bEnableHandler = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4399 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4400 else // cooked
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4401 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4402 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4403 ENABLE_ECHO_INPUT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4404 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4405 bEnableHandler = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4406 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4407 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4408 SetConsoleMode(g_hConOut, cmodeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4409 SetConsoleCtrlHandler(handler_routine, bEnableHandler);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4410
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4411 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4412 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4413 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4414 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4415 tmode == TMODE_RAW ? "raw" :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4416 tmode == TMODE_COOK ? "cooked" : "normal",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4417 cmodein, cmodeout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4418 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4419 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4420 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4421 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4422
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4423
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4424 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4425 * Get the size of the current window in `Rows' and `Columns'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4426 * Return OK when size could be determined, FAIL otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4427 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4428 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4429 mch_get_shellsize(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4430 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4431 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4432
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4433 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4434 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4435 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4436 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4437 if (!g_fTermcapMode && g_cbTermcap.IsValid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4439 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4440 * For some reason, we are trying to get the screen dimensions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4441 * even though we are not in termcap mode. The 'Rows' and 'Columns'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4442 * variables are really intended to mean the size of Vim screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4443 * while in termcap mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4444 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4445 Rows = g_cbTermcap.Info.dwSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4446 Columns = g_cbTermcap.Info.dwSize.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4447 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4448 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4449 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4450 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4451 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4452 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4453 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4454 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4455 Rows = 25;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4456 Columns = 80;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4457 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4458 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4459 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4461 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4462 * Resize console buffer to 'COORD'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4463 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4464 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4465 ResizeConBuf(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4466 HANDLE hConsole,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4467 COORD coordScreen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4468 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4469 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4470 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4471
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4472 if (!SetConsoleScreenBufferSize(hConsole, coordScreen))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4473 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4474 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4475 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4476 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4477 fprintf(fdDump, "SetConsoleScreenBufferSize failed: %lx\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4478 GetLastError());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4479 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4480 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4481 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4482 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4483 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4484
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4485 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4486 * Resize console window size to 'srWindowRect'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4487 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4488 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4489 ResizeWindow(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4490 HANDLE hConsole,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4491 SMALL_RECT srWindowRect)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4492 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4493 if (!SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4494 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4495 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4496 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4497 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4498 fprintf(fdDump, "SetConsoleWindowInfo failed: %lx\n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4499 GetLastError());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4500 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4501 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4502 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4503 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4504 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4505
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4506 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4507 * Set a console window to `xSize' * `ySize'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4508 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4509 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4510 ResizeConBufAndWindow(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4511 HANDLE hConsole,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4512 int xSize,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4513 int ySize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4514 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4515 CONSOLE_SCREEN_BUFFER_INFO csbi; // hold current console buffer info
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4516 SMALL_RECT srWindowRect; // hold the new console size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4517 COORD coordScreen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4518 COORD cursor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4519 static int resized = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4520
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4521 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4522 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4523 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4524 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4525 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4526 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4527 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4528
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4529 // get the largest size we can size the console window to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4530 coordScreen = GetLargestConsoleWindowSize(hConsole);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4531
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4532 // define the new console window size and scroll position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4533 srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4534 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4535 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4537 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4538 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4539 int sx, sy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4540
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4541 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4542 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4543 if (sy < ySize || sx < xSize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4544 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4545 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4546 * Increasing number of lines/columns, do buffer first.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4547 * Use the maximal size in x and y direction.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4548 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4549 if (sy < ySize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4550 coordScreen.Y = ySize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4551 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4552 coordScreen.Y = sy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4553 if (sx < xSize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4554 coordScreen.X = xSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4555 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4556 coordScreen.X = sx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4557 SetConsoleScreenBufferSize(hConsole, coordScreen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4558 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4559 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4560
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4561 // define the new console buffer size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4562 coordScreen.X = xSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4563 coordScreen.Y = ySize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4564
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4565 // In the new console call API, only the first time in reverse order
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4566 if (!vtp_working || resized)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4567 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4568 ResizeWindow(hConsole, srWindowRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4569 ResizeConBuf(hConsole, coordScreen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4570 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4571 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4572 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4573 // Workaround for a Windows 10 bug
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4574 cursor.X = srWindowRect.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4575 cursor.Y = srWindowRect.Top;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4576 SetConsoleCursorPosition(hConsole, cursor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4577
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4578 ResizeConBuf(hConsole, coordScreen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4579 ResizeWindow(hConsole, srWindowRect);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4580 resized = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4581 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4582 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4584
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4585 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4586 * Set the console window to `Rows' * `Columns'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4587 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4588 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4589 mch_set_shellsize(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4590 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4591 COORD coordScreen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4592
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4593 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4594 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4595 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4596 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4597 // Don't change window size while still starting up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4598 if (suppress_winsize != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4599 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4600 suppress_winsize = 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4601 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4602 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4603
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4604 if (term_console)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4605 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4606 coordScreen = GetLargestConsoleWindowSize(g_hConOut);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4607
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4608 // Clamp Rows and Columns to reasonable values
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4609 if (Rows > coordScreen.Y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4610 Rows = coordScreen.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4611 if (Columns > coordScreen.X)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4612 Columns = coordScreen.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4614 ResizeConBufAndWindow(g_hConOut, Columns, Rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4615 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4616 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4617
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4618 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4619 * Rows and/or Columns has changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4620 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4621 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4622 mch_new_shellsize(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4623 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4624 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4625 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4626 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4627 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4628 set_scroll_region(0, 0, Columns - 1, Rows - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4629 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4630
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4631
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4632 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4633 * Called when started up, to set the winsize that was delayed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4634 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4635 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4636 mch_set_winsize_now(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4637 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4638 if (suppress_winsize == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4639 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4640 suppress_winsize = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4641 mch_set_shellsize();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4642 shell_resized();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4643 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4644 suppress_winsize = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4645 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4646 #endif // FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4647
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4648 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4649 vim_create_process(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4650 char *cmd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4651 BOOL inherit_handles,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4652 DWORD flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4653 STARTUPINFO *si,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4654 PROCESS_INFORMATION *pi,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4655 LPVOID *env,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4656 char *cwd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4657 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4658 BOOL ret = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4659 WCHAR *wcmd, *wcwd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4661 wcmd = enc_to_utf16((char_u *)cmd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4662 if (wcmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4663 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4664 if (cwd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4665 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4666 wcwd = enc_to_utf16((char_u *)cwd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4667 if (wcwd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4668 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4669 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4671 ret = CreateProcessW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4672 NULL, // Executable name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4673 wcmd, // Command to execute
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4674 NULL, // Process security attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4675 NULL, // Thread security attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4676 inherit_handles, // Inherit handles
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4677 flags, // Creation flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4678 env, // Environment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4679 wcwd, // Current directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4680 (LPSTARTUPINFOW)si, // Startup information
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4681 pi); // Process information
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4682 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4683 vim_free(wcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4684 vim_free(wcwd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4685 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4686 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4687
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4689 static HINSTANCE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4690 vim_shell_execute(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4691 char *cmd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4692 INT n_show_cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4693 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4694 HINSTANCE ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4695 WCHAR *wcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4696
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4697 wcmd = enc_to_utf16((char_u *)cmd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4698 if (wcmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4699 return (HINSTANCE) 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4700
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4701 ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, n_show_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4702 vim_free(wcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4703 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4704 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4706
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4707 #if defined(FEAT_GUI_MSWIN) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4709 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4710 * Specialised version of system() for Win32 GUI mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4711 * This version proceeds as follows:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4712 * 1. Create a console window for use by the subprocess
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4713 * 2. Run the subprocess (it gets the allocated console by default)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4714 * 3. Wait for the subprocess to terminate and get its exit code
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4715 * 4. Prompt the user to press a key to close the console window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4716 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4717 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4718 mch_system_classic(char *cmd, int options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4719 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4720 STARTUPINFO si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4721 PROCESS_INFORMATION pi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4722 DWORD ret = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4723 HWND hwnd = GetFocus();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4724
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4725 si.cb = sizeof(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4726 si.lpReserved = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4727 si.lpDesktop = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4728 si.lpTitle = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4729 si.dwFlags = STARTF_USESHOWWINDOW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4730 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4731 * It's nicer to run a filter command in a minimized window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4732 * Don't activate the window to keep focus on Vim.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4733 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4734 if (options & SHELL_DOOUT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4735 si.wShowWindow = SW_SHOWMINNOACTIVE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4736 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4737 si.wShowWindow = SW_SHOWNORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4738 si.cbReserved2 = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4739 si.lpReserved2 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4741 // Now, run the command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4742 vim_create_process(cmd, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4743 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4744 &si, &pi, NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4746 // Wait for the command to terminate before continuing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4747 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4748 # ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4749 int delay = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4751 // Keep updating the window while waiting for the shell to finish.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4752 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4753 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4754 MSG msg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4755
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4756 if (PeekMessageW(&msg, (HWND)NULL, 0, 0, PM_REMOVE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4757 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4758 TranslateMessage(&msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4759 DispatchMessageW(&msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4760 delay = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4761 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4762 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4763 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4764 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4765
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4766 // We start waiting for a very short time and then increase it, so
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4767 // that we respond quickly when the process is quick, and don't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4768 // consume too much overhead when it's slow.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4769 if (delay < 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4770 delay += 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4771 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4772 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4773 WaitForSingleObject(pi.hProcess, INFINITE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4774 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4775
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4776 // Get the command exit code
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4777 GetExitCodeProcess(pi.hProcess, &ret);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4778 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4780 // Close the handles to the subprocess, so that it goes away
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4781 CloseHandle(pi.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4782 CloseHandle(pi.hProcess);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4784 // Try to get input focus back. Doesn't always work though.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4785 PostMessage(hwnd, WM_SETFOCUS, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4786
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4787 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4788 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4789
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4790 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4791 * Thread launched by the gui to send the current buffer data to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4792 * process. This way avoid to hang up vim totally if the children
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4793 * process take a long time to process the lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4794 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4795 static unsigned int __stdcall
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4796 sub_process_writer(LPVOID param)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4797 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4798 HANDLE g_hChildStd_IN_Wr = param;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4799 linenr_T lnum = curbuf->b_op_start.lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4800 DWORD len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4801 DWORD l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4802 char_u *lp = ml_get(lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4803 char_u *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4804 int written = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4805
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4806 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4807 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4808 l = (DWORD)STRLEN(lp + written);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4809 if (l == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4810 len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4811 else if (lp[written] == NL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4812 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4813 // NL -> NUL translation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4814 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4815 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4816 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4817 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4818 s = vim_strchr(lp + written, NL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4819 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4820 s == NULL ? l : (DWORD)(s - (lp + written)),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4821 &len, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4822 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4823 if (len == l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4824 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4825 // Finished a line, add a NL, unless this line should not have
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4826 // one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4827 if (lnum != curbuf->b_op_end.lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4828 || (!curbuf->b_p_bin
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4829 && curbuf->b_p_fixeol)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4830 || (lnum != curbuf->b_no_eol_lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4831 && (lnum != curbuf->b_ml.ml_line_count
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4832 || curbuf->b_p_eol)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4833 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4834 WriteFile(g_hChildStd_IN_Wr, "\n", 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4835 (LPDWORD)&vim_ignored, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4836 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4838 ++lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4839 if (lnum > curbuf->b_op_end.lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4840 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4842 lp = ml_get(lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4843 written = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4844 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4845 else if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4846 written += len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4847 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4848
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4849 // finished all the lines, close pipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4850 CloseHandle(g_hChildStd_IN_Wr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4851 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4852 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4853
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4854
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4855 # define BUFLEN 100 // length for buffer, stolen from unix version
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4856
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4857 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4858 * This function read from the children's stdout and write the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4859 * data on screen or in the buffer accordingly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4860 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4861 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4862 dump_pipe(int options,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4863 HANDLE g_hChildStd_OUT_Rd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4864 garray_T *ga,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4865 char_u buffer[],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4866 DWORD *buffer_off)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4867 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4868 DWORD availableBytes = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4869 DWORD i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4870 int ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4871 DWORD len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4872 DWORD toRead;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4874 // we query the pipe to see if there is any data to read
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4875 // to avoid to perform a blocking read
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4876 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, // pipe to query
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4877 NULL, // optional buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4878 0, // buffer size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4879 NULL, // number of read bytes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4880 &availableBytes, // available bytes total
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4881 NULL); // byteLeft
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4882
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4883 // We got real data in the pipe, read it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4884 while (ret != 0 && availableBytes > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4885 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4886 toRead = (DWORD)(BUFLEN - *buffer_off);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4887 toRead = availableBytes < toRead ? availableBytes : toRead;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4888 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4890 // If we haven't read anything, there is a problem
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4891 if (len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4892 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4893
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4894 availableBytes -= len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4896 if (options & SHELL_READ)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4897 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4898 // Do NUL -> NL translation, append NL separated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4899 // lines to the current buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4900 for (i = 0; i < len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4901 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4902 if (buffer[i] == NL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4903 append_ga_line(ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4904 else if (buffer[i] == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4905 ga_append(ga, NL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4906 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4907 ga_append(ga, buffer[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4908 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4909 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4910 else if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4911 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4912 int l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4913 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4914 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4916 len += *buffer_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4917 buffer[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4918
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4919 // Check if the last character in buffer[] is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4920 // incomplete, keep these bytes for the next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4921 // round.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4922 for (p = buffer; p < buffer + len; p += l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4923 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4924 l = MB_CPTR2LEN(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4925 if (l == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4926 l = 1; // NUL byte?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4927 else if (MB_BYTE2LEN(*p) != l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4928 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4929 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4930 if (p == buffer) // no complete character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4931 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4932 // avoid getting stuck at an illegal byte
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4933 if (len >= 12)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4934 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4935 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4936 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4937 *buffer_off = len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4938 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4939 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4940 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4941 c = *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4942 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4943 msg_puts((char *)buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4944 if (p < buffer + len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4945 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4946 *p = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4947 *buffer_off = (DWORD)((buffer + len) - p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4948 mch_memmove(buffer, p, *buffer_off);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4949 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4950 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4951 *buffer_off = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4952 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4953 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4954 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4955 buffer[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4956 msg_puts((char *)buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4957 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4958
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4959 windgoto(msg_row, msg_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4960 cursor_on();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4961 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4962 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4963 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4964
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4965 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4966 * Version of system to use for windows NT > 5.0 (Win2K), use pipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4967 * for communication and doesn't open any new window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4968 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4969 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4970 mch_system_piped(char *cmd, int options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4971 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4972 STARTUPINFO si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4973 PROCESS_INFORMATION pi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4974 DWORD ret = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4975
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4976 HANDLE g_hChildStd_IN_Rd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4977 HANDLE g_hChildStd_IN_Wr = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4978 HANDLE g_hChildStd_OUT_Rd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4979 HANDLE g_hChildStd_OUT_Wr = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4980
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4981 char_u buffer[BUFLEN + 1]; // reading buffer + size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4982 DWORD len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4983
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4984 // buffer used to receive keys
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4985 char_u ta_buf[BUFLEN + 1]; // TypeAHead
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4986 int ta_len = 0; // valid bytes in ta_buf[]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4988 DWORD i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4989 int noread_cnt = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4990 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4991 int delay = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4992 DWORD buffer_off = 0; // valid bytes in buffer[]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4993 char *p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4994
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4995 SECURITY_ATTRIBUTES saAttr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4997 // Set the bInheritHandle flag so pipe handles are inherited.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4998 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
4999 saAttr.bInheritHandle = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5000 saAttr.lpSecurityDescriptor = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5002 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5003 // Ensure the read handle to the pipe for STDOUT is not inherited.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5004 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5005 // Create a pipe for the child process's STDIN.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5006 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5007 // Ensure the write handle to the pipe for STDIN is not inherited.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5008 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5009 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5010 CloseHandle(g_hChildStd_IN_Rd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5011 CloseHandle(g_hChildStd_IN_Wr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5012 CloseHandle(g_hChildStd_OUT_Rd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5013 CloseHandle(g_hChildStd_OUT_Wr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5014 msg_puts(_("\nCannot create pipes\n"));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5015 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5016
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5017 si.cb = sizeof(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5018 si.lpReserved = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5019 si.lpDesktop = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5020 si.lpTitle = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5021 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5022
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5023 // set-up our file redirection
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5024 si.hStdError = g_hChildStd_OUT_Wr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5025 si.hStdOutput = g_hChildStd_OUT_Wr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5026 si.hStdInput = g_hChildStd_IN_Rd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5027 si.wShowWindow = SW_HIDE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5028 si.cbReserved2 = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5029 si.lpReserved2 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5030
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5031 if (options & SHELL_READ)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5032 ga_init2(&ga, 1, BUFLEN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5034 if (cmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5035 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5036 p = (char *)vim_strsave((char_u *)cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5037 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5038 unescape_shellxquote((char_u *)p, p_sxe);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5039 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5040 p = cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5041 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5043 // Now, run the command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5044 // About "Inherit handles" being TRUE: this command can be litigious,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5045 // handle inheritance was deactivated for pending temp file, but, if we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5046 // deactivate it, the pipes don't work for some reason.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5047 vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5048 &si, &pi, NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5050 if (p != cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5051 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5052
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5053 // Close our unused side of the pipes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5054 CloseHandle(g_hChildStd_IN_Rd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5055 CloseHandle(g_hChildStd_OUT_Wr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5056
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5057 if (options & SHELL_WRITE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5058 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5059 HANDLE thread = (HANDLE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5060 _beginthreadex(NULL, // security attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5061 0, // default stack size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5062 sub_process_writer, // function to be executed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5063 g_hChildStd_IN_Wr, // parameter
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5064 0, // creation flag, start immediately
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5065 NULL); // we don't care about thread id
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5066 CloseHandle(thread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5067 g_hChildStd_IN_Wr = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5068 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5069
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5070 // Keep updating the window while waiting for the shell to finish.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5071 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5072 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5073 MSG msg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5074
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5075 if (PeekMessageW(&msg, (HWND)NULL, 0, 0, PM_REMOVE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5076 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5077 TranslateMessage(&msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5078 DispatchMessageW(&msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5079 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5081 // write pipe information in the window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5082 if ((options & (SHELL_READ|SHELL_WRITE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5083 # ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5084 || gui.in_use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5085 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5086 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5087 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5088 len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5089 if (!(options & SHELL_EXPAND)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5090 && ((options &
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5091 (SHELL_READ|SHELL_WRITE|SHELL_COOKED))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5092 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5093 # ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5094 || gui.in_use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5095 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5096 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5097 && (ta_len > 0 || noread_cnt > 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5098 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5099 if (ta_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5100 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5101 // Get extra characters when we don't have any. Reset the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5102 // counter and timer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5103 noread_cnt = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5104 len = ui_inchar(ta_buf, BUFLEN, 10L, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5105 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5106 if (ta_len > 0 || len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5107 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5108 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5109 * For pipes: Check for CTRL-C: send interrupt signal to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5110 * child. Check for CTRL-D: EOF, close pipe to child.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5111 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5112 if (len == 1 && cmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5113 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5114 if (ta_buf[ta_len] == Ctrl_C)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5115 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5116 // Learn what exit code is expected, for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5117 // now put 9 as SIGKILL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5118 TerminateProcess(pi.hProcess, 9);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5119 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5120 if (ta_buf[ta_len] == Ctrl_D)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5121 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5122 CloseHandle(g_hChildStd_IN_Wr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5123 g_hChildStd_IN_Wr = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5124 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5125 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5126
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5127 len = term_replace_keycodes(ta_buf, ta_len, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5128
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5129 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5130 * For pipes: echo the typed characters. For a pty this
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5131 * does not seem to work.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5132 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5133 for (i = ta_len; i < ta_len + len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5134 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5135 if (ta_buf[i] == '\n' || ta_buf[i] == '\b')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5136 msg_putchar(ta_buf[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5137 else if (has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5138 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5139 int l = (*mb_ptr2len)(ta_buf + i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5141 msg_outtrans_len(ta_buf + i, l);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5142 i += l - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5143 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5144 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5145 msg_outtrans_len(ta_buf + i, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5146 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5147 windgoto(msg_row, msg_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5148 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5150 ta_len += len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5152 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5153 * Write the characters to the child, unless EOF has been
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5154 * typed for pipes. Write one character at a time, to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5155 * avoid losing too much typeahead. When writing buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5156 * lines, drop the typed characters (only check for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5157 * CTRL-C).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5158 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5159 if (options & SHELL_WRITE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5160 ta_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5161 else if (g_hChildStd_IN_Wr != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5162 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5163 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5164 1, &len, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5165 // if we are typing in, we want to keep things reactive
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5166 delay = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5167 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5168 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5169 ta_len -= len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5170 mch_memmove(ta_buf, ta_buf + len, ta_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5171 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5172 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5173 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5174 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5175 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5177 if (ta_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5178 ui_inchar_undo(ta_buf, ta_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5180 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5181 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5182 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5183 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5184 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5186 ++noread_cnt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5187 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5189 // We start waiting for a very short time and then increase it, so
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5190 // that we respond quickly when the process is quick, and don't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5191 // consume too much overhead when it's slow.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5192 if (delay < 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5193 delay += 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5194 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5196 // Close the pipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5197 CloseHandle(g_hChildStd_OUT_Rd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5198 if (g_hChildStd_IN_Wr != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5199 CloseHandle(g_hChildStd_IN_Wr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5201 WaitForSingleObject(pi.hProcess, INFINITE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5203 // Get the command exit code
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5204 GetExitCodeProcess(pi.hProcess, &ret);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5206 if (options & SHELL_READ)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5207 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5208 if (ga.ga_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5209 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5210 append_ga_line(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5211 // remember that the NL was missing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5212 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5213 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5214 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5215 curbuf->b_no_eol_lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5216 ga_clear(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5217 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5219 // Close the handles to the subprocess, so that it goes away
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5220 CloseHandle(pi.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5221 CloseHandle(pi.hProcess);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5222
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5223 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5224 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5225
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5226 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5227 mch_system_g(char *cmd, int options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5228 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5229 // if we can pipe and the shelltemp option is off
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5230 if (!p_stmp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5231 return mch_system_piped(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5232 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5233 return mch_system_classic(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5234 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5235 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5236
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5237 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5238 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5239 mch_system_c(char *cmd, int options UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5240 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5241 int ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5242 WCHAR *wcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5243 char_u *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5244 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5245
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5246 // If the command starts and ends with double quotes, enclose the command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5247 // in parentheses.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5248 len = STRLEN(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5249 if (len >= 2 && cmd[0] == '"' && cmd[len - 1] == '"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5250 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5251 len += 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5252 buf = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5253 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5254 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5255 vim_snprintf((char *)buf, len, "(%s)", cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5256 wcmd = enc_to_utf16(buf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5257 free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5258 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5259 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5260 wcmd = enc_to_utf16((char_u *)cmd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5261
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5262 if (wcmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5263 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5265 ret = _wsystem(wcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5266 vim_free(wcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5267 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5268 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5270 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5271
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5272 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5273 mch_system(char *cmd, int options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5274 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5275 #ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5276 if (gui.in_use || gui.starting)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5277 return mch_system_g(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5278 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5279 return mch_system_c(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5280 #elif defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5281 return mch_system_g(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5282 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5283 return mch_system_c(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5284 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5285 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5287 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5288 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5289 * Use a terminal window to run a shell command in.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5290 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5291 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5292 mch_call_shell_terminal(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5293 char_u *cmd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5294 int options UNUSED) // SHELL_*, see vim.h
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5295 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5296 jobopt_T opt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5297 char_u *newcmd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5298 typval_T argvar[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5299 long_u cmdlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5300 int retval = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5301 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5302 job_T *job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5303 aco_save_T aco;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5304 oparg_T oa; // operator arguments
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5306 if (cmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5307 cmdlen = STRLEN(p_sh) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5308 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5309 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5310 newcmd = alloc(cmdlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5311 if (newcmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5312 return 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5313 if (cmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5314 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5315 STRCPY(newcmd, p_sh);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5316 ch_log(NULL, "starting terminal to run a shell");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5318 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5319 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5320 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5321 ch_log(NULL, "starting terminal for system command '%s'", cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5322 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5324 init_job_options(&opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5326 argvar[0].v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5327 argvar[0].vval.v_string = newcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5328 argvar[1].v_type = VAR_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5329 buf = term_start(argvar, NULL, &opt, TERM_START_SYSTEM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5330 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5331 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5332 vim_free(newcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5333 return 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5334 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5335
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5336 job = term_getjob(buf->b_term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5337 ++job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5338
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5339 // Find a window to make "buf" curbuf.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5340 aucmd_prepbuf(&aco, buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5341 if (curbuf == buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5342 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5343 // Only do this when a window was found for "buf".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5344 clear_oparg(&oa);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5345 while (term_use_loop())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5346 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5347 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5348 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5349 // If terminal_loop() returns OK we got a key that is handled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5350 // in Normal model. We don't do redrawing anyway.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5351 if (terminal_loop(TRUE) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5352 normal_cmd(&oa, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5353 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5354 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5355 normal_cmd(&oa, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5356 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5357 retval = job->jv_exitval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5358 ch_log(NULL, "system command finished");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5360 job_unref(job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5361
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5362 // restore curwin/curbuf and a few other things
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5363 aucmd_restbuf(&aco);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5364 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5365
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5366 wait_return(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5367 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5368
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5369 vim_free(newcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5370 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5371 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5372 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5373
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5374 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5375 * Either execute a command by calling the shell or start a new shell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5376 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5377 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5378 mch_call_shell(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5379 char_u *cmd,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5380 int options) // SHELL_*, see vim.h
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5381 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5382 int x = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5383 int tmode = cur_tmode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5384 WCHAR szShellTitle[512];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5385
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5386 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5387 ch_log(NULL, "executing shell command: %s", cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5388 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5389 // Change the title to reflect that we are in a subshell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5390 if (GetConsoleTitleW(szShellTitle, ARRAY_LENGTH(szShellTitle) - 4) > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5391 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5392 if (cmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5393 wcscat(szShellTitle, L" :sh");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5394 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5395 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5396 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5397
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5398 if (wn != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5399 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5400 wcscat(szShellTitle, L" - !");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5401 if ((wcslen(szShellTitle) + wcslen(wn) <
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5402 ARRAY_LENGTH(szShellTitle)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5403 wcscat(szShellTitle, wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5404 SetConsoleTitleW(szShellTitle);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5405 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5406 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5407 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5408 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5409
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5410 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5412 #ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5413 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5414 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5415 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5416 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5417 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5418 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5419 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5420 // TODO: make the terminal window work with input or output redirected.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5421 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5422 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5423 gui.in_use &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5424 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5425 vim_strchr(p_go, GO_TERMINAL) != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5426 && (options & (SHELL_FILTER|SHELL_DOOUT|SHELL_WRITE|SHELL_READ)) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5427 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5428 char_u *cmdbase = cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5430 if (cmdbase != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5431 // Skip a leading quote and (.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5432 while (*cmdbase == '"' || *cmdbase == '(')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5433 ++cmdbase;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5435 // Check the command does not begin with "start "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5436 if (cmdbase == NULL || STRNICMP(cmdbase, "start", 5) != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5437 || !VIM_ISWHITE(cmdbase[5]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5439 // Use a terminal window to run the command in.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5440 x = mch_call_shell_terminal(cmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5441 resettitle();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5442 return x;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5443 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5444 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5445 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5447 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5448 * Catch all deadly signals while running the external command, because a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5449 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5450 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5451 mch_signal(SIGINT, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5452 #if defined(__GNUC__) && !defined(__MINGW32__)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5453 mch_signal(SIGKILL, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5454 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5455 mch_signal(SIGBREAK, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5456 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5457 mch_signal(SIGILL, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5458 mch_signal(SIGFPE, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5459 mch_signal(SIGSEGV, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5460 mch_signal(SIGTERM, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5461 mch_signal(SIGABRT, SIG_IGN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5463 if (options & SHELL_COOKED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5464 settmode(TMODE_COOK); // set to normal mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5465
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5466 if (cmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5467 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5468 x = mch_system((char *)p_sh, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5469 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5470 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5471 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5472 // we use "command" or "cmd" to start the shell; slow but easy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5473 char_u *newcmd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5474 char_u *cmdbase = cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5475 long_u cmdlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5476
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5477 // Skip a leading ", ( and "(.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5478 if (*cmdbase == '"' )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5479 ++cmdbase;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5480 if (*cmdbase == '(')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5481 ++cmdbase;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5483 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5484 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5485 STARTUPINFO si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5486 PROCESS_INFORMATION pi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5487 DWORD flags = CREATE_NEW_CONSOLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5488 INT n_show_cmd = SW_SHOWNORMAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5489 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5491 ZeroMemory(&si, sizeof(si));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5492 si.cb = sizeof(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5493 si.lpReserved = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5494 si.lpDesktop = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5495 si.lpTitle = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5496 si.dwFlags = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5497 si.cbReserved2 = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5498 si.lpReserved2 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5499
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5500 cmdbase = skipwhite(cmdbase + 5);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5501 if ((STRNICMP(cmdbase, "/min", 4) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5502 && VIM_ISWHITE(cmdbase[4]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5503 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5504 cmdbase = skipwhite(cmdbase + 4);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5505 si.dwFlags = STARTF_USESHOWWINDOW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5506 si.wShowWindow = SW_SHOWMINNOACTIVE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5507 n_show_cmd = SW_SHOWMINNOACTIVE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5508 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5509 else if ((STRNICMP(cmdbase, "/b", 2) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5510 && VIM_ISWHITE(cmdbase[2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5511 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5512 cmdbase = skipwhite(cmdbase + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5513 flags = CREATE_NO_WINDOW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5514 si.dwFlags = STARTF_USESTDHANDLES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5515 si.hStdInput = CreateFile("\\\\.\\NUL", // File name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5516 GENERIC_READ, // Access flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5517 0, // Share flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5518 NULL, // Security att.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5519 OPEN_EXISTING, // Open flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5520 FILE_ATTRIBUTE_NORMAL, // File att.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5521 NULL); // Temp file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5522 si.hStdOutput = si.hStdInput;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5523 si.hStdError = si.hStdInput;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5524 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5525
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5526 // Remove a trailing ", ) and )" if they have a match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5527 // at the start of the command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5528 if (cmdbase > cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5529 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5530 p = cmdbase + STRLEN(cmdbase);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5531 if (p > cmdbase && p[-1] == '"' && *cmd == '"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5532 *--p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5533 if (p > cmdbase && p[-1] == ')'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5534 && (*cmd =='(' || cmd[1] == '('))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5535 *--p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5536 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5538 newcmd = cmdbase;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5539 unescape_shellxquote(cmdbase, p_sxe);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5540
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5541 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5542 * If creating new console, arguments are passed to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5543 * 'cmd.exe' as-is. If it's not, arguments are not treated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5544 * correctly for current 'cmd.exe'. So unescape characters in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5545 * shellxescape except '|' for avoiding to be treated as
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5546 * argument to them. Pass the arguments to sub-shell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5547 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5548 if (flags != CREATE_NEW_CONSOLE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5549 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5550 char_u *subcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5551 char_u *cmd_shell = mch_getenv("COMSPEC");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5553 if (cmd_shell == NULL || *cmd_shell == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5554 cmd_shell = (char_u *)default_shell();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5555
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5556 subcmd = vim_strsave_escaped_ext(cmdbase,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5557 (char_u *)"|", '^', FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5558 if (subcmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5560 // make "cmd.exe /c arguments"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5561 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5562 newcmd = alloc(cmdlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5563 if (newcmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5564 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5565 cmd_shell, subcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5566 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5567 newcmd = cmdbase;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5568 vim_free(subcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5569 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5570 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5571
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5572 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5573 * Now, start the command as a process, so that it doesn't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5574 * inherit our handles which causes unpleasant dangling swap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5575 * files if we exit before the spawned process
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5576 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5577 if (vim_create_process((char *)newcmd, FALSE, flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5578 &si, &pi, NULL, NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5579 x = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5580 else if (vim_shell_execute((char *)newcmd, n_show_cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5581 > (HINSTANCE)32)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5582 x = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5583 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5584 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5585 x = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5586 #ifdef FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5587 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5588 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5589 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5590 emsg(_(e_command_not_found));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5591 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5592 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5594 if (newcmd != cmdbase)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5595 vim_free(newcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5597 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5598 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5599 // Close the handle to \\.\NUL created above.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5600 CloseHandle(si.hStdInput);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5602 // Close the handles to the subprocess, so that it goes away
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5603 CloseHandle(pi.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5604 CloseHandle(pi.hProcess);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5605 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5606 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5607 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5608 cmdlen =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5609 #ifdef FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5610 ((gui.in_use || gui.starting) ?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5611 (!s_dont_use_vimrun && p_stmp ?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5612 STRLEN(vimrun_path) : STRLEN(p_sh) + STRLEN(p_shcf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5613 : 0) +
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5614 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5615 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5617 newcmd = alloc(cmdlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5618 if (newcmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5619 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5620 #if defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5621 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5622 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5623 (gui.in_use || gui.starting) &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5624 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5625 need_vimrun_warning)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5626 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5627 char *msg = _("VIMRUN.EXE not found in your $PATH.\n"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5628 "External commands will not pause after completion.\n"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5629 "See :help win32-vimrun for more information.");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5630 char *title = _("Vim Warning");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5631 WCHAR *wmsg = enc_to_utf16((char_u *)msg, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5632 WCHAR *wtitle = enc_to_utf16((char_u *)title, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5634 if (wmsg != NULL && wtitle != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5635 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5636 vim_free(wmsg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5637 vim_free(wtitle);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5638 need_vimrun_warning = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5639 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5640 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5641 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5642 (gui.in_use || gui.starting) &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5643 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5644 !s_dont_use_vimrun && p_stmp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5645 // Use vimrun to execute the command. It opens a console
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5646 // window, which can be closed without killing Vim.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5647 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5648 vimrun_path,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5649 (msg_silent != 0 || (options & SHELL_DOOUT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5650 ? "-s " : "",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5651 p_sh, p_shcf, cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5652 else if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5653 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5654 (gui.in_use || gui.starting) &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5655 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5656 s_dont_use_vimrun && STRCMP(p_shcf, "/c") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5657 // workaround for the case that "vimrun" does not exist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5658 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s %s %s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5659 p_sh, p_shcf, p_sh, p_shcf, cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5660 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5661 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5662 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5663 p_sh, p_shcf, cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5664 x = mch_system((char *)newcmd, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5665 vim_free(newcmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5666 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5667 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5668 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5670 if (tmode == TMODE_RAW)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5671 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5672 // The shell may have messed with the mode, always set it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5673 cur_tmode = TMODE_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5674 settmode(TMODE_RAW); // set to raw mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5675 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5676
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5677 // Print the return value, unless "vimrun" was used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5678 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5679 #if defined(FEAT_GUI_MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5680 && ((gui.in_use || gui.starting) ?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5681 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5682 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5683 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5684 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5685 smsg(_("shell returned %d"), x);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5686 msg_putchar('\n');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5687 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5688 resettitle();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5689
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5690 mch_signal(SIGINT, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5691 #if defined(__GNUC__) && !defined(__MINGW32__)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5692 mch_signal(SIGKILL, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5693 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5694 mch_signal(SIGBREAK, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5695 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5696 mch_signal(SIGILL, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5697 mch_signal(SIGFPE, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5698 mch_signal(SIGSEGV, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5699 mch_signal(SIGTERM, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5700 mch_signal(SIGABRT, SIG_DFL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5701
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5702 return x;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5703 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5704
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5705 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5706 static HANDLE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5707 job_io_file_open(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5708 char_u *fname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5709 DWORD dwDesiredAccess,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5710 DWORD dwShareMode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5711 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5712 DWORD dwCreationDisposition,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5713 DWORD dwFlagsAndAttributes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5714 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5715 HANDLE h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5716 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5717
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5718 wn = enc_to_utf16(fname, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5719 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5720 return INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5722 h = CreateFileW(wn, dwDesiredAccess, dwShareMode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5723 lpSecurityAttributes, dwCreationDisposition,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5724 dwFlagsAndAttributes, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5725 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5726 return h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5727 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5728
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5729 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5730 * Turn the dictionary "env" into a NUL separated list that can be used as the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5731 * environment argument of vim_create_process().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5732 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5733 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5734 win32_build_env(dict_T *env, garray_T *gap, int is_terminal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5735 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5736 hashitem_T *hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5737 long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5738 LPVOID base = GetEnvironmentStringsW();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5739
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5740 // for last \0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5741 if (ga_grow(gap, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5742 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5744 if (env != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5745 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5746 FOR_ALL_HASHTAB_ITEMS(&env->dv_hashtab, hi, todo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5747 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5748 if (!HASHITEM_EMPTY(hi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5749 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5750 typval_T *item = &dict_lookup(hi)->di_tv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5751 WCHAR *wkey = enc_to_utf16((char_u *)hi->hi_key, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5752 WCHAR *wval = enc_to_utf16(tv_get_string(item), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5753 --todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5754 if (wkey != NULL && wval != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5755 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5756 size_t n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5757 size_t lkey = wcslen(wkey);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5758 size_t lval = wcslen(wval);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5759
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5760 if (ga_grow(gap, (int)(lkey + lval + 2)) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5761 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5762 for (n = 0; n < lkey; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5763 *((WCHAR*)gap->ga_data + gap->ga_len++) = wkey[n];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5764 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'=';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5765 for (n = 0; n < lval; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5766 *((WCHAR*)gap->ga_data + gap->ga_len++) = wval[n];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5767 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5768 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5769 vim_free(wkey);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5770 vim_free(wval);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5771 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5772 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5773 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5774
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5775 if (base)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5776 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5777 WCHAR *p = (WCHAR*) base;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5778
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5779 // for last \0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5780 if (ga_grow(gap, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5781 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5782
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5783 while (*p != 0 || *(p + 1) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5784 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5785 if (ga_grow(gap, 1) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5786 *((WCHAR*)gap->ga_data + gap->ga_len++) = *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5787 p++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5788 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5789 FreeEnvironmentStrings(base);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5790 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5791 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5793 # if defined(FEAT_CLIENTSERVER) || defined(FEAT_TERMINAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5794 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5795 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5796 char_u *servername = get_vim_var_str(VV_SEND_SERVER);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5797 size_t servername_len = STRLEN(servername);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5798 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5799 # ifdef FEAT_TERMINAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5800 char_u *version = get_vim_var_str(VV_VERSION);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5801 size_t version_len = STRLEN(version);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5802 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5803 // size of "VIM_SERVERNAME=" and value,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5804 // plus "VIM_TERMINAL=" and value,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5805 // plus two terminating NULs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5806 size_t n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5807 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5808 + 15 + servername_len
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5809 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5810 # ifdef FEAT_TERMINAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5811 + 13 + version_len + 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5812 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5813 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5815 if (ga_grow(gap, (int)n) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5816 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5817 # ifdef FEAT_CLIENTSERVER
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5818 for (n = 0; n < 15; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5819 *((WCHAR*)gap->ga_data + gap->ga_len++) =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5820 (WCHAR)"VIM_SERVERNAME="[n];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5821 for (n = 0; n < servername_len; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5822 *((WCHAR*)gap->ga_data + gap->ga_len++) =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5823 (WCHAR)servername[n];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5824 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5825 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5826 # ifdef FEAT_TERMINAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5827 if (is_terminal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5828 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5829 for (n = 0; n < 13; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5830 *((WCHAR*)gap->ga_data + gap->ga_len++) =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5831 (WCHAR)"VIM_TERMINAL="[n];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5832 for (n = 0; n < version_len; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5833 *((WCHAR*)gap->ga_data + gap->ga_len++) =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5834 (WCHAR)version[n];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5835 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5836 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5837 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5838 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5839 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5840 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5841 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5843 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5844 * Create a pair of pipes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5845 * Return TRUE for success, FALSE for failure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5846 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5847 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5848 create_pipe_pair(HANDLE handles[2])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5849 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5850 static LONG s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5851 char name[64];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5852 SECURITY_ATTRIBUTES sa;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5853
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5854 sprintf(name, "\\\\?\\pipe\\vim-%08lx-%08lx",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5855 GetCurrentProcessId(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5856 InterlockedIncrement(&s));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5857
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5858 // Create named pipe. Max size of named pipe is 65535.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5859 handles[1] = CreateNamedPipe(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5860 name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5861 PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5862 PIPE_TYPE_BYTE | PIPE_NOWAIT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5863 1, MAX_NAMED_PIPE_SIZE, 0, 0, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5864
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5865 if (handles[1] == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5866 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5867
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5868 sa.nLength = sizeof(sa);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5869 sa.bInheritHandle = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5870 sa.lpSecurityDescriptor = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5872 handles[0] = CreateFile(name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5873 FILE_GENERIC_READ,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5874 FILE_SHARE_READ, &sa,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5875 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5876
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5877 if (handles[0] == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5878 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5879 CloseHandle(handles[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5880 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5881 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5882
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5883 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5884 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5885
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5886 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5887 mch_job_start(char *cmd, job_T *job, jobopt_T *options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5888 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5889 STARTUPINFO si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5890 PROCESS_INFORMATION pi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5891 HANDLE jo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5892 SECURITY_ATTRIBUTES saAttr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5893 channel_T *channel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5894 HANDLE ifd[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5895 HANDLE ofd[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5896 HANDLE efd[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5897 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5899 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5900 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5901 int use_null_for_err = options->jo_io[PART_ERR] == JIO_NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5902 int use_file_for_in = options->jo_io[PART_IN] == JIO_FILE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5903 int use_file_for_out = options->jo_io[PART_OUT] == JIO_FILE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5904 int use_file_for_err = options->jo_io[PART_ERR] == JIO_FILE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5905 int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5906
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5907 if (use_out_for_err && use_null_for_out)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5908 use_null_for_err = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5909
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5910 ifd[0] = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5911 ifd[1] = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5912 ofd[0] = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5913 ofd[1] = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5914 efd[0] = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5915 efd[1] = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5916 ga_init2(&ga, sizeof(wchar_t), 500);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5917
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5918 jo = CreateJobObject(NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5919 if (jo == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5920 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5921 job->jv_status = JOB_FAILED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5922 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5923 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5924
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5925 if (options->jo_env != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5926 win32_build_env(options->jo_env, &ga, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5927
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5928 ZeroMemory(&pi, sizeof(pi));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5929 ZeroMemory(&si, sizeof(si));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5930 si.cb = sizeof(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5931 si.dwFlags |= STARTF_USESHOWWINDOW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5932 si.wShowWindow = SW_HIDE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5934 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5935 saAttr.bInheritHandle = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5936 saAttr.lpSecurityDescriptor = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5937
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5938 if (use_file_for_in)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5939 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5940 char_u *fname = options->jo_io_name[PART_IN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5942 ifd[0] = job_io_file_open(fname, GENERIC_READ,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5943 FILE_SHARE_READ | FILE_SHARE_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5944 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5945 if (ifd[0] == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5946 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5947 semsg(_(e_cant_open_file_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5948 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5949 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5950 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5951 else if (!use_null_for_in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5952 && (!create_pipe_pair(ifd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5953 || !SetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5954 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5956 if (use_file_for_out)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5957 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5958 char_u *fname = options->jo_io_name[PART_OUT];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5959
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5960 ofd[1] = job_io_file_open(fname, GENERIC_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5961 FILE_SHARE_READ | FILE_SHARE_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5962 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5963 if (ofd[1] == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5964 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5965 semsg(_(e_cant_open_file_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5966 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5967 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5968 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5969 else if (!use_null_for_out &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5970 (!CreatePipe(&ofd[0], &ofd[1], &saAttr, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5971 || !SetHandleInformation(ofd[0], HANDLE_FLAG_INHERIT, 0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5972 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5973
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5974 if (use_file_for_err)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5975 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5976 char_u *fname = options->jo_io_name[PART_ERR];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5977
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5978 efd[1] = job_io_file_open(fname, GENERIC_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5979 FILE_SHARE_READ | FILE_SHARE_WRITE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5980 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5981 if (efd[1] == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5982 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5983 semsg(_(e_cant_open_file_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5984 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5985 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5986 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5987 else if (!use_out_for_err && !use_null_for_err &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5988 (!CreatePipe(&efd[0], &efd[1], &saAttr, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5989 || !SetHandleInformation(efd[0], HANDLE_FLAG_INHERIT, 0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5990 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5991
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5992 si.dwFlags |= STARTF_USESTDHANDLES;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5993 si.hStdInput = ifd[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5994 si.hStdOutput = ofd[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5995 si.hStdError = use_out_for_err ? ofd[1] : efd[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5997 if (!use_null_for_in || !use_null_for_out || !use_null_for_err)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5998 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
5999 if (options->jo_set & JO_CHANNEL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6000 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6001 channel = options->jo_channel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6002 if (channel != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6003 ++channel->ch_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6004 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6005 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6006 channel = add_channel();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6007 if (channel == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6008 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6009 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6011 if (!vim_create_process(cmd, TRUE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6012 CREATE_SUSPENDED |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6013 CREATE_DEFAULT_ERROR_MODE |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6014 CREATE_NEW_PROCESS_GROUP |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6015 CREATE_UNICODE_ENVIRONMENT |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6016 CREATE_NEW_CONSOLE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6017 &si, &pi,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6018 ga.ga_data,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6019 (char *)options->jo_cwd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6020 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6021 CloseHandle(jo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6022 job->jv_status = JOB_FAILED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6023 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6024 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6026 ga_clear(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6028 if (!AssignProcessToJobObject(jo, pi.hProcess))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6029 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6030 // if failing, switch the way to terminate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6031 // process with TerminateProcess.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6032 CloseHandle(jo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6033 jo = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6034 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6035 ResumeThread(pi.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6036 CloseHandle(pi.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6037 job->jv_proc_info = pi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6038 job->jv_job_object = jo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6039 job->jv_status = JOB_STARTED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6040
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6041 CloseHandle(ifd[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6042 CloseHandle(ofd[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6043 if (!use_out_for_err && !use_null_for_err)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6044 CloseHandle(efd[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6045
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6046 job->jv_channel = channel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6047 if (channel != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6048 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6049 channel_set_pipes(channel,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6050 use_file_for_in || use_null_for_in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6051 ? INVALID_FD : (sock_T)ifd[1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6052 use_file_for_out || use_null_for_out
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6053 ? INVALID_FD : (sock_T)ofd[0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6054 use_out_for_err || use_file_for_err || use_null_for_err
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6055 ? INVALID_FD : (sock_T)efd[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6056 channel_set_job(channel, job, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6057 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6058 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6059
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6060 failed:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6061 CloseHandle(ifd[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6062 CloseHandle(ofd[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6063 CloseHandle(efd[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6064 CloseHandle(ifd[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6065 CloseHandle(ofd[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6066 CloseHandle(efd[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6067 channel_unref(channel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6068 ga_clear(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6069 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6070
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6071 char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6072 mch_job_status(job_T *job)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6073 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6074 DWORD dwExitCode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6076 if (!GetExitCodeProcess(job->jv_proc_info.hProcess, &dwExitCode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6077 || dwExitCode != STILL_ACTIVE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6078 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6079 job->jv_exitval = (int)dwExitCode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6080 if (job->jv_status < JOB_ENDED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6081 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6082 ch_log(job->jv_channel, "Job ended");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6083 job->jv_status = JOB_ENDED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6084 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6085 return "dead";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6086 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6087 return "run";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6088 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6089
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6090 job_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6091 mch_detect_ended_job(job_T *job_list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6092 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6093 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6094 job_T *jobArray[MAXIMUM_WAIT_OBJECTS];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6095 job_T *job = job_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6096
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6097 while (job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6098 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6099 DWORD n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6100 DWORD result;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6101
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6102 for (n = 0; n < MAXIMUM_WAIT_OBJECTS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6103 && job != NULL; job = job->jv_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6104 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6105 if (job->jv_status == JOB_STARTED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6106 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6107 jobHandles[n] = job->jv_proc_info.hProcess;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6108 jobArray[n] = job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6109 ++n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6110 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6111 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6112 if (n == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6113 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6114 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6115 if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6116 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6117 job_T *wait_job = jobArray[result - WAIT_OBJECT_0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6118
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6119 if (STRCMP(mch_job_status(wait_job), "dead") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6120 return wait_job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6122 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6123 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6124 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6125
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6126 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6127 terminate_all(HANDLE process, int code)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6128 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6129 PROCESSENTRY32 pe;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6130 HANDLE h = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6131 DWORD pid = GetProcessId(process);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6133 if (pid != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6134 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6135 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6136 if (h != INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6137 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6138 pe.dwSize = sizeof(PROCESSENTRY32);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6139 if (!Process32First(h, &pe))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6140 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6141
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6142 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6143 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6144 if (pe.th32ParentProcessID == pid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6145 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6146 HANDLE ph = OpenProcess(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6147 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6148 if (ph != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6149 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6150 terminate_all(ph, code);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6151 CloseHandle(ph);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6152 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6153 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6154 } while (Process32Next(h, &pe));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6156 CloseHandle(h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6157 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6158 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6160 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6161 return TerminateProcess(process, code);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6162 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6163
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6164 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6165 * Send a (deadly) signal to "job".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6166 * Return FAIL if it didn't work.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6167 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6168 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6169 mch_signal_job(job_T *job, char_u *how)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6170 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6171 int ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6172
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6173 if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6174 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6175 // deadly signal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6176 if (job->jv_job_object != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6177 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6178 if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6179 job->jv_channel->ch_killing = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6180 return TerminateJobObject(job->jv_job_object, (UINT)-1) ? OK : FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6181 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6182 return terminate_all(job->jv_proc_info.hProcess, -1) ? OK : FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6183 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6185 if (!AttachConsole(job->jv_proc_info.dwProcessId))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6186 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6187 ret = GenerateConsoleCtrlEvent(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6188 STRCMP(how, "int") == 0 ? CTRL_C_EVENT : CTRL_BREAK_EVENT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6189 job->jv_proc_info.dwProcessId)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6190 ? OK : FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6191 FreeConsole();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6192 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6193 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6195 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6196 * Clear the data related to "job".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6197 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6198 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6199 mch_clear_job(job_T *job)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6200 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6201 if (job->jv_status == JOB_FAILED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6202 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6204 if (job->jv_job_object != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6205 CloseHandle(job->jv_job_object);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6206 CloseHandle(job->jv_proc_info.hProcess);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6207 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6208 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6209
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6210
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6211 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6212
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6213 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6214 * Start termcap mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6215 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6216 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6217 termcap_mode_start(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6218 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6219 DWORD cmodein;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6220
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6221 if (g_fTermcapMode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6222 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6224 SaveConsoleBuffer(&g_cbNonTermcap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6225
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6226 if (g_cbTermcap.IsValid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6227 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6228 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6229 * We've been in termcap mode before. Restore certain screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6230 * characteristics, including the buffer size and the window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6231 * size. Since we will be redrawing the screen, we don't need
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6232 * to restore the actual contents of the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6233 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6234 RestoreConsoleBuffer(&g_cbTermcap, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6235 reset_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6236 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6237 Rows = g_cbTermcap.Info.dwSize.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6238 Columns = g_cbTermcap.Info.dwSize.X;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6239 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6240 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6241 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6242 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6243 * This is our first time entering termcap mode. Clear the console
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6244 * screen buffer, and resize the buffer to match the current window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6245 * size. We will use this as the size of our editing environment.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6246 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6247 ClearConsoleBuffer(g_attrCurrent);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6248 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6249 ResizeConBufAndWindow(g_hConOut, Columns, Rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6250 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6252 resettitle();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6254 GetConsoleMode(g_hConIn, &cmodein);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6255 if (g_fMouseActive)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6256 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6257 cmodein |= ENABLE_MOUSE_INPUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6258 cmodein &= ~ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6259 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6260 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6261 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6262 cmodein &= ~ENABLE_MOUSE_INPUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6263 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6264 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6265 cmodein |= ENABLE_WINDOW_INPUT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6266 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6268 redraw_later_clear();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6269 g_fTermcapMode = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6270 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6271
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6273 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6274 * End termcap mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6275 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6276 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6277 termcap_mode_end(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6278 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6279 DWORD cmodein;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6280 ConsoleBuffer *cb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6281 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6282 DWORD dwDummy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6283
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6284 if (!g_fTermcapMode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6285 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6287 SaveConsoleBuffer(&g_cbTermcap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6288
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6289 GetConsoleMode(g_hConIn, &cmodein);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6290 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6291 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6292 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6293
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6294 # ifdef FEAT_RESTORE_ORIG_SCREEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6295 cb = exiting ? &g_cbOrig : &g_cbNonTermcap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6296 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6297 cb = &g_cbNonTermcap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6298 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6299 RestoreConsoleBuffer(cb, p_rs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6300 restore_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6302 // Switch back to main screen buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6303 if (exiting && use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6304 vtp_printf("\033[?1049l");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6306 if (!USE_WT && (p_rs || exiting))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6307 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6308 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6309 * Clear anything that happens to be on the current line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6310 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6311 coord.X = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6312 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6313 FillConsoleOutputCharacter(g_hConOut, ' ',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6314 cb->Info.dwSize.X, coord, &dwDummy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6315 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6316 * The following is just for aesthetics. If we are exiting without
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6317 * restoring the screen, then we want to have a prompt string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6318 * appear at the bottom line. However, the command interpreter
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6319 * seems to always advance the cursor one line before displaying
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6320 * the prompt string, which causes the screen to scroll. To
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6321 * counter this, move the cursor up one line before exiting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6322 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6323 if (exiting && !p_rs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6324 coord.Y--;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6325 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6326 * Position the cursor at the leftmost column of the desired row.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6327 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6328 SetConsoleCursorPosition(g_hConOut, coord);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6329 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6330 SetConsoleCursorInfo(g_hConOut, &g_cci);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6331 g_fTermcapMode = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6332 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6333 #endif // !FEAT_GUI_MSWIN || VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6335
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6336 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6337 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6338 mch_write(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6339 char_u *s UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6340 int len UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6341 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6342 // never used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6343 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6345 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6347 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6348 * clear `n' chars, starting from `coord'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6349 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6350 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6351 clear_chars(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6352 COORD coord,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6353 DWORD n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6354 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6355 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6356 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6357 DWORD dwDummy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6358
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6359 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6360 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6361 &dwDummy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6362 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6363 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6364 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6365 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6366 gotoxy(coord.X + 1, coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6367 vtp_printf("\033[%dX", n);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6368 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6371
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6372 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6373 * Clear the screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6374 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6375 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6376 clear_screen(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6377 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6378 g_coord.X = g_coord.Y = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6379
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6380 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6381 clear_chars(g_coord, Rows * Columns);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6382 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6383 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6384 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6385 gotoxy(1, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6386 vtp_printf("\033[2J");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6387 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6388 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6391 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6392 * Clear to end of display
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6393 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6394 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6395 clear_to_end_of_display(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6396 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6397 COORD save = g_coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6398
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6399 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6400 clear_chars(g_coord, (Rows - g_coord.Y - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6401 * Columns + (Columns - g_coord.X));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6402 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6403 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6404 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6405 gotoxy(g_coord.X + 1, g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6406 vtp_printf("\033[0J");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6407
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6408 gotoxy(save.X + 1, save.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6409 g_coord = save;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6410 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6411 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6412
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6413
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6414 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6415 * Clear to end of line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6416 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6417 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6418 clear_to_end_of_line(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6419 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6420 COORD save = g_coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6422 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6423 clear_chars(g_coord, Columns - g_coord.X);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6424 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6425 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6426 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6427 gotoxy(g_coord.X + 1, g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6428 vtp_printf("\033[0K");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6430 gotoxy(save.X + 1, save.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6431 g_coord = save;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6432 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6433 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6435
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6436 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6437 * Scroll the scroll region up by `cLines' lines
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6438 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6439 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6440 scroll(unsigned cLines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6441 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6442 COORD oldcoord = g_coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6443
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6444 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6445 delete_lines(cLines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6447 g_coord = oldcoord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6448 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6449
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6451 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6452 * Set the scroll region
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6453 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6454 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6455 set_scroll_region(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6456 unsigned left,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6457 unsigned top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6458 unsigned right,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6459 unsigned bottom)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6460 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6461 if (left >= right
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6462 || top >= bottom
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6463 || right > (unsigned) Columns - 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6464 || bottom > (unsigned) Rows - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6465 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6466
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6467 g_srScrollRegion.Left = left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6468 g_srScrollRegion.Top = top;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6469 g_srScrollRegion.Right = right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6470 g_srScrollRegion.Bottom = bottom;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6471 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6472
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6473 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6474 set_scroll_region_tb(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6475 unsigned top,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6476 unsigned bottom)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6477 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6478 if (top >= bottom || bottom > (unsigned)Rows - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6479 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6481 g_srScrollRegion.Top = top;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6482 g_srScrollRegion.Bottom = bottom;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6483 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6484
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6485 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6486 set_scroll_region_lr(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6487 unsigned left,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6488 unsigned right)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6489 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6490 if (left >= right || right > (unsigned)Columns - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6491 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6492
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6493 g_srScrollRegion.Left = left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6494 g_srScrollRegion.Right = right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6495 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6496
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6498 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6499 * Insert `cLines' lines at the current cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6500 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6501 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6502 insert_lines(unsigned cLines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6503 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6504 SMALL_RECT source, clip;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6505 COORD dest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6506 CHAR_INFO fill;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6508 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6509
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6510 dest.X = g_srScrollRegion.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6511 dest.Y = g_coord.Y + cLines;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6512
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6513 source.Left = g_srScrollRegion.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6514 source.Top = g_coord.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6515 source.Right = g_srScrollRegion.Right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6516 source.Bottom = g_srScrollRegion.Bottom - cLines;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6518 clip.Left = g_srScrollRegion.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6519 clip.Top = g_coord.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6520 clip.Right = g_srScrollRegion.Right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6521 clip.Bottom = g_srScrollRegion.Bottom;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6523 fill.Char.AsciiChar = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6524 if (!USE_VTP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6525 fill.Attributes = g_attrCurrent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6526 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6527 fill.Attributes = g_attrDefault;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6528
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6529 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6530
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6531 ScrollConsoleScreenBuffer(g_hConOut, &source, &clip, dest, &fill);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6533 // Here we have to deal with a win32 console flake: If the scroll
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6534 // region looks like abc and we scroll c to a and fill with d we get
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6535 // cbd... if we scroll block c one line at a time to a, we get cdd...
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6536 // vim expects cdd consistently... So we have to deal with that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6537 // here... (this also occurs scrolling the same way in the other
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6538 // direction).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6539
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6540 if (source.Bottom < dest.Y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6541 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6542 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6543 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6544
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6545 coord.X = source.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6546 for (i = clip.Top; i < dest.Y; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6547 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6548 coord.Y = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6549 clear_chars(coord, source.Right - source.Left + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6550 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6551 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6553 if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6554 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6555 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6556 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6557
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6558 coord.X = source.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6559 for (i = source.Top; i < dest.Y; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6560 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6561 coord.Y = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6562 clear_chars(coord, source.Right - source.Left + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6563 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6564 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6565 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6566
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6567
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6568 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6569 * Delete `cLines' lines at the current cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6570 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6571 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6572 delete_lines(unsigned cLines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6573 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6574 SMALL_RECT source, clip;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6575 COORD dest;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6576 CHAR_INFO fill;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6577 int nb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6578
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6579 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6580
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6581 dest.X = g_srScrollRegion.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6582 dest.Y = g_coord.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6584 source.Left = g_srScrollRegion.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6585 source.Top = g_coord.Y + cLines;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6586 source.Right = g_srScrollRegion.Right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6587 source.Bottom = g_srScrollRegion.Bottom;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6588
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6589 clip.Left = g_srScrollRegion.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6590 clip.Top = g_coord.Y;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6591 clip.Right = g_srScrollRegion.Right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6592 clip.Bottom = g_srScrollRegion.Bottom;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6594 fill.Char.AsciiChar = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6595 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6596 fill.Attributes = g_attrCurrent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6597 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6598 fill.Attributes = g_attrDefault;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6599
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6600 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6601
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6602 ScrollConsoleScreenBuffer(g_hConOut, &source, &clip, dest, &fill);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6603
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6604 // Here we have to deal with a win32 console flake; See insert_lines()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6605 // above.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6606
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6607 nb = dest.Y + (source.Bottom - source.Top) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6608
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6609 if (nb < source.Top)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6610 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6611 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6612 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6614 coord.X = source.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6615 for (i = nb; i < clip.Bottom; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6616 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6617 coord.Y = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6618 clear_chars(coord, source.Right - source.Left + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6619 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6620 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6622 if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6623 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6624 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6625 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6627 coord.X = source.Left;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6628 for (i = nb; i <= source.Bottom; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6629 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6630 coord.Y = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6631 clear_chars(coord, source.Right - source.Left + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6632 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6633 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6634 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6635
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6636
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6637 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6638 * Set the cursor position to (x,y) (1-based).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6639 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6640 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6641 gotoxy(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6642 unsigned x,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6643 unsigned y)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6644 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6645 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6646 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6647
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6648 if (!USE_VTP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6649 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6650 // There are reports of double-width characters not displayed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6651 // correctly. This workaround should fix it, similar to how it's done
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6652 // for VTP.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6653 g_coord.X = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6654 SetConsoleCursorPosition(g_hConOut, g_coord);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6656 // external cursor coords are 1-based; internal are 0-based
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6657 g_coord.X = x - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6658 g_coord.Y = y - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6659 SetConsoleCursorPosition(g_hConOut, g_coord);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6660 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6661 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6662 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6663 // Move the cursor to the left edge of the screen to prevent screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6664 // destruction. Insider build bug. Always enabled because it's cheap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6665 // and avoids mistakes with recognizing the build.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6666 vtp_printf("\033[%d;%dH", g_coord.Y + 1, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6668 vtp_printf("\033[%d;%dH", y, x);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6670 g_coord.X = x - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6671 g_coord.Y = y - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6672 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6673 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6675
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6676 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6677 * Set the current text attribute = (foreground | background)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6678 * See ../runtime/doc/os_win32.txt for the numbers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6679 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6680 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6681 textattr(WORD wAttr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6682 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6683 g_attrCurrent = wAttr & 0xff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6684
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6685 SetConsoleTextAttribute(g_hConOut, wAttr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6686 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6687
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6689 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6690 textcolor(WORD wAttr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6691 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6692 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6694 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6695 SetConsoleTextAttribute(g_hConOut, g_attrCurrent);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6696 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6697 vtp_sgr_bulk(wAttr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6698 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6700
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6701 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6702 textbackground(WORD wAttr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6703 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6704 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6706 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6707 SetConsoleTextAttribute(g_hConOut, g_attrCurrent);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6708 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6709 vtp_sgr_bulk(wAttr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6710 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6711
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6712
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6713 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6714 * restore the default text attribute (whatever we started with)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6715 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6716 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6717 normvideo(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6718 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6719 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6720 textattr(g_attrDefault);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6721 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6722 vtp_sgr_bulk(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6723 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6724
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6726 static WORD g_attrPreStandout = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6727
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6728 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6729 * Make the text standout, by brightening it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6730 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6731 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6732 standout(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6733 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6734 g_attrPreStandout = g_attrCurrent;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6736 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6737 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6738
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6739
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6740 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6741 * Turn off standout mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6742 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6743 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6744 standend(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6745 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6746 if (g_attrPreStandout)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6747 textattr(g_attrPreStandout);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6748
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6749 g_attrPreStandout = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6750 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6752
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6753 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6754 * Set normal fg/bg color, based on T_ME. Called when t_me has been set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6755 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6756 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6757 mch_set_normal_colors(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6758 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6759 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6760 int n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6762 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6763 cterm_normal_bg_color = ((g_attrDefault >> 4) & 0xf) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6764 if (
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6765 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6766 !p_tgc &&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6767 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6768 T_ME[0] == ESC && T_ME[1] == '|')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6769 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6770 p = T_ME + 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6771 n = getdigits(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6772 if (*p == 'm' && n > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6773 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6774 cterm_normal_fg_color = (n & 0xf) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6775 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6776 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6777 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6778 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6779 cterm_normal_fg_gui_color = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6780 cterm_normal_bg_gui_color = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6781 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6782 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6784
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6785 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6786 * visual bell: flash the screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6787 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6788 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6789 visual_bell(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6790 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6791 COORD coordOrigin = {0, 0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6792 WORD attrFlash = ~g_attrCurrent & 0xff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6793
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6794 DWORD dwDummy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6795 LPWORD oldattrs = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6796
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6797 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6798 if (!(p_tgc || t_colors >= 256))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6799 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6800 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6801 oldattrs = ALLOC_MULT(WORD, Rows * Columns);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6802 if (oldattrs == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6803 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6804 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6805 coordOrigin, &dwDummy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6806 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6808 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6809 coordOrigin, &dwDummy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6811 Sleep(15); // wait for 15 msec
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6812
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6813 if (oldattrs != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6814 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6815 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6816 coordOrigin, &dwDummy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6817 vim_free(oldattrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6818 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6819 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6820
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6821
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6822 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6823 * Make the cursor visible or invisible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6824 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6825 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6826 cursor_visible(BOOL fVisible)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6827 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6828 s_cursor_visible = fVisible;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6829
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6830 if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6831 vtp_printf("\033[?25%c", fVisible ? 'h' : 'l');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6832
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6833 # ifdef MCH_CURSOR_SHAPE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6834 mch_update_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6835 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6836 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6839 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6840 * Write "cbToWrite" bytes in `pchBuf' to the screen.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6841 * Returns the number of bytes actually written (at least one).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6842 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6843 static DWORD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6844 write_chars(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6845 char_u *pchBuf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6846 DWORD cbToWrite)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6847 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6848 COORD coord = g_coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6849 DWORD written;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6850 DWORD n, cchwritten;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6851 static DWORD cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6852 static WCHAR *unicodebuf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6853 static int unibuflen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6854 static int length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6855 int cp = enc_utf8 ? CP_UTF8 : enc_codepage;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6856 static WCHAR *utf8spbuf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6857 static int utf8splength;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6858 static DWORD utf8spcells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6859 static WCHAR **utf8usingbuf = &unicodebuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6861 if (cbToWrite != 1 || *pchBuf != ' ' || !enc_utf8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6862 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6863 utf8usingbuf = &unicodebuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6864 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6865 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6866 length = MultiByteToWideChar(cp, 0, (LPCSTR)pchBuf, cbToWrite,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6867 unicodebuf, unibuflen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6868 if (length && length <= unibuflen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6869 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6870 vim_free(unicodebuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6871 unicodebuf = length ? LALLOC_MULT(WCHAR, length) : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6872 unibuflen = unibuflen ? 0 : length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6873 } while (TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6874 cells = mb_string2cells(pchBuf, cbToWrite);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6875 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6876 else // cbToWrite == 1 && *pchBuf == ' ' && enc_utf8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6877 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6878 if (utf8usingbuf != &utf8spbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6879 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6880 if (utf8spbuf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6881 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6882 cells = mb_string2cells((char_u *)" ", 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6883 length = MultiByteToWideChar(CP_UTF8, 0, " ", 1, NULL, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6884 utf8spbuf = LALLOC_MULT(WCHAR, length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6885 if (utf8spbuf != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6886 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6887 MultiByteToWideChar(CP_UTF8, 0, " ", 1, utf8spbuf, length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6888 utf8usingbuf = &utf8spbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6889 utf8splength = length;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6890 utf8spcells = cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6891 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6892 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6893 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6894 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6895 utf8usingbuf = &utf8spbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6896 length = utf8splength;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6897 cells = utf8spcells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6898 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6899 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6900 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6901
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6902 if (!USE_VTP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6903 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6904 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6905 coord, &written);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6906 // When writing fails or didn't write a single character, pretend one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6907 // character was written, otherwise we get stuck.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6908 if (WriteConsoleOutputCharacterW(g_hConOut, *utf8usingbuf, length,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6909 coord, &cchwritten) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6910 || cchwritten == 0 || cchwritten == (DWORD)-1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6911 cchwritten = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6912 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6913 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6914 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6915 if (WriteConsoleW(g_hConOut, *utf8usingbuf, length, &cchwritten,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6916 NULL) == 0 || cchwritten == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6917 cchwritten = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6918 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6920 if (cchwritten == (DWORD)length)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6921 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6922 written = cbToWrite;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6923 g_coord.X += (SHORT)cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6924 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6925 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6926 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6927 char_u *p = pchBuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6928 for (n = 0; n < cchwritten; n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6929 MB_CPTR_ADV(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6930 written = p - pchBuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6931 g_coord.X += (SHORT)mb_string2cells(pchBuf, written);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6932 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6934 while (g_coord.X > g_srScrollRegion.Right)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6935 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6936 g_coord.X -= (SHORT) Columns;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6937 if (g_coord.Y < g_srScrollRegion.Bottom)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6938 g_coord.Y++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6939 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6940
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6941 // Cursor under VTP is always in the correct position, no need to reset.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6942 if (!USE_VTP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6943 gotoxy(g_coord.X + 1, g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6944
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6945 return written;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6946 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6947
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6948 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6949 get_seq(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6950 int *args,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6951 int *count,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6952 char_u *head)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6953 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6954 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6955 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6956
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6957 if (head == NULL || *head != '\033')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6958 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6959
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6960 argc = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6961 p = head;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6962 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6963 do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6964 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6965 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6966 args[argc] = getdigits(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6967 argc += (argc < 15) ? 1 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6968 } while (*p == ';');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6969 *count = argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6971 return p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6972 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6973
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6974 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6975 get_sgr(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6976 int *args,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6977 int *count,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6978 char_u *head)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6979 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6980 char_u *p = get_seq(args, count, head);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6981
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6982 return (p && *p == 'm') ? ++p : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6983 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6984
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6985 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6986 * Pointer to next if SGR (^[[n;2;*;*;*m), NULL otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6987 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6988 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6989 sgrn2(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6990 char_u *head,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6991 int n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6992 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6993 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6994 int args[16];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6995 char_u *p = get_sgr(args, &argc, head);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6997 return p && argc == 5 && args[0] == n && args[1] == 2 ? p : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6998 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
6999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7000 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7001 * Pointer to next if SGR(^[[nm)<space>ESC, NULL otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7002 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7003 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7004 sgrnc(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7005 char_u *head,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7006 int n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7007 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7008 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7009 int args[16];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7010 char_u *p = get_sgr(args, &argc, head);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7011
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7012 return p && argc == 1 && args[0] == n && (p = skipwhite(p)) && *p == '\033'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7013 ? p : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7014 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7015
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7016 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7017 skipblank(char_u *q)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7018 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7019 char_u *p = q;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7020
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7021 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7022 ++p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7023 return p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7024 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7026 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7027 * Pointer to the next if any whitespace that may follow SGR is ESC, otherwise
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7028 * NULL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7029 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7030 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7031 sgrn2c(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7032 char_u *head,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7033 int n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7035 char_u *p = sgrn2(head, n);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7036
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7037 return p && *p != NUL && (p = skipblank(p)) && *p == '\033' ? p : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7038 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7039
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7040 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7041 * If there is only a newline between the sequence immediately following it,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7042 * a pointer to the character following the newline is returned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7043 * Otherwise NULL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7044 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7045 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7046 sgrn2cn(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7047 char_u *head,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7048 int n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7049 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7050 char_u *p = sgrn2(head, n);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7051
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7052 return p && p[0] == 0x0a && p[1] == '\033' ? ++p : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7053 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7054
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7055 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7056 * mch_write(): write the output buffer to the screen, translating ESC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7057 * sequences into calls to console output routines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7058 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7059 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7060 mch_write(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7061 char_u *s,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7062 int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7063 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7064 char_u *end = s + len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7065
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7066 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7067 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7068 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7069 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7070
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7071 if (!term_console)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7072 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7073 write(1, s, (unsigned)len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7074 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7075 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7076
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7077 // translate ESC | sequences into faked bios calls
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7078 while (len--)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7079 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7080 int prefix = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7081 char_u ch;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7083 // While processing a sequence, on rare occasions it seems that another
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7084 // sequence may be inserted asynchronously.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7085 if (len < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7086 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7087 redraw_all_later(UPD_CLEAR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7088 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7089 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7090
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7091 while (s + ++prefix < end)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7092 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7093 ch = s[prefix];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7094 if (ch <= 0x1e && !(ch != '\n' && ch != '\r' && ch != '\b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7095 && ch != '\a' && ch != '\033'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7096 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7097 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7098
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7099 if (p_wd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7100 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7101 WaitForChar(p_wd, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7102 if (prefix != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7103 prefix = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7104 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7106 if (prefix != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7107 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7108 DWORD nWritten;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7109
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7110 nWritten = write_chars(s, prefix);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7111 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7112 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7113 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7114 fputc('>', fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7115 fwrite(s, sizeof(char_u), nWritten, fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7116 fputs("<\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7117 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7118 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7119 len -= (nWritten - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7120 s += nWritten;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7122 else if (s[0] == '\n')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7123 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7124 // \n, newline: go to the beginning of the next line or scroll
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7125 if (g_coord.Y == g_srScrollRegion.Bottom)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7126 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7127 scroll(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7128 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7129 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7130 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7131 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7132 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7133 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7134 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7135 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7136 fputs("\\n\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7137 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7138 s++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7139 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7140 else if (s[0] == '\r')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7141 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7142 // \r, carriage return: go to beginning of line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7143 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7144 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7145 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7146 fputs("\\r\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7147 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7148 s++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7149 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7150 else if (s[0] == '\b')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7151 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7152 // \b, backspace: move cursor one position left
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7153 if (g_coord.X > g_srScrollRegion.Left)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7154 g_coord.X--;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7155 else if (g_coord.Y > g_srScrollRegion.Top)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7156 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7157 g_coord.X = g_srScrollRegion.Right;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7158 g_coord.Y--;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7159 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7160 gotoxy(g_coord.X + 1, g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7161 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7162 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7163 fputs("\\b\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7164 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7165 s++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7166 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7167 else if (s[0] == '\a')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7168 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7169 // \a, bell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7170 MessageBeep(0xFFFFFFFF);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7171 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7172 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7173 fputs("\\a\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7174 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7175 s++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7176 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7177 else if (s[0] == ESC && len >= 3-1 && s[1] == '|')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7178 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7179 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7180 char_u *old_s = s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7181 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7182 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7183 int arg1 = 0, arg2 = 0, argc = 0, args[16];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7184 char_u *sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7186 switch (s[2])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7187 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7188 case '0': case '1': case '2': case '3': case '4':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7189 case '5': case '6': case '7': case '8': case '9':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7190 if (*(p = get_seq(args, &argc, s)) != 'm')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7191 goto notsgr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7193 p = s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7195 // Handling frequent optional sequences. Output to the screen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7196 // takes too long, so do not output as much as possible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7198 // If resetFG,FG,BG,<cr>,BG,FG are connected, the preceding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7199 // resetFG,FG,BG are omitted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7200 if (sgrn2(sgrn2(sgrn2cn(sgrn2(sgrnc(p, 39), 38), 48), 48), 38))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7201 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7202 p = sgrn2(sgrn2(sgrnc(p, 39), 38), 48);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7203 len = len + 1 - (int)(p - s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7204 s = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7205 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7206 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7208 // If FG,BG,BG,FG of SGR are connected, the first FG can be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7209 // omitted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7210 if (sgrn2(sgrn2(sgrn2c((sp = sgrn2(p, 38)), 48), 48), 38))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7211 p = sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7212
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7213 // If FG,BG,FG,BG of SGR are connected, the first FG can be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7214 // omitted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7215 if (sgrn2(sgrn2(sgrn2c((sp = sgrn2(p, 38)), 48), 38), 48))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7216 p = sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7218 // If BG,BG of SGR are connected, the first BG can be omitted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7219 if (sgrn2((sp = sgrn2(p, 48)), 48))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7220 p = sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7221
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7222 // If restoreFG and FG are connected, the restoreFG can be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7223 // omitted.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7224 if (sgrn2((sp = sgrnc(p, 39)), 38))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7225 p = sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7227 p = get_seq(args, &argc, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7228
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7229 notsgr:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7230 arg1 = args[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7231 arg2 = args[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7232 if (*p == 'm')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7233 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7234 if (argc == 1 && args[0] == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7235 normvideo();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7236 else if (argc == 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7237 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7238 if (USE_VTP)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7239 textcolor((WORD)arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7240 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7241 textattr((WORD)arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7242 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7243 else if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7244 vtp_sgr_bulks(argc, args);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7245 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7246 else if (argc == 2 && *p == 'H')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7247 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7248 gotoxy(arg2, arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7249 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7250 else if (argc == 2 && *p == 'r')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7251 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7252 set_scroll_region(0, arg1 - 1, Columns - 1, arg2 - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7253 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7254 else if (argc == 2 && *p == 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7255 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7256 set_scroll_region_tb(arg1, arg2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7257 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7258 else if (argc == 2 && *p == 'V')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7259 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7260 set_scroll_region_lr(arg1, arg2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7261 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7262 else if (argc == 1 && *p == 'A')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7263 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7264 gotoxy(g_coord.X + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7265 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7266 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7267 else if (argc == 1 && *p == 'b')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7268 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7269 textbackground((WORD) arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7270 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7271 else if (argc == 1 && *p == 'C')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7272 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7273 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7274 g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7275 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7276 else if (argc == 1 && *p == 'f')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7277 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7278 textcolor((WORD) arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7279 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7280 else if (argc == 1 && *p == 'H')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7281 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7282 gotoxy(1, arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7283 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7284 else if (argc == 1 && *p == 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7285 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7286 insert_lines(arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7287 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7288 else if (argc == 1 && *p == 'M')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7289 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7290 delete_lines(arg1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7291 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7292
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7293 len -= (int)(p - s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7294 s = p + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7295 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7296
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7297 case 'A':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7298 gotoxy(g_coord.X + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7299 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7300 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7302 case 'B':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7303 visual_bell();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7304 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7306 case 'C':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7307 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7308 g_coord.Y + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7309 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7310
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7311 case 'E':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7312 termcap_mode_end();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7313 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7314
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7315 case 'F':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7316 standout();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7317 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7319 case 'f':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7320 standend();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7321 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7322
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7323 case 'H':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7324 gotoxy(1, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7325 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7326
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7327 case 'j':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7328 clear_to_end_of_display();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7329 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7330
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7331 case 'J':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7332 clear_screen();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7333 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7335 case 'K':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7336 clear_to_end_of_line();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7337 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7338
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7339 case 'L':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7340 insert_lines(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7341 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7342
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7343 case 'M':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7344 delete_lines(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7345 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7347 case 'S':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7348 termcap_mode_start();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7349 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7351 case 'V':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7352 cursor_visible(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7353 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7354
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7355 case 'v':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7356 cursor_visible(FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7357 goto got3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7358
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7359 got3:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7360 s += 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7361 len -= 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7362 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7364 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7365 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7366 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7367 fputs("ESC | ", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7368 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7369 fputc('\n', fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7370 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7371 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7372 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7373 else if (s[0] == ESC && len >= 3-1 && s[1] == '[')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7374 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7375 int l = 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7377 if (isdigit(s[l]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7378 l++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7379 if (s[l] == ' ' && s[l + 1] == 'q')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7380 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7381 // DECSCUSR (cursor style) sequences
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7382 if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7383 vtp_printf("%.*s", l + 2, s); // Pass through
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7384 s += l + 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7385 len -= l + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7386 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7387 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7388 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7389 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7390 // Write a single character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7391 DWORD nWritten;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7393 nWritten = write_chars(s, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7394 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7395 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7396 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7397 fputc('>', fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7398 fwrite(s, sizeof(char_u), nWritten, fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7399 fputs("<\n", fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7400 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7401 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7402
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7403 len -= (nWritten - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7404 s += nWritten;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7405 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7406 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7407
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7408 # ifdef MCH_WRITE_DUMP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7409 if (fdDump)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7410 fflush(fdDump);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7411 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7412 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7413
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7414 #endif // FEAT_GUI_MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7417 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7418 * Delay for "msec" milliseconds.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7419 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7420 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7421 mch_delay(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7422 long msec,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7423 int flags UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7424 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7425 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7426 Sleep((int)msec); // never wait for input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7427 #else // Console
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7428 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7429 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7430 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7431 Sleep((int)msec); // never wait for input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7432 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7433 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7434 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7435 if (flags & MCH_DELAY_IGNOREINPUT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7436 # ifdef FEAT_MZSCHEME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7437 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7439 int towait = p_mzq;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7441 // if msec is large enough, wait by portions in p_mzq
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7442 while (msec > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7443 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7444 mzvim_check_threads();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7445 if (msec < towait)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7446 towait = msec;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7447 Sleep(towait);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7448 msec -= towait;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7450 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7451 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7452 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7453 Sleep((int)msec);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7454 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7455 WaitForChar(msec, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7456 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7457 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7459
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7460 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7461 * This version of remove is not scared by a readonly (backup) file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7462 * This can also remove a symbolic link like Unix.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7463 * Return 0 for success, -1 for failure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7464 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7465 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7466 mch_remove(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7467 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7468 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7469 int n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7471 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7472 * On Windows, deleting a directory's symbolic link is done by
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7473 * RemoveDirectory(): mch_rmdir. It seems unnatural, but it is fact.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7474 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7475 if (mch_isdir(name) && mch_is_symbolic_link(name))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7476 return mch_rmdir(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7478 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7479
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7480 wn = enc_to_utf16(name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7481 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7482 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7484 n = DeleteFileW(wn) ? 0 : -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7485 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7486 return n;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7487 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7488
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7489
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7490 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7491 * Check for an "interrupt signal": CTRL-break or CTRL-C.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7492 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7493 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7494 mch_breakcheck(int force UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7495 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7496 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7497 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7498 if (!gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7499 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7500 if (g_fCtrlCPressed || g_fCBrkPressed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7501 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7502 ctrl_break_was_pressed = g_fCBrkPressed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7503 g_fCtrlCPressed = g_fCBrkPressed = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7504 got_int = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7505 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7506 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7507 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7508
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7509 // physical RAM to leave for the OS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7510 #define WINNT_RESERVE_BYTES (256*1024*1024)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7511
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7512 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7513 * How much main memory in KiB that can be used by VIM.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7514 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7515 long_u
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7516 mch_total_mem(int special UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7517 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7518 MEMORYSTATUSEX ms;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7519
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7520 // Need to use GlobalMemoryStatusEx() when there is more memory than
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7521 // what fits in 32 bits.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7522 ms.dwLength = sizeof(MEMORYSTATUSEX);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7523 GlobalMemoryStatusEx(&ms);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7524 if (ms.ullAvailVirtual < ms.ullTotalPhys)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7525 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7526 // Process address space fits in physical RAM, use all of it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7527 return (long_u)(ms.ullAvailVirtual / 1024);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7528 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7529 if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7530 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7531 // Catch old NT box or perverse hardware setup.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7532 return (long_u)((ms.ullTotalPhys / 2) / 1024);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7533 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7534 // Use physical RAM less reserve for OS + data.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7535 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7536 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7538 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7539 * mch_wrename() works around a bug in rename (aka MoveFile) in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7540 * Windows 95: rename("foo.bar", "foo.bar~") will generate a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7541 * file whose short file name is "FOO.BAR" (its long file name will
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7542 * be correct: "foo.bar~"). Because a file can be accessed by
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7543 * either its SFN or its LFN, "foo.bar" has effectively been
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7544 * renamed to "foo.bar", which is not at all what was wanted. This
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7545 * seems to happen only when renaming files with three-character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7546 * extensions by appending a suffix that does not include ".".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7547 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7548 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7549 * There is another problem, which isn't really a bug but isn't right either:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7550 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7551 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7552 * service pack 6. Doesn't seem to happen on Windows 98.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7553 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7554 * Like rename(), returns 0 upon success, non-zero upon failure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7555 * Should probably set errno appropriately when errors occur.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7556 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7557 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7558 mch_wrename(WCHAR *wold, WCHAR *wnew)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7560 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7561 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7562 WCHAR szTempFile[_MAX_PATH + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7563 WCHAR szNewPath[_MAX_PATH + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7564 HANDLE hf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7565
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7566 // No need to play tricks unless the file name contains a "~" as the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7567 // seventh character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7568 p = wold;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7569 for (i = 0; wold[i] != NUL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7570 if ((wold[i] == '/' || wold[i] == '\\' || wold[i] == ':')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7571 && wold[i + 1] != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7572 p = wold + i + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7573 if ((int)(wold + i - p) < 8 || p[6] != '~')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7574 return (MoveFileW(wold, wnew) == 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7575
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7576 // Get base path of new file name. Undocumented feature: If pszNewFile is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7577 // a directory, no error is returned and pszFilePart will be NULL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7578 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7579 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7580 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7581
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7582 // Get (and create) a unique temporary file name in directory of new file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7583 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7584 return -2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7585
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7586 // blow the temp file away
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7587 if (!DeleteFileW(szTempFile))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7588 return -3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7589
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7590 // rename old file to the temp file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7591 if (!MoveFileW(wold, szTempFile))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7592 return -4;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7594 // now create an empty file called pszOldFile; this prevents the operating
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7595 // system using pszOldFile as an alias (SFN) if we're renaming within the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7596 // same directory. For example, we're editing a file called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7597 // filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7598 // to filena~1.txt~ (i.e., we're making a backup while writing it), the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7599 // SFN for filena~1.txt~ will be filena~1.txt, by default, which will
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7600 // cause all sorts of problems later in buf_write(). So, we create an
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7601 // empty file called filena~1.txt and the system will have to find some
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7602 // other SFN for filena~1.txt~, such as filena~2.txt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7603 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7604 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7605 return -5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7606 if (!CloseHandle(hf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7607 return -6;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7608
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7609 // rename the temp file to the new file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7610 if (!MoveFileW(szTempFile, wnew))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7611 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7612 // Renaming failed. Rename the file back to its old name, so that it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7613 // looks like nothing happened.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7614 (void)MoveFileW(szTempFile, wold);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7615 return -7;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7616 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7617
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7618 // Seems to be left around on Novell filesystems
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7619 DeleteFileW(szTempFile);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7621 // finally, remove the empty old file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7622 if (!DeleteFileW(wold))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7623 return -8;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7624
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7625 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7626 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7628
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7629 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7630 * Converts the filenames to UTF-16, then call mch_wrename().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7631 * Like rename(), returns 0 upon success, non-zero upon failure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7632 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7633 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7634 mch_rename(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7635 const char *pszOldFile,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7636 const char *pszNewFile)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7637 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7638 WCHAR *wold = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7639 WCHAR *wnew = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7640 int retval = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7641
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7642 wold = enc_to_utf16((char_u *)pszOldFile, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7643 wnew = enc_to_utf16((char_u *)pszNewFile, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7644 if (wold != NULL && wnew != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7645 retval = mch_wrename(wold, wnew);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7646 vim_free(wold);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7647 vim_free(wnew);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7648 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7649 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7650
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7651 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7652 * Get the default shell for the current hardware platform
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7653 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7654 char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7655 default_shell(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7656 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7657 return "cmd.exe";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7658 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7659
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7660 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7661 * mch_access() extends access() to do more detailed check on network drives.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7662 * Returns 0 if file "n" has access rights according to "p", -1 otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7663 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7664 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7665 mch_access(char *n, int p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7666 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7667 HANDLE hFile;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7668 int retval = -1; // default: fail
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7669 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7671 wn = enc_to_utf16((char_u *)n, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7672 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7673 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7675 if (mch_isdir((char_u *)n))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7676 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7677 WCHAR TempNameW[_MAX_PATH + 16] = L"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7679 if (p & R_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7681 // Read check is performed by seeing if we can do a find file on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7682 // the directory for any file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7683 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7684 WIN32_FIND_DATAW d;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7685
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7686 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7687 TempNameW[i] = wn[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7688 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7689 TempNameW[i++] = '\\';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7690 TempNameW[i++] = '*';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7691 TempNameW[i++] = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7693 hFile = FindFirstFileW(TempNameW, &d);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7694 if (hFile == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7695 goto getout;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7696 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7697 (void)FindClose(hFile);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7698 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7700 if (p & W_OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7701 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7702 // Trying to create a temporary file in the directory should catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7703 // directories on read-only network shares. However, in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7704 // directories whose ACL allows writes but denies deletes will end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7705 // up keeping the temporary file :-(.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7706 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7707 goto getout;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7708 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7709 DeleteFileW(TempNameW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7710 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7711 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7712 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7713 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7714 // Don't consider a file read-only if another process has opened it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7715 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7716
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7717 // Trying to open the file for the required access does ACL, read-only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7718 // network share, and file attribute checks.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7719 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7720 | ((p & R_OK) ? GENERIC_READ : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7722 hFile = CreateFileW(wn, access_mode, share_mode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7723 NULL, OPEN_EXISTING, 0, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7724 if (hFile == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7725 goto getout;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7726 CloseHandle(hFile);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7727 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7728
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7729 retval = 0; // success
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7730 getout:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7731 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7732 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7733 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7735 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7736 * Version of open() that may use UTF-16 file name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7737 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7738 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7739 mch_open(const char *name, int flags, int mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7740 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7741 WCHAR *wn;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7742 int f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7744 wn = enc_to_utf16((char_u *)name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7745 if (wn == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7746 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7748 f = _wopen(wn, flags, mode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7749 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7750 return f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7751 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7752
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7753 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7754 * Version of fopen() that uses UTF-16 file name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7755 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7756 FILE *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7757 mch_fopen(const char *name, const char *mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7758 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7759 WCHAR *wn, *wm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7760 FILE *f = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7762 #if defined(DEBUG) && _MSC_VER >= 1400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7763 // Work around an annoying assertion in the Microsoft debug CRT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7764 // when mode's text/binary setting doesn't match _get_fmode().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7765 char newMode = mode[strlen(mode) - 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7766 int oldMode = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7768 _get_fmode(&oldMode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7769 if (newMode == 't')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7770 _set_fmode(_O_TEXT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7771 else if (newMode == 'b')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7772 _set_fmode(_O_BINARY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7773 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7774 wn = enc_to_utf16((char_u *)name, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7775 wm = enc_to_utf16((char_u *)mode, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7776 if (wn != NULL && wm != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7777 f = _wfopen(wn, wm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7778 vim_free(wn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7779 vim_free(wm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7781 #if defined(DEBUG) && _MSC_VER >= 1400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7782 _set_fmode(oldMode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7783 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7784 return f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7785 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7786
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7787 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7788 * SUB STREAM (aka info stream) handling:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7789 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7790 * NTFS can have sub streams for each file. The normal contents of a file is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7791 * stored in the main stream, and extra contents (author information, title and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7792 * so on) can be stored in a sub stream. After Windows 2000, the user can
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7793 * access and store this information in sub streams via an explorer's property
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7794 * menu item in the right click menu. This information in sub streams was lost
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7795 * when copying only the main stream. Therefore we have to copy sub streams.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7796 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7797 * Incomplete explanation:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7798 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7799 * More useful info and an example:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7800 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7801 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7802
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7803 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7804 * Copy info stream data "substream". Read from the file with BackupRead(sh)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7805 * and write to stream "substream" of file "to".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7806 * Errors are ignored.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7807 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7808 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7809 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7810 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7811 HANDLE hTo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7812 WCHAR *to_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7814 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7815 wcscpy(to_name, to);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7816 wcscat(to_name, substream);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7817
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7818 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7819 FILE_ATTRIBUTE_NORMAL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7820 if (hTo != INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7821 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7822 long done;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7823 DWORD todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7824 DWORD readcnt, written;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7825 char buf[4096];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7826
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7827 // Copy block of bytes at a time. Abort when something goes wrong.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7828 for (done = 0; done < len; done += written)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7829 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7830 // (size_t) cast for Borland C 5.5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7831 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7832 : (size_t)(len - done));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7833 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7834 FALSE, FALSE, context)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7835 || readcnt != todo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7836 || !WriteFile(hTo, buf, todo, &written, NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7837 || written != todo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7838 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7839 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7840 CloseHandle(hTo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7841 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7843 free(to_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7844 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7845
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7846 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7847 * Copy info streams from file "from" to file "to".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7848 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7849 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7850 copy_infostreams(char_u *from, char_u *to)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7851 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7852 WCHAR *fromw;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7853 WCHAR *tow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7854 HANDLE sh;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7855 WIN32_STREAM_ID sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7856 int headersize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7857 WCHAR streamname[_MAX_PATH];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7858 DWORD readcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7859 void *context = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7860 DWORD lo, hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7861 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7862
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7863 // Convert the file names to wide characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7864 fromw = enc_to_utf16(from, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7865 tow = enc_to_utf16(to, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7866 if (fromw != NULL && tow != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7867 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7868 // Open the file for reading.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7869 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7870 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7871 if (sh != INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7872 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7873 // Use BackupRead() to find the info streams. Repeat until we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7874 // have done them all.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7875 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7876 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7877 // Get the header to find the length of the stream name. If
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7878 // the "readcount" is zero we have done all info streams.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7879 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7880 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7881 if (!BackupRead(sh, (LPBYTE)&sid, headersize,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7882 &readcount, FALSE, FALSE, &context)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7883 || readcount == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7884 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7885
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7886 // We only deal with streams that have a name. The normal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7887 // file data appears to be without a name, even though docs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7888 // suggest it is called "::$DATA".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7889 if (sid.dwStreamNameSize > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7890 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7891 // Read the stream name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7892 if (!BackupRead(sh, (LPBYTE)streamname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7893 sid.dwStreamNameSize,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7894 &readcount, FALSE, FALSE, &context))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7895 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7896
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7897 // Copy an info stream with a name ":anything:$DATA".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7898 // Skip "::$DATA", it has no stream name (examples suggest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7899 // it might be used for the normal file contents).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7900 // Note that BackupRead() counts bytes, but the name is in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7901 // wide characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7902 len = readcount / sizeof(WCHAR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7903 streamname[len] = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7904 if (len > 7 && wcsicmp(streamname + len - 6,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7905 L":$DATA") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7906 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7907 streamname[len - 6] = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7908 copy_substream(sh, &context, tow, streamname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7909 (long)sid.Size.u.LowPart);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7910 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7911 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7912
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7913 // Advance to the next stream. We might try seeking too far,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7914 // but BackupSeek() doesn't skip over stream borders, thus
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7915 // that's OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7916 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7917 &lo, &hi, &context);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7918 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7920 // Clear the context.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7921 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7922
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7923 CloseHandle(sh);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7924 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7925 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7926 vim_free(fromw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7927 vim_free(tow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7928 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7929
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7930 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7931 * ntdll.dll definitions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7932 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7933 #define FileEaInformation 7
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7934 #ifndef STATUS_SUCCESS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7935 # define STATUS_SUCCESS ((NTSTATUS) 0x00000000L)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7936 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7937
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7938 typedef struct _FILE_FULL_EA_INFORMATION_ {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7939 ULONG NextEntryOffset;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7940 UCHAR Flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7941 UCHAR EaNameLength;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7942 USHORT EaValueLength;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7943 CHAR EaName[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7944 } FILE_FULL_EA_INFORMATION_, *PFILE_FULL_EA_INFORMATION_;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7946 typedef struct _FILE_EA_INFORMATION_ {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7947 ULONG EaSize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7948 } FILE_EA_INFORMATION_, *PFILE_EA_INFORMATION_;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7949
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7950 #ifndef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7951 typedef NTSTATUS (NTAPI *PfnNtOpenFile)(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7952 PHANDLE FileHandle,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7953 ACCESS_MASK DesiredAccess,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7954 POBJECT_ATTRIBUTES ObjectAttributes,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7955 PIO_STATUS_BLOCK IoStatusBlock,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7956 ULONG ShareAccess,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7957 ULONG OpenOptions);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7958 typedef NTSTATUS (NTAPI *PfnNtClose)(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7959 HANDLE Handle);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7960 typedef NTSTATUS (NTAPI *PfnNtSetEaFile)(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7961 HANDLE FileHandle,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7962 PIO_STATUS_BLOCK IoStatusBlock,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7963 PVOID Buffer,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7964 ULONG Length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7965 typedef NTSTATUS (NTAPI *PfnNtQueryEaFile)(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7966 HANDLE FileHandle,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7967 PIO_STATUS_BLOCK IoStatusBlock,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7968 PVOID Buffer,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7969 ULONG Length,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7970 BOOLEAN ReturnSingleEntry,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7971 PVOID EaList,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7972 ULONG EaListLength,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7973 PULONG EaIndex,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7974 BOOLEAN RestartScan);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7975 typedef NTSTATUS (NTAPI *PfnNtQueryInformationFile)(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7976 HANDLE FileHandle,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7977 PIO_STATUS_BLOCK IoStatusBlock,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7978 PVOID FileInformation,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7979 ULONG Length,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7980 FILE_INFORMATION_CLASS FileInformationClass);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7981 typedef VOID (NTAPI *PfnRtlInitUnicodeString)(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7982 PUNICODE_STRING DestinationString,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7983 PCWSTR SourceString);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7984
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7985 PfnNtOpenFile pNtOpenFile = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7986 PfnNtClose pNtClose = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7987 PfnNtSetEaFile pNtSetEaFile = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7988 PfnNtQueryEaFile pNtQueryEaFile = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7989 PfnNtQueryInformationFile pNtQueryInformationFile = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7990 PfnRtlInitUnicodeString pRtlInitUnicodeString = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7991 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7993 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7994 * Load ntdll.dll functions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7995 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7996 static BOOL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7997 load_ntdll(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7998 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
7999 static int loaded = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8001 if (loaded != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8002 return (BOOL) loaded;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8003
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8004 HMODULE hNtdll = GetModuleHandle("ntdll.dll");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8005 if (hNtdll != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8006 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8007 pNtOpenFile = (PfnNtOpenFile) GetProcAddress(hNtdll, "NtOpenFile");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8008 pNtClose = (PfnNtClose) GetProcAddress(hNtdll, "NtClose");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8009 pNtSetEaFile = (PfnNtSetEaFile)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8010 GetProcAddress(hNtdll, "NtSetEaFile");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8011 pNtQueryEaFile = (PfnNtQueryEaFile)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8012 GetProcAddress(hNtdll, "NtQueryEaFile");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8013 pNtQueryInformationFile = (PfnNtQueryInformationFile)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8014 GetProcAddress(hNtdll, "NtQueryInformationFile");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8015 pRtlInitUnicodeString = (PfnRtlInitUnicodeString)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8016 GetProcAddress(hNtdll, "RtlInitUnicodeString");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8017 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8018 if (pNtOpenFile == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8019 || pNtClose == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8020 || pNtSetEaFile == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8021 || pNtQueryEaFile == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8022 || pNtQueryInformationFile == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8023 || pRtlInitUnicodeString == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8024 loaded = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8025 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8026 loaded = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8027 return (BOOL) loaded;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8028 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8030 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8031 * Copy extended attributes (EA) from file "from" to file "to".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8032 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8033 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8034 copy_extattr(char_u *from, char_u *to)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8035 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8036 char_u *fromf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8037 char_u *tof = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8038 WCHAR *fromw = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8039 WCHAR *tow = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8040 UNICODE_STRING u;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8041 HANDLE h;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8042 OBJECT_ATTRIBUTES oa;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8043 IO_STATUS_BLOCK iosb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8044 FILE_EA_INFORMATION_ eainfo = {0};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8045 void *ea = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8047 if (!load_ntdll())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8048 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8050 // Convert the file names to the fully qualified object names.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8051 fromf = alloc(STRLEN(from) + 5);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8052 tof = alloc(STRLEN(to) + 5);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8053 if (fromf == NULL || tof == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8054 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8055 STRCPY(fromf, "\\??\\");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8056 STRCAT(fromf, from);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8057 STRCPY(tof, "\\??\\");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8058 STRCAT(tof, to);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8059
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8060 // Convert the names to wide characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8061 fromw = enc_to_utf16(fromf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8062 tow = enc_to_utf16(tof, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8063 if (fromw == NULL || tow == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8064 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8065
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8066 // Get the EA.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8067 pRtlInitUnicodeString(&u, fromw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8068 InitializeObjectAttributes(&oa, &u, 0, NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8069 if (pNtOpenFile(&h, FILE_READ_EA, &oa, &iosb, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8070 FILE_NON_DIRECTORY_FILE) != STATUS_SUCCESS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8071 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8072 pNtQueryInformationFile(h, &iosb, &eainfo, sizeof(eainfo),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8073 FileEaInformation);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8074 if (eainfo.EaSize != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8075 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8076 ea = alloc(eainfo.EaSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8077 if (ea != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8078 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8079 if (pNtQueryEaFile(h, &iosb, ea, eainfo.EaSize, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8080 NULL, 0, NULL, TRUE) != STATUS_SUCCESS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8081 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8082 VIM_CLEAR(ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8083 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8084 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8085 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8086 pNtClose(h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8087
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8088 // Set the EA.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8089 if (ea != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8090 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8091 pRtlInitUnicodeString(&u, tow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8092 InitializeObjectAttributes(&oa, &u, 0, NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8093 if (pNtOpenFile(&h, FILE_WRITE_EA, &oa, &iosb, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8094 FILE_NON_DIRECTORY_FILE) != STATUS_SUCCESS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8095 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8096
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8097 pNtSetEaFile(h, &iosb, ea, eainfo.EaSize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8098 pNtClose(h);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8099 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8101 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8102 vim_free(fromf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8103 vim_free(tof);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8104 vim_free(fromw);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8105 vim_free(tow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8106 vim_free(ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8107 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8109 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8110 * Copy file attributes from file "from" to file "to".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8111 * For Windows NT and later we copy info streams.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8112 * Always returns zero, errors are ignored.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8113 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8114 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8115 mch_copy_file_attribute(char_u *from, char_u *to)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8116 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8117 // File streams only work on Windows NT and later.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8118 copy_infostreams(from, to);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8119 copy_extattr(from, to);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8120 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8124 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8125 * The command line arguments in UTF-16
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8126 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8127 static int nArgsW = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8128 static LPWSTR *ArglistW = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8129 static int global_argc = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8130 static char **global_argv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8131
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8132 static int used_file_argc = 0; // last argument in global_argv[] used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8133 // for the argument list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8134 static int *used_file_indexes = NULL; // indexes in global_argv[] for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8135 // command line arguments added to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8136 // the argument list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8137 static int used_file_count = 0; // nr of entries in used_file_indexes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8138 static int used_file_literal = FALSE; // take file names literally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8139 static int used_file_full_path = FALSE; // file name was full path
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8140 static int used_file_diff_mode = FALSE; // file name was with diff mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8141 static int used_alist_count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8143
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8144 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8145 * Get the command line arguments. Unicode version.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8146 * Returns argc. Zero when something fails.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8147 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8148 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8149 get_cmd_argsW(char ***argvp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8150 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8151 char **argv = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8152 int argc = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8153 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8155 free_cmd_argsW();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8156 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8157 if (ArglistW != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8158 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8159 argv = malloc((nArgsW + 1) * sizeof(char *));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8160 if (argv != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8161 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8162 argc = nArgsW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8163 argv[argc] = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8164 for (i = 0; i < argc; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8165 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8166 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8168 // Convert each Unicode argument to UTF-8.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8169 WideCharToMultiByte_alloc(CP_UTF8, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8170 ArglistW[i], (int)wcslen(ArglistW[i]) + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8171 (LPSTR *)&argv[i], &len, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8172 if (argv[i] == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8173 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8174 // Out of memory, clear everything.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8175 while (i > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8176 free(argv[--i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8177 free(argv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8178 argv = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8179 argc = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8180 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8181 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8182 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8183 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8185 global_argc = argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8186 global_argv = argv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8187 if (argc > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8188 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8189 if (used_file_indexes != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8190 free(used_file_indexes);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8191 used_file_indexes = malloc(argc * sizeof(int));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8192 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8193
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8194 if (argvp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8195 *argvp = argv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8196 return argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8197 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8198
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8199 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8200 free_cmd_argsW(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8201 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8202 if (ArglistW == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8203 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8204
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8205 GlobalFree(ArglistW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8206 ArglistW = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8207 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8209 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8210 * Remember "name" is an argument that was added to the argument list.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8211 * This avoids that we have to re-parse the argument list when fix_arg_enc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8212 * is called.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8213 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8214 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8215 used_file_arg(char *name, int literal, int full_path, int diff_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8216 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8217 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8219 if (used_file_indexes == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8220 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8221 for (i = used_file_argc + 1; i < global_argc; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8222 if (STRCMP(global_argv[i], name) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8223 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8224 used_file_argc = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8225 used_file_indexes[used_file_count++] = i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8226 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8227 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8228 used_file_literal = literal;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8229 used_file_full_path = full_path;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8230 used_file_diff_mode = diff_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8231 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8232
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8233 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8234 * Remember the length of the argument list as it was. If it changes then we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8235 * leave it alone when 'encoding' is set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8236 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8237 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8238 set_alist_count(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8239 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8240 used_alist_count = GARGCOUNT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8241 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8243 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8244 * Fix the encoding of the command line arguments. Invoked when 'encoding'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8245 * has been changed while starting up. Use the UTF-16 command line arguments
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8246 * and convert them to 'encoding'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8247 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8248 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8249 fix_arg_enc(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8250 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8251 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8252 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8253 char_u *str;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8254 int *fnum_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8256 // Safety checks:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8257 // - if argument count differs between the wide and non-wide argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8258 // list, something must be wrong.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8259 // - the file name arguments must have been located.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8260 // - the length of the argument list wasn't changed by the user.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8261 if (global_argc != nArgsW
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8262 || ArglistW == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8263 || used_file_indexes == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8264 || used_file_count == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8265 || used_alist_count != GARGCOUNT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8266 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8268 // Remember the buffer numbers for the arguments.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8269 fnum_list = ALLOC_MULT(int, GARGCOUNT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8270 if (fnum_list == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8271 return; // out of memory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8272 for (i = 0; i < GARGCOUNT; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8273 fnum_list[i] = GARGLIST[i].ae_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8274
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8275 // Clear the argument list. Make room for the new arguments.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8276 alist_clear(&global_alist);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8277 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8278 return; // out of memory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8279
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8280 for (i = 0; i < used_file_count; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8281 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8282 idx = used_file_indexes[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8283 str = utf16_to_enc(ArglistW[idx], NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8284 if (str != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8285 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8286 int literal = used_file_literal;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8288 #ifdef FEAT_DIFF
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8289 // When using diff mode may need to concatenate file name to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8290 // directory name. Just like it's done in main().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8291 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8292 && !mch_isdir(alist_name(&GARGLIST[0])))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8293 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8294 char_u *r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8296 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8297 if (r != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8298 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8299 vim_free(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8300 str = r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8301 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8302 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8303 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8304 // Re-use the old buffer by renaming it. When not using literal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8305 // names it's done by alist_expand() below.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8306 if (used_file_literal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8307 buf_set_name(fnum_list[i], str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8309 // Check backtick literal. backtick literal is already expanded in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8310 // main.c, so this part add str as literal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8311 if (literal == FALSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8312 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8313 size_t len = STRLEN(str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8314
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8315 if (len > 2 && *str == '`' && *(str + len - 1) == '`')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8316 literal = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8318 alist_add(&global_alist, str, literal ? 2 : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8319 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8320 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8322 if (!used_file_literal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8323 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8324 // Now expand wildcards in the arguments.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8325 // Temporarily add '(' and ')' to 'isfname'. These are valid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8326 // filename characters but are excluded from 'isfname' to make
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8327 // "gf" work on a file name in parentheses (e.g.: see vim.h).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8328 // Also, unset wildignore to not be influenced by this option.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8329 // The arguments specified in command-line should be kept even if
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8330 // encoding options were changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8331 // Use :legacy so that it also works when in Vim9 script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8332 do_cmdline_cmd((char_u *)":legacy let g:SaVe_ISF = &isf|set isf+=(,)");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8333 do_cmdline_cmd((char_u *)":legacy let g:SaVe_WIG = &wig|set wig=");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8334 alist_expand(fnum_list, used_alist_count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8335 do_cmdline_cmd(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8336 (char_u *)":legacy let &isf = g:SaVe_ISF|unlet g:SaVe_ISF");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8337 do_cmdline_cmd(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8338 (char_u *)":legacy let &wig = g:SaVe_WIG|unlet g:SaVe_WIG");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8339 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8341 // If wildcard expansion failed, we are editing the first file of the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8342 // arglist and there is no file name: Edit the first argument now.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8343 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8344 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8345 do_cmdline_cmd((char_u *)":rewind");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8346 if (GARGCOUNT == 1 && used_file_full_path
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8347 && vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8348 last_chdir_reason = "drop";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8349 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8351 set_alist_count();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8352 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8354 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8355 mch_setenv(char *var, char *value, int x UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8356 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8357 char_u *envbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8358 WCHAR *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8360 envbuf = alloc(STRLEN(var) + STRLEN(value) + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8361 if (envbuf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8362 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8364 sprintf((char *)envbuf, "%s=%s", var, value);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8365
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8366 p = enc_to_utf16(envbuf, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8367
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8368 vim_free(envbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8369 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8370 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8371 _wputenv(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8372 #ifdef libintl_wputenv
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8373 libintl_wputenv(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8374 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8375 // Unlike Un*x systems, we can free the string for _wputenv().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8376 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8377
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8378 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8379 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8381 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8382 * Support for 256 colors and 24-bit colors was added in Windows 10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8383 * version 1703 (Creators update).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8384 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8385 #define VTP_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 15063)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8386
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8387 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8388 * Support for pseudo-console (ConPTY) was added in windows 10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8389 * version 1809 (October 2018 update).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8390 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8391 #define CONPTY_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 17763)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8393 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8394 * ConPTY differences between versions, need different logic.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8395 * version 1903 (May 2019 update).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8396 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8397 #define CONPTY_1903_BUILD MAKE_VER(10, 0, 18362)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8398
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8399 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8400 * version 1909 (November 2019 update).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8401 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8402 #define CONPTY_1909_BUILD MAKE_VER(10, 0, 18363)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8404 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8405 * Stay ahead of the next update, and when it's done, fix this.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8406 * version ? (2020 update, temporarily use the build number of insider preview)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8407 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8408 #define CONPTY_NEXT_UPDATE_BUILD MAKE_VER(10, 0, 19587)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8409
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8410 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8411 * Confirm until this version. Also the logic changes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8412 * insider preview.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8413 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8414 #define CONPTY_INSIDER_BUILD MAKE_VER(10, 0, 18995)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8416 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8417 * Not stable now.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8418 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8419 #define CONPTY_STABLE_BUILD MAKE_VER(10, 0, 32767) // T.B.D.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8420 // Notes:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8421 // Win 10 22H2 Final is build 19045, it's conpty is widely used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8422 // Strangely, 19045 is newer but is a lower build number than the 2020 insider
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8423 // preview which had a build 19587. And, not sure how stable that was?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8424 // Win Server 2022 (May 10, 2022) is build 20348, its conpty is widely used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8425 // Win 11 starts from build 22000, even though the major version says 10!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8426
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8427 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8428 vtp_flag_init(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8429 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8430 DWORD ver = get_build_number();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8431 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8432 DWORD mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8433 HANDLE out;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8435 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8436 if (!gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8437 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8439 out = GetStdHandle(STD_OUTPUT_HANDLE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8441 vtp_working = (ver >= VTP_FIRST_SUPPORT_BUILD) ? 1 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8442 GetConsoleMode(out, &mode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8443 mode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8444 if (SetConsoleMode(out, mode) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8445 vtp_working = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8447 // VTP uses alternate screen buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8448 // But, not if running in a nested terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8449 use_alternate_screen_buffer = win10_22H2_or_later && p_rs && vtp_working
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8450 && !mch_getenv("VIM_TERMINAL");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8451 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8452 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8453
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8454 if (ver >= CONPTY_FIRST_SUPPORT_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8455 conpty_working = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8456 if (ver >= CONPTY_STABLE_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8457 conpty_stable = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8459 if (ver <= CONPTY_INSIDER_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8460 conpty_type = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8461 if (ver <= CONPTY_1909_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8462 conpty_type = 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8463 if (ver <= CONPTY_1903_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8464 conpty_type = 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8465 if (ver < CONPTY_FIRST_SUPPORT_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8466 conpty_type = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8468 if (ver >= CONPTY_NEXT_UPDATE_BUILD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8469 conpty_fix_type = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8470 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8471
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8472 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8473
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8474 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8475 vtp_init(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8476 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8477 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8478 CONSOLE_SCREEN_BUFFER_INFOEX csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8479 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8480 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8481 save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8482 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8483 store_console_bg_rgb = save_console_bg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8484 store_console_fg_rgb = save_console_fg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8485
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8486 COLORREF bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8487 bg = (COLORREF)csbi.ColorTable[g_color_index_bg];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8488 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8489 default_console_color_bg = bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8491 COLORREF fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8492 fg = (COLORREF)csbi.ColorTable[g_color_index_fg];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8493 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8494 default_console_color_fg = fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8495 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8496 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8497 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8499 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8500 vtp_exit(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8501 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8502 restore_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8503 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8504
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8505 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8506 vtp_printf(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8507 char *format,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8508 ...)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8509 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8510 char_u buf[100];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8511 va_list list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8512 DWORD result;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8513 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8514
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8515 va_start(list, format);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8516 len = vim_vsnprintf((char *)buf, 100, (char *)format, list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8517 va_end(list);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8518 WriteConsoleA(g_hConOut, buf, (DWORD)len, &result, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8519 return (int)result;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8520 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8522 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8523 vtp_sgr_bulk(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8524 int arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8525 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8526 int args[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8527
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8528 args[0] = arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8529 vtp_sgr_bulks(1, args);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8530 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8531
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8532 # define FAST256(x) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8533 if ((*p-- = "0123456789"[(n = x % 10)]) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8534 && x >= 10 && (*p-- = "0123456789"[((m = x % 100) - n) / 10]) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8535 && x >= 100 && (*p-- = "012"[((x & 0xff) - m) / 100]));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8537 # define FAST256CASE(x) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8538 case x: \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8539 FAST256(newargs[x - 1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8540
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8541 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8542 vtp_sgr_bulks(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8543 int argc,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8544 int *args)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8545 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8546 # define MAXSGR 16
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8547 # define SGRBUFSIZE 2 + 4 * MAXSGR + 1 // '\033[' + SGR + 'm'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8548 char_u buf[SGRBUFSIZE];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8549 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8550 int in, out;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8551 int newargs[16];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8552 static int sgrfgr = -1, sgrfgg, sgrfgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8553 static int sgrbgr = -1, sgrbgg, sgrbgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8554
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8555 if (argc == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8556 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8557 sgrfgr = sgrbgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8558 vtp_printf("\033[m");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8559 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8560 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8561
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8562 in = out = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8563 while (in < argc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8564 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8565 int s = args[in];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8566 int copylen = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8567
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8568 if (s == 38)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8569 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8570 if (argc - in >= 5 && args[in + 1] == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8571 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8572 if (sgrfgr == args[in + 2] && sgrfgg == args[in + 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8573 && sgrfgb == args[in + 4])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8574 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8575 in += 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8576 copylen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8577 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8578 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8579 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8580 sgrfgr = args[in + 2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8581 sgrfgg = args[in + 3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8582 sgrfgb = args[in + 4];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8583 copylen = 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8584 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8586 else if (argc - in >= 3 && args[in + 1] == 5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8587 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8588 sgrfgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8589 copylen = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8590 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8591 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8592 else if (s == 48)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8593 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8594 if (argc - in >= 5 && args[in + 1] == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8595 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8596 if (sgrbgr == args[in + 2] && sgrbgg == args[in + 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8597 && sgrbgb == args[in + 4])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8598 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8599 in += 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8600 copylen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8602 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8603 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8604 sgrbgr = args[in + 2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8605 sgrbgg = args[in + 3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8606 sgrbgb = args[in + 4];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8607 copylen = 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8608 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8609 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8610 else if (argc - in >= 3 && args[in + 1] == 5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8611 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8612 sgrbgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8613 copylen = 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8614 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8615 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8616 else if (30 <= s && s <= 39)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8617 sgrfgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8618 else if (90 <= s && s <= 97)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8619 sgrfgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8620 else if (40 <= s && s <= 49)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8621 sgrbgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8622 else if (100 <= s && s <= 107)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8623 sgrbgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8624 else if (s == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8625 sgrfgr = sgrbgr = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8627 while (copylen--)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8628 newargs[out++] = args[in++];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8629 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8630
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8631 p = &buf[sizeof(buf) - 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8632 *p-- = 'm';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8634 switch (out)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8635 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8636 int n, m;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8637 DWORD r;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8638
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8639 FAST256CASE(16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8640 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8641 FAST256CASE(15);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8642 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8643 FAST256CASE(14);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8644 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8645 FAST256CASE(13);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8646 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8647 FAST256CASE(12);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8648 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8649 FAST256CASE(11);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8650 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8651 FAST256CASE(10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8652 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8653 FAST256CASE(9);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8654 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8655 FAST256CASE(8);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8656 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8657 FAST256CASE(7);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8658 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8659 FAST256CASE(6);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8660 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8661 FAST256CASE(5);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8662 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8663 FAST256CASE(4);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8664 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8665 FAST256CASE(3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8666 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8667 FAST256CASE(2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8668 *p-- = ';';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8669 FAST256CASE(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8670 *p-- = '[';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8671 *p = '\033';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8672 WriteConsoleA(g_hConOut, p, (DWORD)(&buf[SGRBUFSIZE] - p), &r, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8673 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8674 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8675 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8676 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8678 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8679 wt_init(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8681 wt_working = mch_getenv("WT_SESSION") != NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8682 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8683
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8684 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8685 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8686 ctermtoxterm(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8687 int cterm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8688 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8689 char_u r, g, b, idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8690
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8691 cterm_color2rgb(cterm, &r, &g, &b, &idx);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8692 return (((int)r << 16) | ((int)g << 8) | (int)b);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8693 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8694 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8696 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8697 set_console_color_rgb(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8698 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8699 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8700 CONSOLE_SCREEN_BUFFER_INFOEX csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8701 guicolor_T fg, bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8702 int ctermfg, ctermbg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8703
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8704 if (!vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8705 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8706
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8707 get_default_console_color(&ctermfg, &ctermbg, &fg, &bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8709 if (p_tgc || t_colors >= 256)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8710 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8711 term_fg_rgb_color(fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8712 term_bg_rgb_color(bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8713 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8714 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8715
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8716 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8717 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8718
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8719 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8720 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8722 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8723 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8724
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8725 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8726 csbi.srWindow.Right += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8727 csbi.srWindow.Bottom += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8728 store_console_bg_rgb = csbi.ColorTable[g_color_index_bg];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8729 store_console_fg_rgb = csbi.ColorTable[g_color_index_fg];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8730 csbi.ColorTable[g_color_index_bg] = (COLORREF)bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8731 csbi.ColorTable[g_color_index_fg] = (COLORREF)fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8732 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8733 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8734 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8736 # if defined(FEAT_TERMGUICOLORS) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8737 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8738 get_default_console_color(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8739 int *cterm_fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8740 int *cterm_bg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8741 guicolor_T *gui_fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8742 guicolor_T *gui_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8743 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8744 int id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8745 guicolor_T guifg = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8746 guicolor_T guibg = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8747 int ctermfg = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8748 int ctermbg = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8749 int dummynull = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8751 id = syn_name2id((char_u *)"Normal");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8752 if (id > 0 && p_tgc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8753 syn_id2colors(id, &guifg, &guibg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8754 if (guifg == INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8755 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8756 ctermfg = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8757 if (id > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8758 syn_id2cterm_bg(id, &ctermfg, &dummynull);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8759 if (ctermfg != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8760 guifg = ctermtoxterm(ctermfg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8761 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8762 guifg = USE_WT ? INVALCOLOR : default_console_color_fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8763 cterm_normal_fg_gui_color = guifg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8764 ctermfg = ctermfg < 0 ? 0 : ctermfg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8765 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8766 if (guibg == INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8767 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8768 ctermbg = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8769 if (id > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8770 syn_id2cterm_bg(id, &dummynull, &ctermbg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8771 if (ctermbg != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8772 guibg = ctermtoxterm(ctermbg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8773 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8774 guibg = USE_WT ? INVALCOLOR : default_console_color_bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8775 cterm_normal_bg_gui_color = guibg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8776 ctermbg = ctermbg < 0 ? 0 : ctermbg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8777 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8778
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8779 *cterm_fg = ctermfg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8780 *cterm_bg = ctermbg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8781 *gui_fg = guifg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8782 *gui_bg = guibg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8783 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8784 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8785
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8786 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8787 * Set the console colors to the original colors or the last set colors.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8788 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8789 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8790 reset_console_color_rgb(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8791 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8792 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8793 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8794 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8795
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8796 CONSOLE_SCREEN_BUFFER_INFOEX csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8797
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8798 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8799 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8800
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8801 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8802 csbi.srWindow.Right += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8803 csbi.srWindow.Bottom += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8804 csbi.ColorTable[g_color_index_bg] = (COLORREF)store_console_bg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8805 csbi.ColorTable[g_color_index_fg] = (COLORREF)store_console_fg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8806 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8807 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8808 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8809
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8810 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8811 * Set the console colors to the original colors.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8812 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8813 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8814 restore_console_color_rgb(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8815 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8816 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8817 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8818 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8819
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8820 CONSOLE_SCREEN_BUFFER_INFOEX csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8821
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8822 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8823 GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8825 csbi.cbSize = sizeof(csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8826 csbi.srWindow.Right += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8827 csbi.srWindow.Bottom += 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8828 csbi.ColorTable[g_color_index_bg] = (COLORREF)save_console_bg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8829 csbi.ColorTable[g_color_index_fg] = (COLORREF)save_console_fg_rgb;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8830 SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8831 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8832 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8833
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8834 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8835 control_console_color_rgb(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8836 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8837 if (vtp_working)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8838 set_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8839 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8840 reset_console_color_rgb();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8841 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8843 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8844 use_vtp(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8845 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8846 return USE_VTP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8847 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8848
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8849 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8850 is_term_win32(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8851 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8852 return T_NAME != NULL && STRCMP(T_NAME, "win32") == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8853 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8854
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8855 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8856 has_vtp_working(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8857 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8858 return vtp_working;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8859 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8861 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8862
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8863 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8864 has_conpty_working(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8865 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8866 return conpty_working;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8867 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8868
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8869 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8870 get_conpty_type(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8871 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8872 return conpty_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8873 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8874
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8875 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8876 is_conpty_stable(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8877 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8878 return conpty_stable;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8879 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8881 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8882 get_conpty_fix_type(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8883 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8884 return conpty_fix_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8885 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8886
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8887 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8888 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8889 resize_console_buf(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8890 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8891 if (use_alternate_screen_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8892 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8893
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8894 CONSOLE_SCREEN_BUFFER_INFO csbi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8895 COORD coord;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8896 SMALL_RECT newsize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8898 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8899 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8900
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8901 coord.X = SRWIDTH(csbi.srWindow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8902 coord.Y = SRHEIGHT(csbi.srWindow);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8903 SetConsoleScreenBufferSize(g_hConOut, coord);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8904
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8905 newsize.Left = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8906 newsize.Top = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8907 newsize.Right = coord.X - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8908 newsize.Bottom = coord.Y - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8909 SetConsoleWindowInfo(g_hConOut, TRUE, &newsize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8910
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8911 SetConsoleScreenBufferSize(g_hConOut, coord);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8912 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8913 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8914
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8915 char *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8916 GetWin32Error(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8917 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8918 static char *oldmsg = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8919 char *msg = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8920
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8921 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8922 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8923 if (oldmsg != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8924 LocalFree(oldmsg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8925 if (msg == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8926 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8927
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8928 // remove trailing \r\n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8929 char *pcrlf = strstr(msg, "\r\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8930 if (pcrlf != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8931 *pcrlf = '\0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8932 oldmsg = msg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8933 return msg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8934 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8935
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8936 #if defined(FEAT_RELTIME) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8937 static HANDLE timer_handle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8938 static int timer_active = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8939
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8940 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8941 * Calls to start_timeout alternate the return value pointer between the two
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8942 * entries in timeout_flags. If the previously active timeout is very close to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8943 * expiring when start_timeout() is called then a race condition means that the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8944 * set_flag() function may still be invoked after the previous timer is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8945 * deleted. Ping-ponging between the two flags prevents this causing 'fake'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8946 * timeouts.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8947 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8948 static sig_atomic_t timeout_flags[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8949 static int timeout_flag_idx = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8950 static sig_atomic_t *timeout_flag = &timeout_flags[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8951
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8953 static void CALLBACK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8954 set_flag(void *param, BOOLEAN unused2 UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8955 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8956 int *timeout_flag = (int *)param;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8957
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8958 *timeout_flag = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8959 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8961 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8962 * Stop any active timeout.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8963 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8964 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8965 stop_timeout(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8966 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8967 if (timer_active)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8968 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8969 BOOL ret = DeleteTimerQueueTimer(NULL, timer_handle, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8970 timer_active = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8971 if (!ret && GetLastError() != ERROR_IO_PENDING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8972 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8973 semsg(_(e_could_not_clear_timeout_str), GetWin32Error());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8974 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8975 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8976 *timeout_flag = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8977 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8978
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8979 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8980 * Start the timeout timer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8981 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8982 * The period is defined in milliseconds.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8983 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8984 * The return value is a pointer to a flag that is initialised to 0. If the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8985 * timeout expires, the flag is set to 1. This will only return pointers to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8986 * static memory; i.e. any pointer returned by this function may always be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8987 * safely dereferenced.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8988 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8989 * This function is not expected to fail, but if it does it still returns a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8990 * valid flag pointer; the flag will remain stuck at zero.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8991 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8992 volatile sig_atomic_t *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8993 start_timeout(long msec)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8994 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8995 BOOL ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8997 timeout_flag = &timeout_flags[timeout_flag_idx];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8998
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
8999 stop_timeout();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9000 ret = CreateTimerQueueTimer(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9001 &timer_handle, NULL, set_flag, timeout_flag,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9002 (DWORD)msec, 0, WT_EXECUTEDEFAULT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9003 if (!ret)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9004 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9005 semsg(_(e_could_not_set_timeout_str), GetWin32Error());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9006 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9007 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9008 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9009 timeout_flag_idx = (timeout_flag_idx + 1) % 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9010 timer_active = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9011 *timeout_flag = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9012 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9013 return timeout_flag;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9014 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32458
diff changeset
9015 #endif