Mercurial > vim
annotate src/os_unix.c @ 14366:1c79c92a642e v8.1.0198
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
commit https://github.com/vim/vim/commit/0a6efcd27d62935c465b4406c0c0db9be10a0ddb
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 20 19:56:10 2018 +0200
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Problem: There is no hint that syntax is disabled for 'redrawtime'.
Solution: Add a message.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 20 Jul 2018 20:00:06 +0200 |
parents | 4d3f6bf86bec |
children | 65b222617852 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10019
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * OS/2 port by Paul Slootman | |
5 * VMS merge by Zoltan Arpadffy | |
6 * | |
7 * Do ":help uganda" in Vim to read copying and usage conditions. | |
8 * Do ":help credits" in Vim to see a list of people who contributed. | |
9 * See README.txt for an overview of the Vim source code. | |
10 */ | |
11 | |
12 /* | |
13 * os_unix.c -- code for all flavors of Unix (BSD, SYSV, SVR4, POSIX, ...) | |
14 * Also for OS/2, using the excellent EMX package!!! | |
15 * Also for BeOS and Atari MiNT. | |
16 * | |
17 * A lot of this file was originally written by Juergen Weigert and later | |
18 * changed beyond recognition. | |
19 */ | |
20 | |
21 /* | |
22 * Some systems have a prototype for select() that has (int *) instead of | |
23 * (fd_set *), which is wrong. This define removes that prototype. We define | |
24 * our own prototype below. | |
25 * Don't use it for the Mac, it causes a warning for precompiled headers. | |
26 * TODO: use a configure check for precompiled headers? | |
27 */ | |
1076 | 28 #if !defined(__APPLE__) && !defined(__TANDEM) |
7 | 29 # define select select_declared_wrong |
30 #endif | |
31 | |
32 #include "vim.h" | |
33 | |
14 | 34 #ifdef FEAT_MZSCHEME |
35 # include "if_mzsch.h" | |
36 #endif | |
37 | |
7 | 38 #include "os_unixx.h" /* unix includes for os_unix.c only */ |
39 | |
40 #ifdef USE_XSMP | |
41 # include <X11/SM/SMlib.h> | |
42 #endif | |
43 | |
1583 | 44 #ifdef HAVE_SELINUX |
45 # include <selinux/selinux.h> | |
46 static int selinux_enabled = -1; | |
47 #endif | |
48 | |
5788 | 49 #ifdef HAVE_SMACK |
50 # include <attr/xattr.h> | |
51 # include <linux/xattr.h> | |
52 # ifndef SMACK_LABEL_LEN | |
53 # define SMACK_LABEL_LEN 1024 | |
54 # endif | |
55 #endif | |
56 | |
7 | 57 /* |
58 * Use this prototype for select, some include files have a wrong prototype | |
59 */ | |
1076 | 60 #ifndef __TANDEM |
61 # undef select | |
62 # ifdef __BEOS__ | |
63 # define select beos_select | |
64 # endif | |
7 | 65 #endif |
66 | |
1102 | 67 #ifdef __CYGWIN__ |
68 # ifndef WIN32 | |
1657 | 69 # include <cygwin/version.h> |
70 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or | |
71 * for cygwin_conv_path() */ | |
4168 | 72 # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
73 # define WIN32_LEAN_AND_MEAN | |
74 # include <windows.h> | |
75 # include "winclip.pro" | |
76 # endif | |
1102 | 77 # endif |
78 #endif | |
79 | |
7 | 80 #if defined(HAVE_SELECT) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
81 extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); |
7 | 82 #endif |
83 | |
84 #ifdef FEAT_MOUSE_GPM | |
85 # include <gpm.h> | |
86 /* <linux/keyboard.h> contains defines conflicting with "keymap.h", | |
87 * I just copied relevant defines here. A cleaner solution would be to put gpm | |
88 * code into separate file and include there linux/keyboard.h | |
89 */ | |
90 /* #include <linux/keyboard.h> */ | |
91 # define KG_SHIFT 0 | |
92 # define KG_CTRL 2 | |
93 # define KG_ALT 3 | |
94 # define KG_ALTGR 1 | |
95 # define KG_SHIFTL 4 | |
96 # define KG_SHIFTR 5 | |
97 # define KG_CTRLL 6 | |
98 # define KG_CTRLR 7 | |
99 # define KG_CAPSSHIFT 8 | |
100 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
101 static void gpm_close(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
102 static int gpm_open(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
103 static int mch_gpm_process(void); |
7 | 104 #endif |
105 | |
1620 | 106 #ifdef FEAT_SYSMOUSE |
107 # include <sys/consio.h> | |
108 # include <sys/fbio.h> | |
109 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
110 static int sysmouse_open(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
111 static void sysmouse_close(void); |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
112 static RETSIGTYPE sig_sysmouse SIGPROTOARG; |
1620 | 113 #endif |
114 | |
7 | 115 /* |
116 * end of autoconf section. To be extended... | |
117 */ | |
118 | |
119 /* Are the following #ifdefs still required? And why? Is that for X11? */ | |
120 | |
121 #if defined(ESIX) || defined(M_UNIX) && !defined(SCO) | |
122 # ifdef SIGWINCH | |
123 # undef SIGWINCH | |
124 # endif | |
125 # ifdef TIOCGWINSZ | |
126 # undef TIOCGWINSZ | |
127 # endif | |
128 #endif | |
129 | |
130 #if defined(SIGWINDOW) && !defined(SIGWINCH) /* hpux 9.01 has it */ | |
131 # define SIGWINCH SIGWINDOW | |
132 #endif | |
133 | |
134 #ifdef FEAT_X11 | |
135 # include <X11/Xlib.h> | |
136 # include <X11/Xutil.h> | |
137 # include <X11/Xatom.h> | |
138 # ifdef FEAT_XCLIPBOARD | |
139 # include <X11/Intrinsic.h> | |
140 # include <X11/Shell.h> | |
141 # include <X11/StringDefs.h> | |
142 static Widget xterm_Shell = (Widget)0; | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
143 static void clip_update(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
144 static void xterm_update(void); |
7 | 145 # endif |
146 | |
147 # if defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE) | |
148 Window x11_window = 0; | |
149 # endif | |
150 Display *x11_display = NULL; | |
151 | |
152 # ifdef FEAT_TITLE | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
153 static int get_x11_windis(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
154 static void set_x11_title(char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
155 static void set_x11_icon(char_u *); |
7 | 156 # endif |
157 #endif | |
158 | |
159 #ifdef FEAT_TITLE | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
160 static int get_x11_title(int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
161 static int get_x11_icon(int); |
7 | 162 |
163 static char_u *oldtitle = NULL; | |
164 static int did_set_title = FALSE; | |
165 static char_u *oldicon = NULL; | |
166 static int did_set_icon = FALSE; | |
167 #endif | |
168 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
169 static void may_core_dump(void); |
7 | 170 |
3048 | 171 #ifdef HAVE_UNION_WAIT |
172 typedef union wait waitstatus; | |
173 #else | |
174 typedef int waitstatus; | |
175 #endif | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
176 static pid_t wait4pid(pid_t, waitstatus *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
177 |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
178 static int WaitForChar(long msec, int *interrupted, int ignore_input); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
179 static int WaitForCharOrMouse(long msec, int *interrupted, int ignore_input); |
5541 | 180 #if defined(__BEOS__) || defined(VMS) |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
181 int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 182 #else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
183 static int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 184 #endif |
185 | |
186 #ifdef FEAT_XCLIPBOARD | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
187 static int do_xterm_trace(void); |
331 | 188 # define XT_TRACE_DELAY 50 /* delay for xterm tracing */ |
7 | 189 #endif |
190 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
191 static void handle_resize(void); |
7 | 192 |
193 #if defined(SIGWINCH) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
194 static RETSIGTYPE sig_winch SIGPROTOARG; |
7 | 195 #endif |
196 #if defined(SIGINT) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
197 static RETSIGTYPE catch_sigint SIGPROTOARG; |
7 | 198 #endif |
199 #if defined(SIGPWR) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
200 static RETSIGTYPE catch_sigpwr SIGPROTOARG; |
7 | 201 #endif |
202 #if defined(SIGALRM) && defined(FEAT_X11) \ | |
203 && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) | |
204 # define SET_SIG_ALARM | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
205 static RETSIGTYPE sig_alarm SIGPROTOARG; |
1832 | 206 /* volatile because it is used in signal handler sig_alarm(). */ |
207 static volatile int sig_alarm_called; | |
7 | 208 #endif |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
209 static RETSIGTYPE deathtrap SIGPROTOARG; |
7 | 210 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
211 static void catch_int_signal(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
212 static void set_signals(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
213 static void catch_signals(RETSIGTYPE (*func_deadly)(), RETSIGTYPE (*func_other)()); |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
214 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
215 # define SIGSET_DECL(set) sigset_t set; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
216 # define BLOCK_SIGNALS(set) block_signals(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
217 # define UNBLOCK_SIGNALS(set) unblock_signals(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
218 #else |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
219 # define SIGSET_DECL(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
220 # define BLOCK_SIGNALS(set) do { /**/ } while (0) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
221 # define UNBLOCK_SIGNALS(set) do { /**/ } while (0) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
222 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
223 static int have_wildcard(int, char_u **); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
224 static int have_dollars(int, char_u **); |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
225 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
226 static int save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file); |
7 | 227 |
228 #ifndef SIG_ERR | |
1879 | 229 # define SIG_ERR ((RETSIGTYPE (*)())-1) |
7 | 230 #endif |
231 | |
1832 | 232 /* volatile because it is used in signal handler sig_winch(). */ |
233 static volatile int do_resize = FALSE; | |
7 | 234 static char_u *extra_shell_arg = NULL; |
235 static int show_shell_mess = TRUE; | |
1832 | 236 /* volatile because it is used in signal handler deathtrap(). */ |
237 static volatile int deadly_signal = 0; /* The signal we caught */ | |
238 /* volatile because it is used in signal handler deathtrap(). */ | |
239 static volatile int in_mch_delay = FALSE; /* sleeping in mch_delay() */ | |
7 | 240 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
241 #if defined(FEAT_JOB_CHANNEL) && !defined(USE_SYSTEM) |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
242 static int dont_check_job_ended = 0; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
243 #endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
244 |
7 | 245 static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ |
246 | |
247 #ifdef USE_XSMP | |
248 typedef struct | |
249 { | |
250 SmcConn smcconn; /* The SM connection ID */ | |
251 IceConn iceconn; /* The ICE connection ID */ | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
252 char *clientid; /* The client ID for the current smc session */ |
7 | 253 Bool save_yourself; /* If we're in the middle of a save_yourself */ |
254 Bool shutdown; /* If we're in shutdown mode */ | |
255 } xsmp_config_T; | |
256 | |
257 static xsmp_config_T xsmp; | |
258 #endif | |
259 | |
260 #ifdef SYS_SIGLIST_DECLARED | |
261 /* | |
262 * I have seen | |
263 * extern char *_sys_siglist[NSIG]; | |
264 * on Irix, Linux, NetBSD and Solaris. It contains a nice list of strings | |
265 * that describe the signals. That is nearly what we want here. But | |
266 * autoconf does only check for sys_siglist (without the underscore), I | |
267 * do not want to change everything today.... jw. | |
10375
2055d3722c5b
commit https://github.com/vim/vim/commit/3f7d0907269558cb3ea184a3083640f9e20bb21e
Christian Brabandt <cb@256bit.org>
parents:
10353
diff
changeset
|
268 * This is why AC_DECL_SYS_SIGLIST is commented out in configure.ac. |
7 | 269 */ |
270 #endif | |
271 | |
272 static struct signalinfo | |
273 { | |
274 int sig; /* Signal number, eg. SIGSEGV etc */ | |
275 char *name; /* Signal name (not char_u!). */ | |
276 char deadly; /* Catch as a deadly signal? */ | |
277 } signal_info[] = | |
278 { | |
279 #ifdef SIGHUP | |
280 {SIGHUP, "HUP", TRUE}, | |
281 #endif | |
282 #ifdef SIGQUIT | |
283 {SIGQUIT, "QUIT", TRUE}, | |
284 #endif | |
285 #ifdef SIGILL | |
286 {SIGILL, "ILL", TRUE}, | |
287 #endif | |
288 #ifdef SIGTRAP | |
289 {SIGTRAP, "TRAP", TRUE}, | |
290 #endif | |
291 #ifdef SIGABRT | |
292 {SIGABRT, "ABRT", TRUE}, | |
293 #endif | |
294 #ifdef SIGEMT | |
295 {SIGEMT, "EMT", TRUE}, | |
296 #endif | |
297 #ifdef SIGFPE | |
298 {SIGFPE, "FPE", TRUE}, | |
299 #endif | |
300 #ifdef SIGBUS | |
301 {SIGBUS, "BUS", TRUE}, | |
302 #endif | |
4074 | 303 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) |
304 /* MzScheme uses SEGV in its garbage collector */ | |
7 | 305 {SIGSEGV, "SEGV", TRUE}, |
306 #endif | |
307 #ifdef SIGSYS | |
308 {SIGSYS, "SYS", TRUE}, | |
309 #endif | |
310 #ifdef SIGALRM | |
311 {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ | |
312 #endif | |
313 #ifdef SIGTERM | |
314 {SIGTERM, "TERM", TRUE}, | |
315 #endif | |
2701 | 316 #if defined(SIGVTALRM) && !defined(FEAT_RUBY) |
7 | 317 {SIGVTALRM, "VTALRM", TRUE}, |
318 #endif | |
1560 | 319 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) |
320 /* MzScheme uses SIGPROF for its own needs; On Linux with profiling | |
321 * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ | |
7 | 322 {SIGPROF, "PROF", TRUE}, |
323 #endif | |
324 #ifdef SIGXCPU | |
325 {SIGXCPU, "XCPU", TRUE}, | |
326 #endif | |
327 #ifdef SIGXFSZ | |
328 {SIGXFSZ, "XFSZ", TRUE}, | |
329 #endif | |
330 #ifdef SIGUSR1 | |
331 {SIGUSR1, "USR1", TRUE}, | |
332 #endif | |
1620 | 333 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) |
334 /* Used for sysmouse handling */ | |
7 | 335 {SIGUSR2, "USR2", TRUE}, |
336 #endif | |
337 #ifdef SIGINT | |
338 {SIGINT, "INT", FALSE}, | |
339 #endif | |
340 #ifdef SIGWINCH | |
341 {SIGWINCH, "WINCH", FALSE}, | |
342 #endif | |
343 #ifdef SIGTSTP | |
344 {SIGTSTP, "TSTP", FALSE}, | |
345 #endif | |
346 #ifdef SIGPIPE | |
347 {SIGPIPE, "PIPE", FALSE}, | |
348 #endif | |
349 {-1, "Unknown!", FALSE} | |
350 }; | |
351 | |
1935 | 352 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
353 mch_chdir(char *path) |
1935 | 354 { |
355 if (p_verbose >= 5) | |
356 { | |
357 verbose_enter(); | |
358 smsg((char_u *)"chdir(%s)", path); | |
359 verbose_leave(); | |
360 } | |
361 # ifdef VMS | |
362 return chdir(vms_fixfilename(path)); | |
363 # else | |
364 return chdir(path); | |
365 # endif | |
366 } | |
367 | |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
368 /* Why is NeXT excluded here (and not in os_unixx.h)? */ |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
369 #if defined(ECHOE) && defined(ICANON) && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) && !defined(__NeXT__) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
370 # define NEW_TTY_SYSTEM |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
371 #endif |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
372 |
1757 | 373 /* |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
374 * Write s[len] to the screen (stdout). |
1757 | 375 */ |
7 | 376 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
377 mch_write(char_u *s, int len) |
7 | 378 { |
1757 | 379 ignored = (int)write(1, (char *)s, len); |
7 | 380 if (p_wd) /* Unix is too fast, slow down a bit more */ |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
381 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); |
7 | 382 } |
383 | |
384 /* | |
1450 | 385 * mch_inchar(): low level input function. |
7 | 386 * Get a characters from the keyboard. |
387 * Return the number of characters that are available. | |
388 * If wtime == 0 do not wait for characters. | |
389 * If wtime == n wait a short time for characters. | |
390 * If wtime == -1 wait forever for characters. | |
391 */ | |
392 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
393 mch_inchar( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
394 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
395 int maxlen, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
396 long wtime, /* don't use "time", MIPS cannot handle it */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
397 int tb_change_cnt) |
7 | 398 { |
399 int len; | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
400 int interrupted = FALSE; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
401 int did_start_blocking = FALSE; |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
402 long wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
403 long elapsed_time = 0; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
404 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
405 ELAPSED_TYPE start_tv; |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
406 |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
407 ELAPSED_INIT(start_tv); |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
408 #endif |
7 | 409 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
410 /* repeat until we got a character or waited long enough */ |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
411 for (;;) |
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
412 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
413 /* Check if window changed size while we were busy, perhaps the ":set |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
414 * columns=99" command was used. */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
415 while (do_resize) |
7 | 416 handle_resize(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
417 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
418 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
419 parse_queued_messages(); |
11834
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11826
diff
changeset
|
420 /* If input was put directly in typeahead buffer bail out here. */ |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11826
diff
changeset
|
421 if (typebuf_changed(tb_change_cnt)) |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11826
diff
changeset
|
422 return 0; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
423 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
424 if (wtime < 0 && did_start_blocking) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
425 /* blocking and already waited for p_ut */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
426 wait_time = -1; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
427 else |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
428 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
429 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
430 wait_time = wtime; |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
431 else |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
432 /* going to block after p_ut */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
433 wait_time = p_ut; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
434 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
435 elapsed_time = ELAPSED_FUNC(start_tv); |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
436 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
437 wait_time -= elapsed_time; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
438 if (wait_time < 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
439 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
440 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
441 /* no character available within "wtime" */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
442 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
443 |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
444 else |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
445 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
446 /* no character available within 'updatetime' */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
447 did_start_blocking = TRUE; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
448 if (trigger_cursorhold() && maxlen >= 3 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
449 && !typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
450 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
451 buf[0] = K_SPECIAL; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
452 buf[1] = KS_EXTRA; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
453 buf[2] = (int)KE_CURSORHOLD; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
454 return 3; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
455 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
456 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
457 * If there is no character available within 'updatetime' |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
458 * seconds flush all the swap files to disk. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
459 * Also done when interrupted by SIGWINCH. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
460 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
461 before_blocking(); |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
462 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
463 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
464 } |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
465 } |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
466 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
467 #ifdef FEAT_JOB_CHANNEL |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
468 /* Checking if a job ended requires polling. Do this every 100 msec. */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
469 if (has_pending_job() && (wait_time < 0 || wait_time > 100L)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
470 wait_time = 100L; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
471 /* If there is readahead then parse_queued_messages() timed out and we |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
472 * should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
473 if ((wait_time < 0 || wait_time > 100L) && channel_any_readahead()) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
474 wait_time = 10L; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
475 #endif |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
476 #ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
477 if (p_beval && wait_time > 100L) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
478 /* The 'balloonexpr' may indirectly invoke a callback while waiting |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
479 * for a character, need to check often. */ |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
480 wait_time = 100L; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
481 #endif |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
482 |
7 | 483 /* |
2436 | 484 * We want to be interrupted by the winch signal |
485 * or by an event on the monitored file descriptors. | |
7 | 486 */ |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
487 if (WaitForChar(wait_time, &interrupted, FALSE)) |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
488 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
489 /* If input was put directly in typeahead buffer bail out here. */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
490 if (typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
491 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
492 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
493 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
494 * For some terminals we only get one character at a time. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
495 * We want the get all available characters, so we could keep on |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
496 * trying until none is available |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
497 * For some other terminals this is quite slow, that's why we don't |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
498 * do it. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
499 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
500 len = read_from_input_buf(buf, (long)maxlen); |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
501 if (len > 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
502 return len; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
503 continue; |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
504 } |
7 | 505 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
506 /* no character available */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
507 #if !(defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
508 /* estimate the elapsed time */ |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
509 elapsed_time += wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
510 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
511 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
512 if (do_resize /* interrupted by SIGWINCH signal */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
513 #ifdef FEAT_CLIENTSERVER |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
514 || server_waiting() |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
515 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
516 #ifdef MESSAGE_QUEUE |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
517 || interrupted |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
518 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
519 || wait_time > 0 |
11252
d7c1d5f7cf2a
patch 8.0.0512: check for available characters takes too long
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
520 || (wtime < 0 && !did_start_blocking)) |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
521 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
522 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
523 /* no character available or interrupted */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
524 break; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
525 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
526 return 0; |
7 | 527 } |
528 | |
529 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
530 handle_resize(void) |
7 | 531 { |
532 do_resize = FALSE; | |
533 shell_resized(); | |
534 } | |
535 | |
536 /* | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
537 * Return non-zero if a character is available. |
7 | 538 */ |
539 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
540 mch_char_avail(void) |
7 | 541 { |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
542 return WaitForChar(0L, NULL, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
543 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
544 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
545 #if defined(FEAT_TERMINAL) || defined(PROTO) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
546 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
547 * Check for any pending input or messages. |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
548 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
549 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
550 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
551 { |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
552 return WaitForChar(0L, NULL, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
553 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
554 #endif |
7 | 555 |
556 #if defined(HAVE_TOTAL_MEM) || defined(PROTO) | |
557 # ifdef HAVE_SYS_RESOURCE_H | |
1879 | 558 # include <sys/resource.h> |
7 | 559 # endif |
560 # if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTL) | |
561 # include <sys/sysctl.h> | |
562 # endif | |
563 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) | |
564 # include <sys/sysinfo.h> | |
565 # endif | |
13396
5252ca53093a
patch 8.0.1572: Mac: getting memory size doesn't work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13388
diff
changeset
|
566 # ifdef MACOS_X |
13355
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
567 # include <mach/mach_host.h> |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
568 # include <mach/mach_port.h> |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
569 # endif |
7 | 570 |
571 /* | |
1110 | 572 * Return total amount of memory available in Kbyte. |
573 * Doesn't change when memory has been allocated. | |
7 | 574 */ |
575 long_u | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
576 mch_total_mem(int special UNUSED) |
7 | 577 { |
578 long_u mem = 0; | |
1110 | 579 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ |
7 | 580 |
13396
5252ca53093a
patch 8.0.1572: Mac: getting memory size doesn't work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13388
diff
changeset
|
581 # ifdef MACOS_X |
13355
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
582 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
583 /* Mac (Darwin) way of getting the amount of RAM available */ |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
584 mach_port_t host = mach_host_self(); |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
585 kern_return_t kret; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
586 # ifdef HOST_VM_INFO64 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
587 struct vm_statistics64 vm_stat; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
588 natural_t count = HOST_VM_INFO64_COUNT; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
589 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
590 kret = host_statistics64(host, HOST_VM_INFO64, |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
591 (host_info64_t)&vm_stat, &count); |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
592 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
593 struct vm_statistics vm_stat; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
594 natural_t count = HOST_VM_INFO_COUNT; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
595 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
596 kret = host_statistics(host, HOST_VM_INFO, |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
597 (host_info_t)&vm_stat, &count); |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
598 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
599 if (kret == KERN_SUCCESS) |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
600 /* get the amount of user memory by summing each usage */ |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
601 mem = (long_u)(vm_stat.free_count + vm_stat.active_count |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
602 + vm_stat.inactive_count |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
603 # ifdef MAC_OS_X_VERSION_10_9 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
604 + vm_stat.compressor_page_count |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
605 # endif |
13511
8db9449b5c79
patch 8.0.1629: Mac: getpagesize() is deprecated
Christian Brabandt <cb@256bit.org>
parents:
13478
diff
changeset
|
606 ) * sysconf(_SC_PAGESIZE); |
13355
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
607 mach_port_deallocate(mach_task_self(), host); |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
608 } |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
609 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
610 |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
611 # ifdef HAVE_SYSCTL |
13355
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
612 if (mem == 0) |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
613 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
614 /* BSD way of getting the amount of RAM available. */ |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
615 int mib[2]; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
616 size_t len = sizeof(long_u); |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
617 # ifdef HW_USERMEM64 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
618 long_u physmem; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
619 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
620 /* sysctl() may return 32 bit or 64 bit, accept both */ |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
621 union { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
622 int_u u32; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
623 long_u u64; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
624 } physmem; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
625 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
626 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
627 mib[0] = CTL_HW; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
628 # ifdef HW_USERMEM64 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
629 mib[1] = HW_USERMEM64; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
630 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
631 mib[1] = HW_USERMEM; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
632 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
633 if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0) |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
634 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
635 # ifdef HW_USERMEM64 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
636 mem = (long_u)physmem; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
637 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
638 if (len == sizeof(physmem.u64)) |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
639 mem = (long_u)physmem.u64; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
640 else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
641 mem = (long_u)physmem.u32; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
642 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
643 } |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
644 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
645 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
646 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
647 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) |
7 | 648 if (mem == 0) |
649 { | |
650 struct sysinfo sinfo; | |
651 | |
652 /* Linux way of getting amount of RAM available */ | |
653 if (sysinfo(&sinfo) == 0) | |
1110 | 654 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
655 # ifdef HAVE_SYSINFO_MEM_UNIT |
1110 | 656 /* avoid overflow as much as possible */ |
657 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) | |
658 { | |
659 sinfo.mem_unit = sinfo.mem_unit >> 1; | |
660 --shiftright; | |
661 } | |
662 mem = sinfo.totalram * sinfo.mem_unit; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
663 # else |
7 | 664 mem = sinfo.totalram; |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
665 # endif |
1110 | 666 } |
7 | 667 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
668 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
669 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
670 # ifdef HAVE_SYSCONF |
7 | 671 if (mem == 0) |
672 { | |
673 long pagesize, pagecount; | |
674 | |
675 /* Solaris way of getting amount of RAM available */ | |
676 pagesize = sysconf(_SC_PAGESIZE); | |
677 pagecount = sysconf(_SC_PHYS_PAGES); | |
678 if (pagesize > 0 && pagecount > 0) | |
1110 | 679 { |
680 /* avoid overflow as much as possible */ | |
681 while (shiftright > 0 && (pagesize & 1) == 0) | |
682 { | |
1204 | 683 pagesize = (long_u)pagesize >> 1; |
1110 | 684 --shiftright; |
685 } | |
7 | 686 mem = (long_u)pagesize * pagecount; |
1110 | 687 } |
7 | 688 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
689 # endif |
7 | 690 |
691 /* Return the minimum of the physical memory and the user limit, because | |
692 * using more than the user limit may cause Vim to be terminated. */ | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
693 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) |
7 | 694 { |
695 struct rlimit rlp; | |
696 | |
697 if (getrlimit(RLIMIT_DATA, &rlp) == 0 | |
698 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
699 # ifdef RLIM_INFINITY |
7 | 700 && rlp.rlim_cur != RLIM_INFINITY |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
701 # endif |
1110 | 702 && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright) |
7 | 703 ) |
1110 | 704 { |
705 mem = (long_u)rlp.rlim_cur; | |
706 shiftright = 10; | |
707 } | |
7 | 708 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
709 # endif |
7 | 710 |
711 if (mem > 0) | |
1110 | 712 return mem >> shiftright; |
713 return (long_u)0x1fffff; | |
7 | 714 } |
715 #endif | |
716 | |
717 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
718 mch_delay(long msec, int ignoreinput) |
7 | 719 { |
720 int old_tmode; | |
14 | 721 #ifdef FEAT_MZSCHEME |
722 long total = msec; /* remember original value */ | |
723 #endif | |
7 | 724 |
725 if (ignoreinput) | |
726 { | |
727 /* Go to cooked mode without echo, to allow SIGINT interrupting us | |
1530 | 728 * here. But we don't want QUIT to kill us (CTRL-\ used in a |
729 * shell may produce SIGQUIT). */ | |
730 in_mch_delay = TRUE; | |
7 | 731 old_tmode = curr_tmode; |
732 if (curr_tmode == TMODE_RAW) | |
733 settmode(TMODE_SLEEP); | |
734 | |
735 /* | |
736 * Everybody sleeps in a different way... | |
737 * Prefer nanosleep(), some versions of usleep() can only sleep up to | |
738 * one second. | |
739 */ | |
14 | 740 #ifdef FEAT_MZSCHEME |
741 do | |
742 { | |
743 /* if total is large enough, wait by portions in p_mzq */ | |
744 if (total > p_mzq) | |
745 msec = p_mzq; | |
746 else | |
747 msec = total; | |
748 total -= msec; | |
749 #endif | |
7 | 750 #ifdef HAVE_NANOSLEEP |
751 { | |
752 struct timespec ts; | |
753 | |
754 ts.tv_sec = msec / 1000; | |
755 ts.tv_nsec = (msec % 1000) * 1000000; | |
756 (void)nanosleep(&ts, NULL); | |
757 } | |
758 #else | |
759 # ifdef HAVE_USLEEP | |
760 while (msec >= 1000) | |
761 { | |
762 usleep((unsigned int)(999 * 1000)); | |
763 msec -= 999; | |
764 } | |
765 usleep((unsigned int)(msec * 1000)); | |
766 # else | |
767 # ifndef HAVE_SELECT | |
768 poll(NULL, 0, (int)msec); | |
769 # else | |
770 { | |
771 struct timeval tv; | |
772 | |
773 tv.tv_sec = msec / 1000; | |
774 tv.tv_usec = (msec % 1000) * 1000; | |
775 /* | |
776 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get | |
777 * a patch from Sun to fix this. Reported by Gunnar Pedersen. | |
778 */ | |
779 select(0, NULL, NULL, NULL, &tv); | |
780 } | |
781 # endif /* HAVE_SELECT */ | |
782 # endif /* HAVE_NANOSLEEP */ | |
783 #endif /* HAVE_USLEEP */ | |
14 | 784 #ifdef FEAT_MZSCHEME |
785 } | |
786 while (total > 0); | |
787 #endif | |
7 | 788 |
789 settmode(old_tmode); | |
1530 | 790 in_mch_delay = FALSE; |
7 | 791 } |
792 else | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
793 WaitForChar(msec, NULL, FALSE); |
7 | 794 } |
795 | |
180 | 796 #if defined(HAVE_STACK_LIMIT) \ |
7 | 797 || (!defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGSTACK)) |
798 # define HAVE_CHECK_STACK_GROWTH | |
799 /* | |
800 * Support for checking for an almost-out-of-stack-space situation. | |
801 */ | |
802 | |
803 /* | |
804 * Return a pointer to an item on the stack. Used to find out if the stack | |
805 * grows up or down. | |
806 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
807 static void check_stack_growth(char *p); |
7 | 808 static int stack_grows_downwards; |
809 | |
810 /* | |
811 * Find out if the stack grows upwards or downwards. | |
812 * "p" points to a variable on the stack of the caller. | |
813 */ | |
814 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
815 check_stack_growth(char *p) |
7 | 816 { |
817 int i; | |
818 | |
819 stack_grows_downwards = (p > (char *)&i); | |
820 } | |
821 #endif | |
822 | |
180 | 823 #if defined(HAVE_STACK_LIMIT) || defined(PROTO) |
7 | 824 static char *stack_limit = NULL; |
825 | |
826 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
827 # include <pthread.h> | |
828 # include <pthread_np.h> | |
829 #endif | |
830 | |
831 /* | |
832 * Find out until how var the stack can grow without getting into trouble. | |
833 * Called when starting up and when switching to the signal stack in | |
834 * deathtrap(). | |
835 */ | |
836 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
837 get_stack_limit(void) |
7 | 838 { |
839 struct rlimit rlp; | |
840 int i; | |
841 long lim; | |
842 | |
843 /* Set the stack limit to 15/16 of the allowable size. Skip this when the | |
844 * limit doesn't fit in a long (rlim_cur might be "long long"). */ | |
845 if (getrlimit(RLIMIT_STACK, &rlp) == 0 | |
846 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
847 # ifdef RLIM_INFINITY | |
848 && rlp.rlim_cur != RLIM_INFINITY | |
849 # endif | |
850 ) | |
851 { | |
852 lim = (long)rlp.rlim_cur; | |
853 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
854 { | |
855 pthread_attr_t attr; | |
856 size_t size; | |
857 | |
858 /* On FreeBSD the initial thread always has a fixed stack size, no | |
859 * matter what the limits are set to. Normally it's 1 Mbyte. */ | |
860 pthread_attr_init(&attr); | |
861 if (pthread_attr_get_np(pthread_self(), &attr) == 0) | |
862 { | |
863 pthread_attr_getstacksize(&attr, &size); | |
864 if (lim > (long)size) | |
865 lim = (long)size; | |
866 } | |
867 pthread_attr_destroy(&attr); | |
868 } | |
869 #endif | |
870 if (stack_grows_downwards) | |
871 { | |
872 stack_limit = (char *)((long)&i - (lim / 16L * 15L)); | |
873 if (stack_limit >= (char *)&i) | |
874 /* overflow, set to 1/16 of current stack position */ | |
875 stack_limit = (char *)((long)&i / 16L); | |
876 } | |
877 else | |
878 { | |
879 stack_limit = (char *)((long)&i + (lim / 16L * 15L)); | |
880 if (stack_limit <= (char *)&i) | |
881 stack_limit = NULL; /* overflow */ | |
882 } | |
883 } | |
884 } | |
885 | |
886 /* | |
887 * Return FAIL when running out of stack space. | |
888 * "p" must point to any variable local to the caller that's on the stack. | |
889 */ | |
890 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
891 mch_stackcheck(char *p) |
7 | 892 { |
893 if (stack_limit != NULL) | |
894 { | |
895 if (stack_grows_downwards) | |
896 { | |
897 if (p < stack_limit) | |
898 return FAIL; | |
899 } | |
900 else if (p > stack_limit) | |
901 return FAIL; | |
902 } | |
903 return OK; | |
904 } | |
905 #endif | |
906 | |
907 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
908 /* | |
909 * Support for using the signal stack. | |
910 * This helps when we run out of stack space, which causes a SIGSEGV. The | |
911 * signal handler then must run on another stack, since the normal stack is | |
912 * completely full. | |
913 */ | |
914 | |
915 #ifndef SIGSTKSZ | |
916 # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ | |
917 #endif | |
918 | |
919 # ifdef HAVE_SIGALTSTACK | |
920 static stack_t sigstk; /* for sigaltstack() */ | |
921 # else | |
922 static struct sigstack sigstk; /* for sigstack() */ | |
923 # endif | |
924 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
925 static void init_signal_stack(void); |
7 | 926 static char *signal_stack; |
927 | |
928 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
929 init_signal_stack(void) |
7 | 930 { |
931 if (signal_stack != NULL) | |
932 { | |
933 # ifdef HAVE_SIGALTSTACK | |
934 # ifdef HAVE_SS_BASE | |
935 sigstk.ss_base = signal_stack; | |
936 # else | |
937 sigstk.ss_sp = signal_stack; | |
938 # endif | |
939 sigstk.ss_size = SIGSTKSZ; | |
940 sigstk.ss_flags = 0; | |
941 (void)sigaltstack(&sigstk, NULL); | |
942 # else | |
943 sigstk.ss_sp = signal_stack; | |
944 if (stack_grows_downwards) | |
945 sigstk.ss_sp += SIGSTKSZ - 1; | |
946 sigstk.ss_onstack = 0; | |
947 (void)sigstack(&sigstk, NULL); | |
948 # endif | |
949 } | |
950 } | |
951 #endif | |
952 | |
953 /* | |
1832 | 954 * We need correct prototypes for a signal function, otherwise mean compilers |
7 | 955 * will barf when the second argument to signal() is ``wrong''. |
956 * Let me try it with a few tricky defines from my own osdef.h (jw). | |
957 */ | |
958 #if defined(SIGWINCH) | |
959 static RETSIGTYPE | |
960 sig_winch SIGDEFARG(sigarg) | |
961 { | |
962 /* this is not required on all systems, but it doesn't hurt anybody */ | |
963 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
964 do_resize = TRUE; | |
965 SIGRETURN; | |
966 } | |
967 #endif | |
968 | |
969 #if defined(SIGINT) | |
970 static RETSIGTYPE | |
971 catch_sigint SIGDEFARG(sigarg) | |
972 { | |
973 /* this is not required on all systems, but it doesn't hurt anybody */ | |
974 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
975 got_int = TRUE; | |
976 SIGRETURN; | |
977 } | |
978 #endif | |
979 | |
980 #if defined(SIGPWR) | |
981 static RETSIGTYPE | |
982 catch_sigpwr SIGDEFARG(sigarg) | |
983 { | |
37 | 984 /* this is not required on all systems, but it doesn't hurt anybody */ |
985 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
7 | 986 /* |
987 * I'm not sure we get the SIGPWR signal when the system is really going | |
988 * down or when the batteries are almost empty. Just preserve the swap | |
989 * files and don't exit, that can't do any harm. | |
990 */ | |
991 ml_sync_all(FALSE, FALSE); | |
992 SIGRETURN; | |
993 } | |
994 #endif | |
995 | |
996 #ifdef SET_SIG_ALARM | |
997 /* | |
998 * signal function for alarm(). | |
999 */ | |
1000 static RETSIGTYPE | |
1001 sig_alarm SIGDEFARG(sigarg) | |
1002 { | |
1003 /* doesn't do anything, just to break a system call */ | |
1004 sig_alarm_called = TRUE; | |
1005 SIGRETURN; | |
1006 } | |
1007 #endif | |
1008 | |
188 | 1009 #if (defined(HAVE_SETJMP_H) \ |
1010 && ((defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) \ | |
1011 || defined(FEAT_LIBCALL))) \ | |
1012 || defined(PROTO) | |
7 | 1013 /* |
1014 * A simplistic version of setjmp() that only allows one level of using. | |
1015 * Don't call twice before calling mch_endjmp()!. | |
1016 * Usage: | |
1017 * mch_startjmp(); | |
1018 * if (SETJMP(lc_jump_env) != 0) | |
1019 * { | |
1020 * mch_didjmp(); | |
1021 * EMSG("crash!"); | |
1022 * } | |
1023 * else | |
1024 * { | |
1025 * do_the_work; | |
1026 * mch_endjmp(); | |
1027 * } | |
1028 * Note: Can't move SETJMP() here, because a function calling setjmp() must | |
1029 * not return before the saved environment is used. | |
1030 * Returns OK for normal return, FAIL when the protected code caused a | |
1031 * problem and LONGJMP() was used. | |
1032 */ | |
1033 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1034 mch_startjmp(void) |
7 | 1035 { |
1036 #ifdef SIGHASARG | |
1037 lc_signal = 0; | |
1038 #endif | |
1039 lc_active = TRUE; | |
1040 } | |
1041 | |
1042 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1043 mch_endjmp(void) |
7 | 1044 { |
1045 lc_active = FALSE; | |
1046 } | |
1047 | |
1048 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1049 mch_didjmp(void) |
7 | 1050 { |
1051 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1052 /* On FreeBSD the signal stack has to be reset after using siglongjmp(), | |
1053 * otherwise catching the signal only works once. */ | |
1054 init_signal_stack(); | |
1055 # endif | |
1056 } | |
1057 #endif | |
1058 | |
1059 /* | |
1060 * This function handles deadly signals. | |
5338 | 1061 * It tries to preserve any swap files and exit properly. |
7 | 1062 * (partly from Elvis). |
5338 | 1063 * NOTE: Avoid unsafe functions, such as allocating memory, they can result in |
1064 * a deadlock. | |
7 | 1065 */ |
1066 static RETSIGTYPE | |
1067 deathtrap SIGDEFARG(sigarg) | |
1068 { | |
1069 static int entered = 0; /* count the number of times we got here. | |
1070 Note: when memory has been corrupted | |
1071 this may get an arbitrary value! */ | |
1072 #ifdef SIGHASARG | |
1073 int i; | |
1074 #endif | |
1075 | |
1076 #if defined(HAVE_SETJMP_H) | |
1077 /* | |
1078 * Catch a crash in protected code. | |
1079 * Restores the environment saved in lc_jump_env, which looks like | |
1080 * SETJMP() returns 1. | |
1081 */ | |
1082 if (lc_active) | |
1083 { | |
1084 # if defined(SIGHASARG) | |
1085 lc_signal = sigarg; | |
1086 # endif | |
1087 lc_active = FALSE; /* don't jump again */ | |
1088 LONGJMP(lc_jump_env, 1); | |
1089 /* NOTREACHED */ | |
1090 } | |
1091 #endif | |
1092 | |
36 | 1093 #ifdef SIGHASARG |
1530 | 1094 # ifdef SIGQUIT |
1095 /* While in mch_delay() we go to cooked mode to allow a CTRL-C to | |
1096 * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when | |
1097 * pressing CTRL-\, but we don't want Vim to exit then. */ | |
1098 if (in_mch_delay && sigarg == SIGQUIT) | |
1099 SIGRETURN; | |
1100 # endif | |
1101 | |
37 | 1102 /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return |
1103 * here. This avoids that a non-reentrant function is interrupted, e.g., | |
1104 * free(). Calling free() again may then cause a crash. */ | |
1105 if (entered == 0 | |
1106 && (0 | |
1107 # ifdef SIGHUP | |
1108 || sigarg == SIGHUP | |
1109 # endif | |
1110 # ifdef SIGQUIT | |
1111 || sigarg == SIGQUIT | |
1112 # endif | |
1113 # ifdef SIGTERM | |
1114 || sigarg == SIGTERM | |
1115 # endif | |
1116 # ifdef SIGPWR | |
1117 || sigarg == SIGPWR | |
1118 # endif | |
1119 # ifdef SIGUSR1 | |
1120 || sigarg == SIGUSR1 | |
1121 # endif | |
1122 # ifdef SIGUSR2 | |
1123 || sigarg == SIGUSR2 | |
1124 # endif | |
1125 ) | |
413 | 1126 && !vim_handle_signal(sigarg)) |
36 | 1127 SIGRETURN; |
1128 #endif | |
1129 | |
7 | 1130 /* Remember how often we have been called. */ |
1131 ++entered; | |
1132 | |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1133 /* Executing autocommands is likely to use more stack space than we have |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1134 * available in the signal stack. */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1135 block_autocmds(); |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1136 |
7 | 1137 #ifdef FEAT_EVAL |
1138 /* Set the v:dying variable. */ | |
1139 set_vim_var_nr(VV_DYING, (long)entered); | |
1140 #endif | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13357
diff
changeset
|
1141 v_dying = entered; |
7 | 1142 |
180 | 1143 #ifdef HAVE_STACK_LIMIT |
7 | 1144 /* Since we are now using the signal stack, need to reset the stack |
1145 * limit. Otherwise using a regexp will fail. */ | |
1146 get_stack_limit(); | |
1147 #endif | |
1148 | |
758 | 1149 #if 0 |
1150 /* This is for opening gdb the moment Vim crashes. | |
1151 * You need to manually adjust the file name and Vim executable name. | |
1152 * Suggested by SungHyun Nam. */ | |
1153 { | |
1154 # define VI_GDB_FILE "/tmp/vimgdb" | |
1155 # define VIM_NAME "/usr/bin/vim" | |
1156 FILE *fp = fopen(VI_GDB_FILE, "w"); | |
1157 if (fp) | |
1158 { | |
1159 fprintf(fp, | |
1160 "file %s\n" | |
1161 "attach %d\n" | |
1162 "set height 1000\n" | |
1163 "bt full\n" | |
1164 , VIM_NAME, getpid()); | |
1165 fclose(fp); | |
1166 system("xterm -e gdb -x "VI_GDB_FILE); | |
1167 unlink(VI_GDB_FILE); | |
1168 } | |
1169 } | |
1170 #endif | |
1171 | |
7 | 1172 #ifdef SIGHASARG |
1173 /* try to find the name of this signal */ | |
1174 for (i = 0; signal_info[i].sig != -1; i++) | |
1175 if (sigarg == signal_info[i].sig) | |
1176 break; | |
1177 deadly_signal = sigarg; | |
1178 #endif | |
1179 | |
1180 full_screen = FALSE; /* don't write message to the GUI, it might be | |
1181 * part of the problem... */ | |
1182 /* | |
1183 * If something goes wrong after entering here, we may get here again. | |
1184 * When this happens, give a message and try to exit nicely (resetting the | |
1185 * terminal mode, etc.) | |
1186 * When this happens twice, just exit, don't even try to give a message, | |
1187 * stack may be corrupt or something weird. | |
1188 * When this still happens again (or memory was corrupted in such a way | |
1189 * that "entered" was clobbered) use _exit(), don't try freeing resources. | |
1190 */ | |
1191 if (entered >= 3) | |
1192 { | |
1193 reset_signals(); /* don't catch any signals anymore */ | |
1194 may_core_dump(); | |
1195 if (entered >= 4) | |
1196 _exit(8); | |
1197 exit(7); | |
1198 } | |
1199 if (entered == 2) | |
1200 { | |
5338 | 1201 /* No translation, it may call malloc(). */ |
1202 OUT_STR("Vim: Double signal, exiting\n"); | |
7 | 1203 out_flush(); |
1204 getout(1); | |
1205 } | |
1206 | |
5338 | 1207 /* No translation, it may call malloc(). */ |
7 | 1208 #ifdef SIGHASARG |
5338 | 1209 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", |
7 | 1210 signal_info[i].name); |
1211 #else | |
5338 | 1212 sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); |
1213 #endif | |
1214 | |
1215 /* Preserve files and exit. This sets the really_exiting flag to prevent | |
1216 * calling free(). */ | |
1217 preserve_exit(); | |
7 | 1218 |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1219 /* NOTREACHED */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1220 |
33 | 1221 #ifdef NBDEBUG |
1222 reset_signals(); | |
1223 may_core_dump(); | |
1224 abort(); | |
1225 #endif | |
1226 | |
7 | 1227 SIGRETURN; |
1228 } | |
1229 | |
1832 | 1230 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1231 /* |
1232 * On Solaris with multi-threading, suspending might not work immediately. | |
1233 * Catch the SIGCONT signal, which will be used as an indication whether the | |
1234 * suspending has been done or not. | |
1832 | 1235 * |
1236 * On Linux, signal is not always handled immediately either. | |
1237 * See https://bugs.launchpad.net/bugs/291373 | |
1238 * | |
2701 | 1239 * volatile because it is used in signal handler sigcont_handler(). |
7 | 1240 */ |
1832 | 1241 static volatile int sigcont_received; |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1242 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
7 | 1243 |
1244 /* | |
1245 * signal handler for SIGCONT | |
1246 */ | |
1247 static RETSIGTYPE | |
1248 sigcont_handler SIGDEFARG(sigarg) | |
1249 { | |
1250 sigcont_received = TRUE; | |
1251 SIGRETURN; | |
1252 } | |
1253 #endif | |
1254 | |
2586 | 1255 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1256 static void loose_clipboard(void); |
4230 | 1257 # ifdef USE_SYSTEM |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1258 static void save_clipboard(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1259 static void restore_clipboard(void); |
4209 | 1260 |
1261 static void *clip_star_save = NULL; | |
1262 static void *clip_plus_save = NULL; | |
4230 | 1263 # endif |
2586 | 1264 |
1265 /* | |
1266 * Called when Vim is going to sleep or execute a shell command. | |
1267 * We can't respond to requests for the X selections. Lose them, otherwise | |
1268 * other applications will hang. But first copy the text to cut buffer 0. | |
1269 */ | |
1270 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1271 loose_clipboard(void) |
2586 | 1272 { |
1273 if (clip_star.owned || clip_plus.owned) | |
1274 { | |
1275 x11_export_final_selection(); | |
1276 if (clip_star.owned) | |
1277 clip_lose_selection(&clip_star); | |
1278 if (clip_plus.owned) | |
1279 clip_lose_selection(&clip_plus); | |
1280 if (x11_display != NULL) | |
1281 XFlush(x11_display); | |
1282 } | |
1283 } | |
4209 | 1284 |
4230 | 1285 # ifdef USE_SYSTEM |
4209 | 1286 /* |
1287 * Save clipboard text to restore later. | |
1288 */ | |
1289 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1290 save_clipboard(void) |
4209 | 1291 { |
1292 if (clip_star.owned) | |
1293 clip_star_save = get_register('*', TRUE); | |
1294 if (clip_plus.owned) | |
1295 clip_plus_save = get_register('+', TRUE); | |
1296 } | |
1297 | |
1298 /* | |
1299 * Restore clipboard text if no one own the X selection. | |
1300 */ | |
1301 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1302 restore_clipboard(void) |
4209 | 1303 { |
1304 if (clip_star_save != NULL) | |
1305 { | |
1306 if (!clip_gen_owner_exists(&clip_star)) | |
1307 put_register('*', clip_star_save); | |
1308 else | |
1309 free_register(clip_star_save); | |
1310 clip_star_save = NULL; | |
1311 } | |
1312 if (clip_plus_save != NULL) | |
1313 { | |
1314 if (!clip_gen_owner_exists(&clip_plus)) | |
1315 put_register('+', clip_plus_save); | |
1316 else | |
1317 free_register(clip_plus_save); | |
1318 clip_plus_save = NULL; | |
1319 } | |
1320 } | |
4230 | 1321 # endif |
2586 | 1322 #endif |
1323 | |
7 | 1324 /* |
1325 * If the machine has job control, use it to suspend the program, | |
1326 * otherwise fake it by starting a new shell. | |
1327 */ | |
1328 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1329 mch_suspend(void) |
7 | 1330 { |
1331 /* BeOS does have SIGTSTP, but it doesn't work. */ | |
1332 #if defined(SIGTSTP) && !defined(__BEOS__) | |
1333 out_flush(); /* needed to make cursor visible on some systems */ | |
1334 settmode(TMODE_COOK); | |
1335 out_flush(); /* needed to disable mouse on some systems */ | |
1336 | |
1337 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2586 | 1338 loose_clipboard(); |
7 | 1339 # endif |
1340 | |
1832 | 1341 # if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1342 sigcont_received = FALSE; |
1343 # endif | |
1344 kill(0, SIGTSTP); /* send ourselves a STOP signal */ | |
1832 | 1345 # if defined(_REENTRANT) && defined(SIGCONT) |
1346 /* | |
1347 * Wait for the SIGCONT signal to be handled. It generally happens | |
1348 * immediately, but somehow not all the time. Do not call pause() | |
1349 * because there would be race condition which would hang Vim if | |
1350 * signal happened in between the test of sigcont_received and the | |
1351 * call to pause(). If signal is not yet received, call sleep(0) | |
1352 * to just yield CPU. Signal should then be received. If somehow | |
1353 * it's still not received, sleep 1, 2, 3 ms. Don't bother waiting | |
1354 * further if signal is not received after 1+2+3+4 ms (not expected | |
1355 * to happen). | |
1356 */ | |
1357 { | |
1932 | 1358 long wait_time; |
1359 for (wait_time = 0; !sigcont_received && wait_time <= 3L; wait_time++) | |
1832 | 1360 /* Loop is not entered most of the time */ |
1932 | 1361 mch_delay(wait_time, FALSE); |
1832 | 1362 } |
7 | 1363 # endif |
1364 | |
1365 # ifdef FEAT_TITLE | |
1366 /* | |
1367 * Set oldtitle to NULL, so the current title is obtained again. | |
1368 */ | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
1369 VIM_CLEAR(oldtitle); |
7 | 1370 # endif |
1371 settmode(TMODE_RAW); | |
1372 need_check_timestamps = TRUE; | |
1373 did_check_timestamps = FALSE; | |
1374 #else | |
1375 suspend_shell(); | |
1376 #endif | |
1377 } | |
1378 | |
1379 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1380 mch_init(void) |
7 | 1381 { |
1382 Columns = 80; | |
1383 Rows = 24; | |
1384 | |
1385 out_flush(); | |
1386 set_signals(); | |
167 | 1387 |
765 | 1388 #ifdef MACOS_CONVERT |
167 | 1389 mac_conv_init(); |
1390 #endif | |
4168 | 1391 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
1392 win_clip_init(); | |
1393 #endif | |
7 | 1394 } |
1395 | |
1396 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1397 set_signals(void) |
7 | 1398 { |
1399 #if defined(SIGWINCH) | |
1400 /* | |
1401 * WINDOW CHANGE signal is handled with sig_winch(). | |
1402 */ | |
1403 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
1404 #endif | |
1405 | |
1406 /* | |
1407 * We want the STOP signal to work, to make mch_suspend() work. | |
1408 * For "rvim" the STOP signal is ignored. | |
1409 */ | |
1410 #ifdef SIGTSTP | |
1411 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); | |
1412 #endif | |
1832 | 1413 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1414 signal(SIGCONT, sigcont_handler); |
1415 #endif | |
1416 | |
1417 /* | |
1418 * We want to ignore breaking of PIPEs. | |
1419 */ | |
1420 #ifdef SIGPIPE | |
1421 signal(SIGPIPE, SIG_IGN); | |
1422 #endif | |
1423 | |
1424 #ifdef SIGINT | |
167 | 1425 catch_int_signal(); |
7 | 1426 #endif |
1427 | |
1428 /* | |
1429 * Ignore alarm signals (Perl's alarm() generates it). | |
1430 */ | |
1431 #ifdef SIGALRM | |
1432 signal(SIGALRM, SIG_IGN); | |
1433 #endif | |
1434 | |
1435 /* | |
1436 * Catch SIGPWR (power failure?) to preserve the swap files, so that no | |
1437 * work will be lost. | |
1438 */ | |
1439 #ifdef SIGPWR | |
1440 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
1441 #endif | |
1442 | |
1443 /* | |
1444 * Arrange for other signals to gracefully shutdown Vim. | |
1445 */ | |
1446 catch_signals(deathtrap, SIG_ERR); | |
1447 | |
1448 #if defined(FEAT_GUI) && defined(SIGHUP) | |
1449 /* | |
1450 * When the GUI is running, ignore the hangup signal. | |
1451 */ | |
1452 if (gui.in_use) | |
1453 signal(SIGHUP, SIG_IGN); | |
1454 #endif | |
1455 } | |
1456 | |
167 | 1457 #if defined(SIGINT) || defined(PROTO) |
1458 /* | |
1459 * Catch CTRL-C (only works while in Cooked mode). | |
1460 */ | |
1461 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1462 catch_int_signal(void) |
167 | 1463 { |
1464 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
1465 } | |
1466 #endif | |
1467 | |
7 | 1468 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1469 reset_signals(void) |
7 | 1470 { |
1471 catch_signals(SIG_DFL, SIG_DFL); | |
1832 | 1472 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1473 /* SIGCONT isn't in the list, because its default action is ignore */ |
1474 signal(SIGCONT, SIG_DFL); | |
1475 #endif | |
1476 } | |
1477 | |
1478 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1479 catch_signals( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1480 RETSIGTYPE (*func_deadly)(), |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1481 RETSIGTYPE (*func_other)()) |
7 | 1482 { |
1483 int i; | |
1484 | |
1485 for (i = 0; signal_info[i].sig != -1; i++) | |
1486 if (signal_info[i].deadly) | |
1487 { | |
1488 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) | |
1489 struct sigaction sa; | |
1490 | |
1491 /* Setup to use the alternate stack for the signal function. */ | |
1492 sa.sa_handler = func_deadly; | |
1493 sigemptyset(&sa.sa_mask); | |
1494 # if defined(__linux__) && defined(_REENTRANT) | |
1495 /* On Linux, with glibc compiled for kernel 2.2, there is a bug in | |
1496 * thread handling in combination with using the alternate stack: | |
1497 * pthread library functions try to use the stack pointer to | |
1498 * identify the current thread, causing a SEGV signal, which | |
1499 * recursively calls deathtrap() and hangs. */ | |
1500 sa.sa_flags = 0; | |
1501 # else | |
1502 sa.sa_flags = SA_ONSTACK; | |
1503 # endif | |
1504 sigaction(signal_info[i].sig, &sa, NULL); | |
1505 #else | |
1506 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) | |
1507 struct sigvec sv; | |
1508 | |
1509 /* Setup to use the alternate stack for the signal function. */ | |
1510 sv.sv_handler = func_deadly; | |
1511 sv.sv_mask = 0; | |
1512 sv.sv_flags = SV_ONSTACK; | |
1513 sigvec(signal_info[i].sig, &sv, NULL); | |
1514 # else | |
1515 signal(signal_info[i].sig, func_deadly); | |
1516 # endif | |
1517 #endif | |
1518 } | |
1519 else if (func_other != SIG_ERR) | |
1520 signal(signal_info[i].sig, func_other); | |
1521 } | |
1522 | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1523 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1524 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1525 block_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1526 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1527 sigset_t newset; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1528 int i; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1529 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1530 sigemptyset(&newset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1531 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1532 for (i = 0; signal_info[i].sig != -1; i++) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1533 sigaddset(&newset, signal_info[i].sig); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1534 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1535 # if defined(_REENTRANT) && defined(SIGCONT) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1536 /* SIGCONT isn't in the list, because its default action is ignore */ |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1537 sigaddset(&newset, SIGCONT); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1538 # endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1539 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1540 sigprocmask(SIG_BLOCK, &newset, set); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1541 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1542 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1543 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1544 unblock_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1545 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1546 sigprocmask(SIG_SETMASK, set, NULL); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1547 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1548 #endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1549 |
7 | 1550 /* |
37 | 1551 * Handling of SIGHUP, SIGQUIT and SIGTERM: |
1146 | 1552 * "when" == a signal: when busy, postpone and return FALSE, otherwise |
1553 * return TRUE | |
1554 * "when" == SIGNAL_BLOCK: Going to be busy, block signals | |
1555 * "when" == SIGNAL_UNBLOCK: Going to wait, unblock signals, use postponed | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
1556 * signal |
36 | 1557 * Returns TRUE when Vim should exit. |
1558 */ | |
1559 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1560 vim_handle_signal(int sig) |
36 | 1561 { |
37 | 1562 static int got_signal = 0; |
1563 static int blocked = TRUE; | |
1564 | |
1565 switch (sig) | |
36 | 1566 { |
37 | 1567 case SIGNAL_BLOCK: blocked = TRUE; |
1568 break; | |
1569 | |
1570 case SIGNAL_UNBLOCK: blocked = FALSE; | |
1571 if (got_signal != 0) | |
1572 { | |
1573 kill(getpid(), got_signal); | |
1574 got_signal = 0; | |
1575 } | |
1576 break; | |
1577 | |
1578 default: if (!blocked) | |
36 | 1579 return TRUE; /* exit! */ |
37 | 1580 got_signal = sig; |
1581 #ifdef SIGPWR | |
1582 if (sig != SIGPWR) | |
1583 #endif | |
1584 got_int = TRUE; /* break any loops */ | |
36 | 1585 break; |
1586 } | |
1587 return FALSE; | |
1588 } | |
1589 | |
1590 /* | |
7 | 1591 * Check_win checks whether we have an interactive stdout. |
1592 */ | |
1593 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1594 mch_check_win(int argc UNUSED, char **argv UNUSED) |
7 | 1595 { |
1596 if (isatty(1)) | |
1597 return OK; | |
1598 return FAIL; | |
1599 } | |
1600 | |
1601 /* | |
1602 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
1603 */ | |
1604 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1605 mch_input_isatty(void) |
7 | 1606 { |
1607 if (isatty(read_cmd_fd)) | |
1608 return TRUE; | |
1609 return FALSE; | |
1610 } | |
1611 | |
1612 #ifdef FEAT_X11 | |
1613 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1614 # if defined(ELAPSED_TIMEVAL) \ |
7 | 1615 && (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE)) |
1616 | |
1617 /* | |
1618 * Give a message about the elapsed time for opening the X window. | |
1619 */ | |
1620 static void | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1621 xopen_message(long elapsed_msec) |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1622 { |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1623 smsg((char_u *)_("Opening the X display took %ld msec"), elapsed_msec); |
7 | 1624 } |
1625 # endif | |
1626 #endif | |
1627 | |
1628 #if defined(FEAT_X11) && (defined(FEAT_TITLE) || defined(FEAT_XCLIPBOARD)) | |
1629 /* | |
1630 * A few functions shared by X11 title and clipboard code. | |
1631 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1632 static int x_error_handler(Display *dpy, XErrorEvent *error_event); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1633 static int x_error_check(Display *dpy, XErrorEvent *error_event); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1634 static int x_connect_to_server(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1635 static int test_x11_window(Display *dpy); |
7 | 1636 |
1637 static int got_x_error = FALSE; | |
1638 | |
1639 /* | |
1640 * X Error handler, otherwise X just exits! (very rude) -- webb | |
1641 */ | |
1642 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1643 x_error_handler(Display *dpy, XErrorEvent *error_event) |
7 | 1644 { |
42 | 1645 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); |
7 | 1646 STRCAT(IObuff, _("\nVim: Got X error\n")); |
1647 | |
1648 /* We cannot print a message and continue, because no X calls are allowed | |
1649 * here (causes my system to hang). Silently continuing might be an | |
1650 * alternative... */ | |
1651 preserve_exit(); /* preserve files and exit */ | |
1652 | |
1653 return 0; /* NOTREACHED */ | |
1654 } | |
1655 | |
1656 /* | |
1657 * Another X Error handler, just used to check for errors. | |
1658 */ | |
1659 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1660 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
7 | 1661 { |
1662 got_x_error = TRUE; | |
1663 return 0; | |
1664 } | |
1665 | |
1666 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) | |
1667 # if defined(HAVE_SETJMP_H) | |
1668 /* | |
1669 * An X IO Error handler, used to catch error while opening the display. | |
1670 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1671 static int x_IOerror_check(Display *dpy); |
7 | 1672 |
1673 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1674 x_IOerror_check(Display *dpy UNUSED) |
7 | 1675 { |
1676 /* This function should not return, it causes exit(). Longjump instead. */ | |
1677 LONGJMP(lc_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1678 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1679 return 0; /* avoid the compiler complains about missing return value */ |
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1680 # endif |
7 | 1681 } |
1682 # endif | |
1683 | |
1684 /* | |
1685 * An X IO Error handler, used to catch terminal errors. | |
1686 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1687 static int x_IOerror_handler(Display *dpy); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1688 static void may_restore_clipboard(void); |
6383 | 1689 static int xterm_dpy_was_reset = FALSE; |
7 | 1690 |
1691 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1692 x_IOerror_handler(Display *dpy UNUSED) |
7 | 1693 { |
1694 xterm_dpy = NULL; | |
6383 | 1695 xterm_dpy_was_reset = TRUE; |
7 | 1696 x11_window = 0; |
1697 x11_display = NULL; | |
1698 xterm_Shell = (Widget)0; | |
1699 | |
1700 /* This function should not return, it causes exit(). Longjump instead. */ | |
1701 LONGJMP(x_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1702 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1703 return 0; /* avoid the compiler complains about missing return value */ |
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1704 # endif |
7 | 1705 } |
6383 | 1706 |
1707 /* | |
1708 * If the X11 connection was lost try to restore it. | |
1709 * Helps when the X11 server was stopped and restarted while Vim was inactive | |
6448 | 1710 * (e.g. through tmux). |
6383 | 1711 */ |
1712 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1713 may_restore_clipboard(void) |
6383 | 1714 { |
1715 if (xterm_dpy_was_reset) | |
1716 { | |
1717 xterm_dpy_was_reset = FALSE; | |
6458 | 1718 |
1719 # ifndef LESSTIF_VERSION | |
1720 /* This has been reported to avoid Vim getting stuck. */ | |
1721 if (app_context != (XtAppContext)NULL) | |
1722 { | |
1723 XtDestroyApplicationContext(app_context); | |
1724 app_context = (XtAppContext)NULL; | |
1725 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
1726 } | |
1727 # endif | |
1728 | |
6383 | 1729 setup_term_clip(); |
1730 get_x11_title(FALSE); | |
1731 } | |
1732 } | |
7 | 1733 #endif |
1734 | |
1735 /* | |
1736 * Return TRUE when connection to the X server is desired. | |
1737 */ | |
1738 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1739 x_connect_to_server(void) |
7 | 1740 { |
1741 #if defined(FEAT_CLIENTSERVER) | |
1742 if (x_force_connect) | |
1743 return TRUE; | |
1744 #endif | |
1745 if (x_no_connect) | |
1746 return FALSE; | |
1747 | |
1748 /* Check for a match with "exclude:" from 'clipboard'. */ | |
1749 if (clip_exclude_prog != NULL) | |
1750 { | |
6375 | 1751 if (vim_regexec_prog(&clip_exclude_prog, FALSE, T_NAME, (colnr_T)0)) |
7 | 1752 return FALSE; |
1753 } | |
1754 return TRUE; | |
1755 } | |
1756 | |
1757 /* | |
1758 * Test if "dpy" and x11_window are valid by getting the window title. | |
1759 * I don't actually want it yet, so there may be a simpler call to use, but | |
1760 * this will cause the error handler x_error_check() to be called if anything | |
1761 * is wrong, such as the window pointer being invalid (as can happen when the | |
1762 * user changes his DISPLAY, but not his WINDOWID) -- webb | |
1763 */ | |
1764 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1765 test_x11_window(Display *dpy) |
7 | 1766 { |
1767 int (*old_handler)(); | |
1768 XTextProperty text_prop; | |
1769 | |
1770 old_handler = XSetErrorHandler(x_error_check); | |
1771 got_x_error = FALSE; | |
1772 if (XGetWMName(dpy, x11_window, &text_prop)) | |
1773 XFree((void *)text_prop.value); | |
1774 XSync(dpy, False); | |
1775 (void)XSetErrorHandler(old_handler); | |
1776 | |
1777 if (p_verbose > 0 && got_x_error) | |
292 | 1778 verb_msg((char_u *)_("Testing the X display failed")); |
7 | 1779 |
1780 return (got_x_error ? FAIL : OK); | |
1781 } | |
1782 #endif | |
1783 | |
1784 #ifdef FEAT_TITLE | |
1785 | |
1786 #ifdef FEAT_X11 | |
1787 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1788 static int get_x11_thing(int get_title, int test_only); |
7 | 1789 |
1790 /* | |
1791 * try to get x11 window and display | |
1792 * | |
1793 * return FAIL for failure, OK otherwise | |
1794 */ | |
1795 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1796 get_x11_windis(void) |
7 | 1797 { |
1798 char *winid; | |
1799 static int result = -1; | |
1800 #define XD_NONE 0 /* x11_display not set here */ | |
1801 #define XD_HERE 1 /* x11_display opened here */ | |
1802 #define XD_GUI 2 /* x11_display used from gui.dpy */ | |
1803 #define XD_XTERM 3 /* x11_display used from xterm_dpy */ | |
1804 static int x11_display_from = XD_NONE; | |
1805 static int did_set_error_handler = FALSE; | |
1806 | |
1807 if (!did_set_error_handler) | |
1808 { | |
1809 /* X just exits if it finds an error otherwise! */ | |
1810 (void)XSetErrorHandler(x_error_handler); | |
1811 did_set_error_handler = TRUE; | |
1812 } | |
1813 | |
574 | 1814 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
7 | 1815 if (gui.in_use) |
1816 { | |
1817 /* | |
1818 * If the X11 display was opened here before, for the window where Vim | |
1819 * was started, close that one now to avoid a memory leak. | |
1820 */ | |
1821 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1822 { | |
1823 XCloseDisplay(x11_display); | |
1824 x11_display_from = XD_NONE; | |
1825 } | |
1826 if (gui_get_x11_windis(&x11_window, &x11_display) == OK) | |
1827 { | |
1828 x11_display_from = XD_GUI; | |
1829 return OK; | |
1830 } | |
1831 x11_display = NULL; | |
1832 return FAIL; | |
1833 } | |
1834 else if (x11_display_from == XD_GUI) | |
1835 { | |
1836 /* GUI must have stopped somehow, clear x11_display */ | |
1837 x11_window = 0; | |
1838 x11_display = NULL; | |
1839 x11_display_from = XD_NONE; | |
1840 } | |
1841 #endif | |
1842 | |
1843 /* When started with the "-X" argument, don't try connecting. */ | |
1844 if (!x_connect_to_server()) | |
1845 return FAIL; | |
1846 | |
1847 /* | |
1848 * If WINDOWID not set, should try another method to find out | |
1849 * what the current window number is. The only code I know for | |
1850 * this is very complicated. | |
1851 * We assume that zero is invalid for WINDOWID. | |
1852 */ | |
1853 if (x11_window == 0 && (winid = getenv("WINDOWID")) != NULL) | |
1854 x11_window = (Window)atol(winid); | |
1855 | |
1856 #ifdef FEAT_XCLIPBOARD | |
1857 if (xterm_dpy != NULL && x11_window != 0) | |
1858 { | |
1450 | 1859 /* We may have checked it already, but Gnome terminal can move us to |
1860 * another window, so we need to check every time. */ | |
1861 if (x11_display_from != XD_XTERM) | |
1862 { | |
1863 /* | |
1864 * If the X11 display was opened here before, for the window where | |
1865 * Vim was started, close that one now to avoid a memory leak. | |
1866 */ | |
1867 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1868 XCloseDisplay(x11_display); | |
1869 x11_display = xterm_dpy; | |
1870 x11_display_from = XD_XTERM; | |
1871 } | |
7 | 1872 if (test_x11_window(x11_display) == FAIL) |
1873 { | |
1874 /* probably bad $WINDOWID */ | |
1875 x11_window = 0; | |
1876 x11_display = NULL; | |
1877 x11_display_from = XD_NONE; | |
1878 return FAIL; | |
1879 } | |
1880 return OK; | |
1881 } | |
1882 #endif | |
1883 | |
1884 if (x11_window == 0 || x11_display == NULL) | |
1885 result = -1; | |
1886 | |
1887 if (result != -1) /* Have already been here and set this */ | |
1888 return result; /* Don't do all these X calls again */ | |
1889 | |
1890 if (x11_window != 0 && x11_display == NULL) | |
1891 { | |
1892 #ifdef SET_SIG_ALARM | |
1893 RETSIGTYPE (*sig_save)(); | |
1894 #endif | |
1895 #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
1896 struct timeval start_tv; | |
1897 | |
1898 if (p_verbose > 0) | |
1899 gettimeofday(&start_tv, NULL); | |
1900 #endif | |
1901 | |
1902 #ifdef SET_SIG_ALARM | |
1903 /* | |
1904 * Opening the Display may hang if the DISPLAY setting is wrong, or | |
1905 * the network connection is bad. Set an alarm timer to get out. | |
1906 */ | |
1907 sig_alarm_called = FALSE; | |
1908 sig_save = (RETSIGTYPE (*)())signal(SIGALRM, | |
1909 (RETSIGTYPE (*)())sig_alarm); | |
1910 alarm(2); | |
1911 #endif | |
1912 x11_display = XOpenDisplay(NULL); | |
1913 | |
1914 #ifdef SET_SIG_ALARM | |
1915 alarm(0); | |
1916 signal(SIGALRM, (RETSIGTYPE (*)())sig_save); | |
1917 if (p_verbose > 0 && sig_alarm_called) | |
292 | 1918 verb_msg((char_u *)_("Opening the X display timed out")); |
7 | 1919 #endif |
1920 if (x11_display != NULL) | |
1921 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1922 # ifdef ELAPSED_FUNC |
7 | 1923 if (p_verbose > 0) |
292 | 1924 { |
1925 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1926 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 1927 verbose_leave(); |
1928 } | |
7 | 1929 # endif |
1930 if (test_x11_window(x11_display) == FAIL) | |
1931 { | |
1932 /* Maybe window id is bad */ | |
1933 x11_window = 0; | |
1934 XCloseDisplay(x11_display); | |
1935 x11_display = NULL; | |
1936 } | |
1937 else | |
1938 x11_display_from = XD_HERE; | |
1939 } | |
1940 } | |
1941 if (x11_window == 0 || x11_display == NULL) | |
1942 return (result = FAIL); | |
2609 | 1943 |
1944 # ifdef FEAT_EVAL | |
1945 set_vim_var_nr(VV_WINDOWID, (long)x11_window); | |
1946 # endif | |
1947 | |
7 | 1948 return (result = OK); |
1949 } | |
1950 | |
1951 /* | |
1952 * Determine original x11 Window Title | |
1953 */ | |
1954 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1955 get_x11_title(int test_only) |
7 | 1956 { |
32 | 1957 return get_x11_thing(TRUE, test_only); |
7 | 1958 } |
1959 | |
1960 /* | |
1961 * Determine original x11 Window icon | |
1962 */ | |
1963 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1964 get_x11_icon(int test_only) |
7 | 1965 { |
1966 int retval = FALSE; | |
1967 | |
1968 retval = get_x11_thing(FALSE, test_only); | |
1969 | |
1970 /* could not get old icon, use terminal name */ | |
1971 if (oldicon == NULL && !test_only) | |
1972 { | |
1973 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 1974 oldicon = vim_strsave(T_NAME + 8); |
7 | 1975 else |
1940 | 1976 oldicon = vim_strsave(T_NAME); |
7 | 1977 } |
1978 | |
1979 return retval; | |
1980 } | |
1981 | |
1982 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1983 get_x11_thing( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1984 int get_title, /* get title string */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1985 int test_only) |
7 | 1986 { |
1987 XTextProperty text_prop; | |
1988 int retval = FALSE; | |
1989 Status status; | |
1990 | |
1991 if (get_x11_windis() == OK) | |
1992 { | |
1993 /* Get window/icon name if any */ | |
1994 if (get_title) | |
1995 status = XGetWMName(x11_display, x11_window, &text_prop); | |
1996 else | |
1997 status = XGetWMIconName(x11_display, x11_window, &text_prop); | |
1998 | |
1999 /* | |
2000 * If terminal is xterm, then x11_window may be a child window of the | |
2001 * outer xterm window that actually contains the window/icon name, so | |
2002 * keep traversing up the tree until a window with a title/icon is | |
2003 * found. | |
2004 */ | |
2005 /* Previously this was only done for xterm and alikes. I don't see a | |
2006 * reason why it would fail for other terminal emulators. | |
2007 * if (term_is_xterm) */ | |
2008 { | |
2009 Window root; | |
2010 Window parent; | |
2011 Window win = x11_window; | |
2012 Window *children; | |
2013 unsigned int num_children; | |
2014 | |
2015 while (!status || text_prop.value == NULL) | |
2016 { | |
2017 if (!XQueryTree(x11_display, win, &root, &parent, &children, | |
2018 &num_children)) | |
2019 break; | |
2020 if (children) | |
2021 XFree((void *)children); | |
2022 if (parent == root || parent == 0) | |
2023 break; | |
2024 | |
2025 win = parent; | |
2026 if (get_title) | |
2027 status = XGetWMName(x11_display, win, &text_prop); | |
2028 else | |
2029 status = XGetWMIconName(x11_display, win, &text_prop); | |
2030 } | |
2031 } | |
2032 if (status && text_prop.value != NULL) | |
2033 { | |
2034 retval = TRUE; | |
2035 if (!test_only) | |
2036 { | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2037 #if defined(FEAT_XFONTSET) || defined(FEAT_MBYTE) |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2038 if (text_prop.encoding == XA_STRING |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2039 # ifdef FEAT_MBYTE |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2040 && !has_mbyte |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2041 # endif |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2042 ) |
7 | 2043 { |
2044 #endif | |
2045 if (get_title) | |
2046 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2047 else | |
2048 oldicon = vim_strsave((char_u *)text_prop.value); | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2049 #if defined(FEAT_XFONTSET) || defined(FEAT_MBYTE) |
7 | 2050 } |
2051 else | |
2052 { | |
2053 char **cl; | |
2054 Status transform_status; | |
2055 int n = 0; | |
2056 | |
2057 transform_status = XmbTextPropertyToTextList(x11_display, | |
2058 &text_prop, | |
2059 &cl, &n); | |
2060 if (transform_status >= Success && n > 0 && cl[0]) | |
2061 { | |
2062 if (get_title) | |
2063 oldtitle = vim_strsave((char_u *) cl[0]); | |
2064 else | |
2065 oldicon = vim_strsave((char_u *) cl[0]); | |
2066 XFreeStringList(cl); | |
2067 } | |
2068 else | |
2069 { | |
2070 if (get_title) | |
2071 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2072 else | |
2073 oldicon = vim_strsave((char_u *)text_prop.value); | |
2074 } | |
2075 } | |
2076 #endif | |
2077 } | |
2078 XFree((void *)text_prop.value); | |
2079 } | |
2080 } | |
2081 return retval; | |
2082 } | |
2083 | |
6282 | 2084 /* Xutf8 functions are not avaialble on older systems. Note that on some |
2085 * systems X_HAVE_UTF8_STRING may be defined in a header file but | |
2086 * Xutf8SetWMProperties() is not in the X11 library. Configure checks for | |
2087 * that and defines HAVE_XUTF8SETWMPROPERTIES. */ | |
7 | 2088 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) |
6282 | 2089 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES |
7 | 2090 # define USE_UTF8_STRING |
2091 # endif | |
2092 #endif | |
2093 | |
2094 /* | |
2095 * Set x11 Window Title | |
2096 * | |
2097 * get_x11_windis() must be called before this and have returned OK | |
2098 */ | |
2099 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2100 set_x11_title(char_u *title) |
7 | 2101 { |
2102 /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING | |
2103 * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't | |
2104 * supported everywhere and STRING doesn't work for multi-byte titles. | |
2105 */ | |
2106 #ifdef USE_UTF8_STRING | |
2107 if (enc_utf8) | |
2108 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, | |
2109 NULL, NULL, 0, NULL, NULL, NULL); | |
2110 else | |
2111 #endif | |
2112 { | |
2113 #if XtSpecificationRelease >= 4 | |
2114 # ifdef FEAT_XFONTSET | |
2115 XmbSetWMProperties(x11_display, x11_window, (const char *)title, | |
2116 NULL, NULL, 0, NULL, NULL, NULL); | |
2117 # else | |
2118 XTextProperty text_prop; | |
129 | 2119 char *c_title = (char *)title; |
7 | 2120 |
2121 /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ | |
129 | 2122 (void)XStringListToTextProperty(&c_title, 1, &text_prop); |
7 | 2123 XSetWMProperties(x11_display, x11_window, &text_prop, |
2124 NULL, NULL, 0, NULL, NULL, NULL); | |
2125 # endif | |
2126 #else | |
2127 XStoreName(x11_display, x11_window, (char *)title); | |
2128 #endif | |
2129 } | |
2130 XFlush(x11_display); | |
2131 } | |
2132 | |
2133 /* | |
2134 * Set x11 Window icon | |
2135 * | |
2136 * get_x11_windis() must be called before this and have returned OK | |
2137 */ | |
2138 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2139 set_x11_icon(char_u *icon) |
7 | 2140 { |
2141 /* See above for comments about using X*SetWMProperties(). */ | |
2142 #ifdef USE_UTF8_STRING | |
2143 if (enc_utf8) | |
2144 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2145 NULL, 0, NULL, NULL, NULL); | |
2146 else | |
2147 #endif | |
2148 { | |
2149 #if XtSpecificationRelease >= 4 | |
2150 # ifdef FEAT_XFONTSET | |
2151 XmbSetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2152 NULL, 0, NULL, NULL, NULL); | |
2153 # else | |
2154 XTextProperty text_prop; | |
129 | 2155 char *c_icon = (char *)icon; |
2156 | |
2157 (void)XStringListToTextProperty(&c_icon, 1, &text_prop); | |
7 | 2158 XSetWMProperties(x11_display, x11_window, NULL, &text_prop, |
2159 NULL, 0, NULL, NULL, NULL); | |
2160 # endif | |
2161 #else | |
2162 XSetIconName(x11_display, x11_window, (char *)icon); | |
2163 #endif | |
2164 } | |
2165 XFlush(x11_display); | |
2166 } | |
2167 | |
2168 #else /* FEAT_X11 */ | |
2169 | |
2170 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2171 get_x11_title(int test_only UNUSED) |
7 | 2172 { |
2173 return FALSE; | |
2174 } | |
2175 | |
2176 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2177 get_x11_icon(int test_only) |
7 | 2178 { |
2179 if (!test_only) | |
2180 { | |
2181 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 2182 oldicon = vim_strsave(T_NAME + 8); |
7 | 2183 else |
1940 | 2184 oldicon = vim_strsave(T_NAME); |
7 | 2185 } |
2186 return FALSE; | |
2187 } | |
2188 | |
2189 #endif /* FEAT_X11 */ | |
2190 | |
2191 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2192 mch_can_restore_title(void) |
7 | 2193 { |
2194 return get_x11_title(TRUE); | |
2195 } | |
2196 | |
2197 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2198 mch_can_restore_icon(void) |
7 | 2199 { |
2200 return get_x11_icon(TRUE); | |
2201 } | |
2202 | |
2203 /* | |
2204 * Set the window title and icon. | |
2205 */ | |
2206 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2207 mch_settitle(char_u *title, char_u *icon) |
7 | 2208 { |
2209 int type = 0; | |
2210 static int recursive = 0; | |
2211 | |
2212 if (T_NAME == NULL) /* no terminal name (yet) */ | |
2213 return; | |
2214 if (title == NULL && icon == NULL) /* nothing to do */ | |
2215 return; | |
2216 | |
2217 /* When one of the X11 functions causes a deadly signal, we get here again | |
2218 * recursively. Avoid hanging then (something is probably locked). */ | |
2219 if (recursive) | |
2220 return; | |
2221 ++recursive; | |
2222 | |
2223 /* | |
2224 * if the window ID and the display is known, we may use X11 calls | |
2225 */ | |
2226 #ifdef FEAT_X11 | |
2227 if (get_x11_windis() == OK) | |
2228 type = 1; | |
2229 #else | |
2230 # if defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_GTK) | |
2231 if (gui.in_use) | |
2232 type = 1; | |
2233 # endif | |
2234 #endif | |
2235 | |
2236 /* | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2237 * Note: if "t_ts" is set, title is set with escape sequence rather |
7 | 2238 * than x11 calls, because the x11 calls don't always work |
2239 */ | |
2240 if ((type || *T_TS != NUL) && title != NULL) | |
2241 { | |
2242 if (oldtitle == NULL | |
2243 #ifdef FEAT_GUI | |
2244 && !gui.in_use | |
2245 #endif | |
2246 ) /* first call but not in GUI, save title */ | |
2247 (void)get_x11_title(FALSE); | |
2248 | |
2249 if (*T_TS != NUL) /* it's OK if t_fs is empty */ | |
2250 term_settitle(title); | |
2251 #ifdef FEAT_X11 | |
2252 else | |
2253 # ifdef FEAT_GUI_GTK | |
2254 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2255 # endif | |
2256 set_x11_title(title); /* x11 */ | |
2257 #endif | |
64 | 2258 #if defined(FEAT_GUI_GTK) \ |
7 | 2259 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
2260 else | |
2261 gui_mch_settitle(title, icon); | |
2262 #endif | |
2263 did_set_title = TRUE; | |
2264 } | |
2265 | |
2266 if ((type || *T_CIS != NUL) && icon != NULL) | |
2267 { | |
2268 if (oldicon == NULL | |
2269 #ifdef FEAT_GUI | |
2270 && !gui.in_use | |
2271 #endif | |
2272 ) /* first call, save icon */ | |
2273 get_x11_icon(FALSE); | |
2274 | |
2275 if (*T_CIS != NUL) | |
2276 { | |
2277 out_str(T_CIS); /* set icon start */ | |
2278 out_str_nf(icon); | |
2279 out_str(T_CIE); /* set icon end */ | |
2280 out_flush(); | |
2281 } | |
2282 #ifdef FEAT_X11 | |
2283 else | |
2284 # ifdef FEAT_GUI_GTK | |
2285 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2286 # endif | |
2287 set_x11_icon(icon); /* x11 */ | |
2288 #endif | |
2289 did_set_icon = TRUE; | |
2290 } | |
2291 --recursive; | |
2292 } | |
2293 | |
2294 /* | |
2295 * Restore the window/icon title. | |
2296 * "which" is one of: | |
2297 * 1 only restore title | |
2298 * 2 only restore icon | |
2299 * 3 restore title and icon | |
2300 */ | |
2301 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2302 mch_restore_title(int which) |
7 | 2303 { |
2304 /* only restore the title or icon when it has been set */ | |
2305 mch_settitle(((which & 1) && did_set_title) ? | |
2306 (oldtitle ? oldtitle : p_titleold) : NULL, | |
2307 ((which & 2) && did_set_icon) ? oldicon : NULL); | |
2308 } | |
2309 | |
2310 #endif /* FEAT_TITLE */ | |
2311 | |
2312 /* | |
2313 * Return TRUE if "name" looks like some xterm name. | |
158 | 2314 * Seiichi Sato mentioned that "mlterm" works like xterm. |
7 | 2315 */ |
2316 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2317 vim_is_xterm(char_u *name) |
7 | 2318 { |
2319 if (name == NULL) | |
2320 return FALSE; | |
2321 return (STRNICMP(name, "xterm", 5) == 0 | |
2322 || STRNICMP(name, "nxterm", 6) == 0 | |
2323 || STRNICMP(name, "kterm", 5) == 0 | |
158 | 2324 || STRNICMP(name, "mlterm", 6) == 0 |
7 | 2325 || STRNICMP(name, "rxvt", 4) == 0 |
12307
50b0b3aaa545
patch 8.0.1033: detecting background color does not work in screen
Christian Brabandt <cb@256bit.org>
parents:
12240
diff
changeset
|
2326 || STRNICMP(name, "screen.xterm", 12) == 0 |
7 | 2327 || STRCMP(name, "builtin_xterm") == 0); |
2328 } | |
2329 | |
1620 | 2330 #if defined(FEAT_MOUSE_XTERM) || defined(PROTO) |
2331 /* | |
2332 * Return TRUE if "name" appears to be that of a terminal | |
2333 * known to support the xterm-style mouse protocol. | |
2334 * Relies on term_is_xterm having been set to its correct value. | |
2335 */ | |
2336 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2337 use_xterm_like_mouse(char_u *name) |
1620 | 2338 { |
2339 return (name != NULL | |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2340 && (term_is_xterm |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2341 || STRNICMP(name, "screen", 6) == 0 |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2342 || STRNICMP(name, "tmux", 4) == 0 |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2343 || STRICMP(name, "st") == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2344 || STRNICMP(name, "st-", 3) == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2345 || STRNICMP(name, "stterm", 6) == 0)); |
1620 | 2346 } |
2347 #endif | |
2348 | |
7 | 2349 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) |
2350 /* | |
2351 * Return non-zero when using an xterm mouse, according to 'ttymouse'. | |
2352 * Return 1 for "xterm". | |
2353 * Return 2 for "xterm2". | |
3145 | 2354 * Return 3 for "urxvt". |
3746 | 2355 * Return 4 for "sgr". |
7 | 2356 */ |
2357 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2358 use_xterm_mouse(void) |
7 | 2359 { |
3746 | 2360 if (ttym_flags == TTYM_SGR) |
2361 return 4; | |
3145 | 2362 if (ttym_flags == TTYM_URXVT) |
2363 return 3; | |
7 | 2364 if (ttym_flags == TTYM_XTERM2) |
2365 return 2; | |
2366 if (ttym_flags == TTYM_XTERM) | |
2367 return 1; | |
2368 return 0; | |
2369 } | |
2370 #endif | |
2371 | |
2372 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2373 vim_is_iris(char_u *name) |
7 | 2374 { |
2375 if (name == NULL) | |
2376 return FALSE; | |
2377 return (STRNICMP(name, "iris-ansi", 9) == 0 | |
2378 || STRCMP(name, "builtin_iris-ansi") == 0); | |
2379 } | |
2380 | |
2381 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2382 vim_is_vt300(char_u *name) |
7 | 2383 { |
2384 if (name == NULL) | |
2385 return FALSE; /* actually all ANSI comp. terminals should be here */ | |
22 | 2386 /* catch VT100 - VT5xx */ |
2387 return ((STRNICMP(name, "vt", 2) == 0 | |
2388 && vim_strchr((char_u *)"12345", name[2]) != NULL) | |
7 | 2389 || STRCMP(name, "builtin_vt320") == 0); |
2390 } | |
2391 | |
2392 /* | |
2393 * Return TRUE if "name" is a terminal for which 'ttyfast' should be set. | |
2394 * This should include all windowed terminal emulators. | |
2395 */ | |
2396 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2397 vim_is_fastterm(char_u *name) |
7 | 2398 { |
2399 if (name == NULL) | |
2400 return FALSE; | |
2401 if (vim_is_xterm(name) || vim_is_vt300(name) || vim_is_iris(name)) | |
2402 return TRUE; | |
2403 return ( STRNICMP(name, "hpterm", 6) == 0 | |
2404 || STRNICMP(name, "sun-cmd", 7) == 0 | |
2405 || STRNICMP(name, "screen", 6) == 0 | |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2406 || STRNICMP(name, "tmux", 4) == 0 |
7 | 2407 || STRNICMP(name, "dtterm", 6) == 0); |
2408 } | |
2409 | |
2410 /* | |
2411 * Insert user name in s[len]. | |
2412 * Return OK if a name found. | |
2413 */ | |
2414 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2415 mch_get_user_name(char_u *s, int len) |
7 | 2416 { |
2417 #ifdef VMS | |
509 | 2418 vim_strncpy(s, (char_u *)cuserid(NULL), len - 1); |
7 | 2419 return OK; |
2420 #else | |
2421 return mch_get_uname(getuid(), s, len); | |
2422 #endif | |
2423 } | |
2424 | |
2425 /* | |
2426 * Insert user name for "uid" in s[len]. | |
2427 * Return OK if a name found. | |
2428 */ | |
2429 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2430 mch_get_uname(uid_t uid, char_u *s, int len) |
7 | 2431 { |
2432 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) | |
2433 struct passwd *pw; | |
2434 | |
2435 if ((pw = getpwuid(uid)) != NULL | |
2436 && pw->pw_name != NULL && *(pw->pw_name) != NUL) | |
2437 { | |
418 | 2438 vim_strncpy(s, (char_u *)pw->pw_name, len - 1); |
7 | 2439 return OK; |
2440 } | |
2441 #endif | |
2442 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ | |
2443 return FAIL; /* a number is not a name */ | |
2444 } | |
2445 | |
2446 /* | |
2447 * Insert host name is s[len]. | |
2448 */ | |
2449 | |
2450 #ifdef HAVE_SYS_UTSNAME_H | |
2451 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2452 mch_get_host_name(char_u *s, int len) |
7 | 2453 { |
2454 struct utsname vutsname; | |
2455 | |
2456 if (uname(&vutsname) < 0) | |
2457 *s = NUL; | |
2458 else | |
418 | 2459 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); |
7 | 2460 } |
2461 #else /* HAVE_SYS_UTSNAME_H */ | |
2462 | |
2463 # ifdef HAVE_SYS_SYSTEMINFO_H | |
2464 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) | |
2465 # endif | |
2466 | |
2467 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2468 mch_get_host_name(char_u *s, int len) |
7 | 2469 { |
2470 # ifdef VAXC | |
2471 vaxc$gethostname((char *)s, len); | |
2472 # else | |
2473 gethostname((char *)s, len); | |
2474 # endif | |
2475 s[len - 1] = NUL; /* make sure it's terminated */ | |
2476 } | |
2477 #endif /* HAVE_SYS_UTSNAME_H */ | |
2478 | |
2479 /* | |
2480 * return process ID | |
2481 */ | |
2482 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2483 mch_get_pid(void) |
7 | 2484 { |
2485 return (long)getpid(); | |
2486 } | |
2487 | |
2488 #if !defined(HAVE_STRERROR) && defined(USE_GETCWD) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
2489 static char *strerror(int); |
7 | 2490 |
2491 static char * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2492 strerror(int err) |
7 | 2493 { |
2494 extern int sys_nerr; | |
2495 extern char *sys_errlist[]; | |
2496 static char er[20]; | |
2497 | |
2498 if (err > 0 && err < sys_nerr) | |
2499 return (sys_errlist[err]); | |
2500 sprintf(er, "Error %d", err); | |
2501 return er; | |
2502 } | |
2503 #endif | |
2504 | |
2505 /* | |
2506 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2507 * Return OK for success, FAIL for failure. | |
2508 */ | |
2509 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2510 mch_dirname(char_u *buf, int len) |
7 | 2511 { |
2512 #if defined(USE_GETCWD) | |
2513 if (getcwd((char *)buf, len) == NULL) | |
2514 { | |
2515 STRCPY(buf, strerror(errno)); | |
2516 return FAIL; | |
2517 } | |
2518 return OK; | |
2519 #else | |
2520 return (getwd((char *)buf) != NULL ? OK : FAIL); | |
2521 #endif | |
2522 } | |
2523 | |
2524 /* | |
1045 | 2525 * Get absolute file name into "buf[len]". |
7 | 2526 * |
2527 * return FAIL for failure, OK for success | |
2528 */ | |
2529 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2530 mch_FullName( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2531 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2532 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2533 int len, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2534 int force) /* also expand when already absolute path */ |
7 | 2535 { |
2536 int l; | |
1082 | 2537 #ifdef HAVE_FCHDIR |
7 | 2538 int fd = -1; |
2539 static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ | |
1082 | 2540 #endif |
7 | 2541 char_u olddir[MAXPATHL]; |
2542 char_u *p; | |
2543 int retval = OK; | |
1615 | 2544 #ifdef __CYGWIN__ |
1620 | 2545 char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but |
2546 it's not always defined */ | |
2547 #endif | |
7 | 2548 |
1082 | 2549 #ifdef VMS |
2550 fname = vms_fixfilename(fname); | |
2551 #endif | |
2552 | |
1102 | 2553 #ifdef __CYGWIN__ |
2554 /* | |
2555 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". | |
2556 */ | |
1657 | 2557 # if CYGWIN_VERSION_DLL_MAJOR >= 1007 |
7420
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2558 /* Use CCP_RELATIVE to avoid that it sometimes returns a path that ends in |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2559 * a forward slash. */ |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2560 cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2561 fname, posix_fname, MAXPATHL); |
1657 | 2562 # else |
1615 | 2563 cygwin_conv_to_posix_path(fname, posix_fname); |
1657 | 2564 # endif |
1615 | 2565 fname = posix_fname; |
1102 | 2566 #endif |
2567 | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2568 /* Expand it if forced or not an absolute path. |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2569 * Do not do it for "/file", the result is always "/". */ |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2570 if ((force || !mch_isFullName(fname)) |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2571 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) |
7 | 2572 { |
2573 /* | |
2574 * If the file name has a path, change to that directory for a moment, | |
2575 * and then do the getwd() (and get back to where we were). | |
2576 * This will get the correct path name with "../" things. | |
2577 */ | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2578 if (p != NULL) |
7 | 2579 { |
1082 | 2580 #ifdef HAVE_FCHDIR |
7 | 2581 /* |
2582 * Use fchdir() if possible, it's said to be faster and more | |
2583 * reliable. But on SunOS 4 it might not work. Check this by | |
2584 * doing a fchdir() right now. | |
2585 */ | |
2586 if (!dont_fchdir) | |
2587 { | |
2588 fd = open(".", O_RDONLY | O_EXTRA, 0); | |
2589 if (fd >= 0 && fchdir(fd) < 0) | |
2590 { | |
2591 close(fd); | |
2592 fd = -1; | |
2593 dont_fchdir = TRUE; /* don't try again */ | |
2594 } | |
2595 } | |
1082 | 2596 #endif |
7 | 2597 |
2598 /* Only change directory when we are sure we can return to where | |
2599 * we are now. After doing "su" chdir(".") might not work. */ | |
2600 if ( | |
1082 | 2601 #ifdef HAVE_FCHDIR |
7 | 2602 fd < 0 && |
1082 | 2603 #endif |
7 | 2604 (mch_dirname(olddir, MAXPATHL) == FAIL |
2605 || mch_chdir((char *)olddir) != 0)) | |
2606 { | |
2607 p = NULL; /* can't get current dir: don't chdir */ | |
2608 retval = FAIL; | |
2609 } | |
2610 else | |
2611 { | |
2612 /* The directory is copied into buf[], to be able to remove | |
2613 * the file name without changing it (could be a string in | |
2614 * read-only memory) */ | |
2615 if (p - fname >= len) | |
2616 retval = FAIL; | |
2617 else | |
2618 { | |
418 | 2619 vim_strncpy(buf, fname, p - fname); |
7 | 2620 if (mch_chdir((char *)buf)) |
2621 retval = FAIL; | |
2622 else | |
2623 fname = p + 1; | |
2624 *buf = NUL; | |
2625 } | |
2626 } | |
2627 } | |
2628 if (mch_dirname(buf, len) == FAIL) | |
2629 { | |
2630 retval = FAIL; | |
2631 *buf = NUL; | |
2632 } | |
2633 if (p != NULL) | |
2634 { | |
1082 | 2635 #ifdef HAVE_FCHDIR |
7 | 2636 if (fd >= 0) |
2637 { | |
1935 | 2638 if (p_verbose >= 5) |
2639 { | |
2640 verbose_enter(); | |
2641 MSG("fchdir() to previous dir"); | |
2642 verbose_leave(); | |
2643 } | |
7 | 2644 l = fchdir(fd); |
2645 close(fd); | |
2646 } | |
2647 else | |
1082 | 2648 #endif |
7 | 2649 l = mch_chdir((char *)olddir); |
2650 if (l != 0) | |
2651 EMSG(_(e_prev_dir)); | |
2652 } | |
2653 | |
2654 l = STRLEN(buf); | |
3867 | 2655 if (l >= len - 1) |
2656 retval = FAIL; /* no space for trailing "/" */ | |
1082 | 2657 #ifndef VMS |
3867 | 2658 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL |
7 | 2659 && STRCMP(fname, ".") != 0) |
3867 | 2660 STRCAT(buf, "/"); |
1082 | 2661 #endif |
7 | 2662 } |
1045 | 2663 |
7 | 2664 /* Catch file names which are too long. */ |
1877 | 2665 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) |
7 | 2666 return FAIL; |
2667 | |
2668 /* Do not append ".", "/dir/." is equal to "/dir". */ | |
2669 if (STRCMP(fname, ".") != 0) | |
2670 STRCAT(buf, fname); | |
2671 | |
2672 return OK; | |
2673 } | |
2674 | |
2675 /* | |
2676 * Return TRUE if "fname" does not depend on the current directory. | |
2677 */ | |
2678 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2679 mch_isFullName(char_u *fname) |
7 | 2680 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
2681 #ifdef VMS |
7 | 2682 return ( fname[0] == '/' || fname[0] == '.' || |
2683 strchr((char *)fname,':') || strchr((char *)fname,'"') || | |
2684 (strchr((char *)fname,'[') && strchr((char *)fname,']'))|| | |
2685 (strchr((char *)fname,'<') && strchr((char *)fname,'>')) ); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
2686 #else |
7 | 2687 return (*fname == '/' || *fname == '~'); |
2688 #endif | |
2689 } | |
2690 | |
585 | 2691 #if defined(USE_FNAME_CASE) || defined(PROTO) |
2692 /* | |
2693 * Set the case of the file name, if it already exists. This will cause the | |
2694 * file name to remain exactly the same. | |
1450 | 2695 * Only required for file systems where case is ignored and preserved. |
585 | 2696 */ |
2697 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2698 fname_case( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2699 char_u *name, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2700 int len UNUSED) /* buffer size, only used when name gets longer */ |
585 | 2701 { |
2702 struct stat st; | |
2703 char_u *slash, *tail; | |
2704 DIR *dirp; | |
2705 struct dirent *dp; | |
2706 | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2707 if (mch_lstat((char *)name, &st) >= 0) |
585 | 2708 { |
2709 /* Open the directory where the file is located. */ | |
2710 slash = vim_strrchr(name, '/'); | |
2711 if (slash == NULL) | |
2712 { | |
2713 dirp = opendir("."); | |
2714 tail = name; | |
2715 } | |
2716 else | |
2717 { | |
2718 *slash = NUL; | |
2719 dirp = opendir((char *)name); | |
2720 *slash = '/'; | |
2721 tail = slash + 1; | |
2722 } | |
2723 | |
2724 if (dirp != NULL) | |
2725 { | |
2726 while ((dp = readdir(dirp)) != NULL) | |
2727 { | |
2728 /* Only accept names that differ in case and are the same byte | |
2729 * length. TODO: accept different length name. */ | |
2730 if (STRICMP(tail, dp->d_name) == 0 | |
2731 && STRLEN(tail) == STRLEN(dp->d_name)) | |
2732 { | |
2733 char_u newname[MAXPATHL + 1]; | |
2734 struct stat st2; | |
2735 | |
2736 /* Verify the inode is equal. */ | |
2737 vim_strncpy(newname, name, MAXPATHL); | |
2738 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, | |
2739 MAXPATHL - (tail - name)); | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2740 if (mch_lstat((char *)newname, &st2) >= 0 |
585 | 2741 && st.st_ino == st2.st_ino |
2742 && st.st_dev == st2.st_dev) | |
2743 { | |
2744 STRCPY(tail, dp->d_name); | |
2745 break; | |
2746 } | |
2747 } | |
2748 } | |
2749 | |
2750 closedir(dirp); | |
2751 } | |
2752 } | |
2753 } | |
2754 #endif | |
2755 | |
7 | 2756 /* |
2757 * Get file permissions for 'name'. | |
2758 * Returns -1 when it doesn't exist. | |
2759 */ | |
2760 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2761 mch_getperm(char_u *name) |
7 | 2762 { |
2763 struct stat statb; | |
2764 | |
2765 /* Keep the #ifdef outside of stat(), it may be a macro. */ | |
2766 #ifdef VMS | |
2767 if (stat((char *)vms_fixfilename(name), &statb)) | |
2768 #else | |
2769 if (stat((char *)name, &statb)) | |
2770 #endif | |
2771 return -1; | |
1350 | 2772 #ifdef __INTERIX |
2773 /* The top bit makes the value negative, which means the file doesn't | |
2774 * exist. Remove the bit, we don't use it. */ | |
2775 return statb.st_mode & ~S_ADDACE; | |
2776 #else | |
7 | 2777 return statb.st_mode; |
1350 | 2778 #endif |
7 | 2779 } |
2780 | |
2781 /* | |
12847
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2782 * Set file permission for "name" to "perm". |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2783 * Return FAIL for failure, OK otherwise. |
7 | 2784 */ |
2785 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2786 mch_setperm(char_u *name, long perm) |
7 | 2787 { |
2788 return (chmod((char *) | |
2789 #ifdef VMS | |
2790 vms_fixfilename(name), | |
2791 #else | |
2792 name, | |
2793 #endif | |
2794 (mode_t)perm) == 0 ? OK : FAIL); | |
2795 } | |
2796 | |
12847
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2797 #if defined(HAVE_FCHMOD) || defined(PROTO) |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2798 /* |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2799 * Set file permission for open file "fd" to "perm". |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2800 * Return FAIL for failure, OK otherwise. |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2801 */ |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2802 int |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2803 mch_fsetperm(int fd, long perm) |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2804 { |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2805 return (fchmod(fd, (mode_t)perm) == 0 ? OK : FAIL); |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2806 } |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2807 #endif |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2808 |
7 | 2809 #if defined(HAVE_ACL) || defined(PROTO) |
2810 # ifdef HAVE_SYS_ACL_H | |
2811 # include <sys/acl.h> | |
2812 # endif | |
2813 # ifdef HAVE_SYS_ACCESS_H | |
2814 # include <sys/access.h> | |
2815 # endif | |
2816 | |
2817 # ifdef HAVE_SOLARIS_ACL | |
2818 typedef struct vim_acl_solaris_T { | |
2819 int acl_cnt; | |
2820 aclent_t *acl_entry; | |
2821 } vim_acl_solaris_T; | |
2822 # endif | |
2823 | |
1583 | 2824 #if defined(HAVE_SELINUX) || defined(PROTO) |
2825 /* | |
2826 * Copy security info from "from_file" to "to_file". | |
2827 */ | |
2828 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2829 mch_copy_sec(char_u *from_file, char_u *to_file) |
1583 | 2830 { |
2831 if (from_file == NULL) | |
2832 return; | |
2833 | |
2834 if (selinux_enabled == -1) | |
2835 selinux_enabled = is_selinux_enabled(); | |
2836 | |
2837 if (selinux_enabled > 0) | |
2838 { | |
2839 security_context_t from_context = NULL; | |
2840 security_context_t to_context = NULL; | |
2841 | |
2842 if (getfilecon((char *)from_file, &from_context) < 0) | |
2843 { | |
2844 /* If the filesystem doesn't support extended attributes, | |
2845 the original had no special security context and the | |
2846 target cannot have one either. */ | |
2847 if (errno == EOPNOTSUPP) | |
2848 return; | |
2849 | |
2850 MSG_PUTS(_("\nCould not get security context for ")); | |
2851 msg_outtrans(from_file); | |
2852 msg_putchar('\n'); | |
2853 return; | |
2854 } | |
2855 if (getfilecon((char *)to_file, &to_context) < 0) | |
2856 { | |
2857 MSG_PUTS(_("\nCould not get security context for ")); | |
2858 msg_outtrans(to_file); | |
2859 msg_putchar('\n'); | |
2860 freecon (from_context); | |
2861 return ; | |
2862 } | |
2863 if (strcmp(from_context, to_context) != 0) | |
2864 { | |
2865 if (setfilecon((char *)to_file, from_context) < 0) | |
2866 { | |
2867 MSG_PUTS(_("\nCould not set security context for ")); | |
2868 msg_outtrans(to_file); | |
2869 msg_putchar('\n'); | |
2870 } | |
2871 } | |
2872 freecon(to_context); | |
2873 freecon(from_context); | |
2874 } | |
2875 } | |
2876 #endif /* HAVE_SELINUX */ | |
2877 | |
5788 | 2878 #if defined(HAVE_SMACK) && !defined(PROTO) |
2879 /* | |
2880 * Copy security info from "from_file" to "to_file". | |
2881 */ | |
2882 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2883 mch_copy_sec(char_u *from_file, char_u *to_file) |
5788 | 2884 { |
5832 | 2885 static const char * const smack_copied_attributes[] = |
5788 | 2886 { |
2887 XATTR_NAME_SMACK, | |
2888 XATTR_NAME_SMACKEXEC, | |
2889 XATTR_NAME_SMACKMMAP | |
2890 }; | |
2891 | |
2892 char buffer[SMACK_LABEL_LEN]; | |
2893 const char *name; | |
2894 int index; | |
2895 int ret; | |
2896 ssize_t size; | |
2897 | |
2898 if (from_file == NULL) | |
2899 return; | |
2900 | |
2901 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) | |
2902 / sizeof(smack_copied_attributes)[0]) ; index++) | |
2903 { | |
2904 /* get the name of the attribute to copy */ | |
2905 name = smack_copied_attributes[index]; | |
2906 | |
2907 /* get the value of the attribute in buffer */ | |
2908 size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); | |
2909 if (size >= 0) | |
2910 { | |
2911 /* copy the attribute value of buffer */ | |
2912 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); | |
2913 if (ret < 0) | |
2914 { | |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2915 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2916 _("Could not set security context %s for %s"), |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2917 name, to_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2918 msg_outtrans(IObuff); |
5788 | 2919 msg_putchar('\n'); |
2920 } | |
2921 } | |
2922 else | |
2923 { | |
2924 /* what reason of not having the attribute value? */ | |
2925 switch (errno) | |
2926 { | |
2927 case ENOTSUP: | |
2928 /* extended attributes aren't supported or enabled */ | |
2929 /* should a message be echoed? not sure... */ | |
2930 return; /* leave because it isn't usefull to continue */ | |
2931 | |
2932 case ERANGE: | |
2933 default: | |
2934 /* no enough size OR unexpected error */ | |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2935 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2936 _("Could not get security context %s for %s. Removing it!"), |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2937 name, from_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2938 msg_puts(IObuff); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2939 msg_putchar('\n'); |
5788 | 2940 /* FALLTHROUGH to remove the attribute */ |
2941 | |
2942 case ENODATA: | |
2943 /* no attribute of this name */ | |
2944 ret = removexattr((char*)to_file, name); | |
5800 | 2945 /* Silently ignore errors, apparently this happens when |
2946 * smack is not actually being used. */ | |
5788 | 2947 break; |
2948 } | |
2949 } | |
2950 } | |
2951 } | |
2952 #endif /* HAVE_SMACK */ | |
2953 | |
7 | 2954 /* |
2955 * Return a pointer to the ACL of file "fname" in allocated memory. | |
2956 * Return NULL if the ACL is not available for whatever reason. | |
2957 */ | |
2958 vim_acl_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2959 mch_get_acl(char_u *fname UNUSED) |
7 | 2960 { |
2961 vim_acl_T ret = NULL; | |
2962 #ifdef HAVE_POSIX_ACL | |
2963 ret = (vim_acl_T)acl_get_file((char *)fname, ACL_TYPE_ACCESS); | |
2964 #else | |
3330 | 2965 #ifdef HAVE_SOLARIS_ZFS_ACL |
2966 acl_t *aclent; | |
2967 | |
2968 if (acl_get((char *)fname, 0, &aclent) < 0) | |
2969 return NULL; | |
2970 ret = (vim_acl_T)aclent; | |
2971 #else | |
7 | 2972 #ifdef HAVE_SOLARIS_ACL |
2973 vim_acl_solaris_T *aclent; | |
2974 | |
2975 aclent = malloc(sizeof(vim_acl_solaris_T)); | |
2976 if ((aclent->acl_cnt = acl((char *)fname, GETACLCNT, 0, NULL)) < 0) | |
2977 { | |
2978 free(aclent); | |
2979 return NULL; | |
2980 } | |
2981 aclent->acl_entry = malloc(aclent->acl_cnt * sizeof(aclent_t)); | |
2982 if (acl((char *)fname, GETACL, aclent->acl_cnt, aclent->acl_entry) < 0) | |
2983 { | |
2984 free(aclent->acl_entry); | |
2985 free(aclent); | |
2986 return NULL; | |
2987 } | |
2988 ret = (vim_acl_T)aclent; | |
2989 #else | |
2990 #if defined(HAVE_AIX_ACL) | |
2991 int aclsize; | |
2992 struct acl *aclent; | |
2993 | |
2994 aclsize = sizeof(struct acl); | |
2995 aclent = malloc(aclsize); | |
2996 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
2997 { | |
2998 if (errno == ENOSPC) | |
2999 { | |
3000 aclsize = aclent->acl_len; | |
3001 aclent = realloc(aclent, aclsize); | |
3002 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
3003 { | |
3004 free(aclent); | |
3005 return NULL; | |
3006 } | |
3007 } | |
3008 else | |
3009 { | |
3010 free(aclent); | |
3011 return NULL; | |
3012 } | |
3013 } | |
3014 ret = (vim_acl_T)aclent; | |
3015 #endif /* HAVE_AIX_ACL */ | |
3016 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3017 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3018 #endif /* HAVE_POSIX_ACL */ |
3019 return ret; | |
3020 } | |
3021 | |
3022 /* | |
3023 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3024 */ | |
3025 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3026 mch_set_acl(char_u *fname UNUSED, vim_acl_T aclent) |
7 | 3027 { |
3028 if (aclent == NULL) | |
3029 return; | |
3030 #ifdef HAVE_POSIX_ACL | |
3031 acl_set_file((char *)fname, ACL_TYPE_ACCESS, (acl_t)aclent); | |
3032 #else | |
3330 | 3033 #ifdef HAVE_SOLARIS_ZFS_ACL |
3034 acl_set((char *)fname, (acl_t *)aclent); | |
3035 #else | |
7 | 3036 #ifdef HAVE_SOLARIS_ACL |
3037 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt, | |
3038 ((vim_acl_solaris_T *)aclent)->acl_entry); | |
3039 #else | |
3040 #ifdef HAVE_AIX_ACL | |
3041 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); | |
3042 #endif /* HAVE_AIX_ACL */ | |
3043 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3044 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3045 #endif /* HAVE_POSIX_ACL */ |
3046 } | |
3047 | |
3048 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3049 mch_free_acl(vim_acl_T aclent) |
7 | 3050 { |
3051 if (aclent == NULL) | |
3052 return; | |
3053 #ifdef HAVE_POSIX_ACL | |
3054 acl_free((acl_t)aclent); | |
3055 #else | |
3330 | 3056 #ifdef HAVE_SOLARIS_ZFS_ACL |
3057 acl_free((acl_t *)aclent); | |
3058 #else | |
7 | 3059 #ifdef HAVE_SOLARIS_ACL |
3060 free(((vim_acl_solaris_T *)aclent)->acl_entry); | |
3061 free(aclent); | |
3062 #else | |
3063 #ifdef HAVE_AIX_ACL | |
3064 free(aclent); | |
3065 #endif /* HAVE_AIX_ACL */ | |
3066 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3067 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3068 #endif /* HAVE_POSIX_ACL */ |
3069 } | |
3070 #endif | |
3071 | |
3072 /* | |
3073 * Set hidden flag for "name". | |
3074 */ | |
3075 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3076 mch_hide(char_u *name UNUSED) |
7 | 3077 { |
3078 /* can't hide a file */ | |
3079 } | |
3080 | |
3081 /* | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3082 * return TRUE if "name" is a directory or a symlink to a directory |
7 | 3083 * return FALSE if "name" is not a directory |
3084 * return FALSE for error | |
3085 */ | |
3086 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3087 mch_isdir(char_u *name) |
7 | 3088 { |
3089 struct stat statb; | |
3090 | |
3091 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ | |
3092 return FALSE; | |
3093 if (stat((char *)name, &statb)) | |
3094 return FALSE; | |
3095 #ifdef _POSIX_SOURCE | |
3096 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); | |
3097 #else | |
3098 return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); | |
3099 #endif | |
3100 } | |
3101 | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3102 /* |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3103 * return TRUE if "name" is a directory, NOT a symlink to a directory |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3104 * return FALSE if "name" is not a directory |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3105 * return FALSE for error |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3106 */ |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3107 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3108 mch_isrealdir(char_u *name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3109 { |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3110 struct stat statb; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3111 |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3112 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3113 return FALSE; |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
3114 if (mch_lstat((char *)name, &statb)) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3115 return FALSE; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3116 #ifdef _POSIX_SOURCE |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3117 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3118 #else |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3119 return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3120 #endif |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3121 } |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3122 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3123 static int executable_file(char_u *name); |
7 | 3124 |
3125 /* | |
3126 * Return 1 if "name" is an executable file, 0 if not or it doesn't exist. | |
3127 */ | |
3128 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3129 executable_file(char_u *name) |
7 | 3130 { |
3131 struct stat st; | |
3132 | |
3133 if (stat((char *)name, &st)) | |
3134 return 0; | |
5704 | 3135 #ifdef VMS |
3136 /* Like on Unix system file can have executable rights but not necessarily | |
3137 * be an executable, but on Unix is not a default for an ordianry file to | |
3138 * have an executable flag - on VMS it is in most cases. | |
3139 * Therefore, this check does not have any sense - let keep us to the | |
3140 * conventions instead: | |
3141 * *.COM and *.EXE files are the executables - the rest are not. This is | |
3142 * not ideal but better then it was. | |
3143 */ | |
3144 int vms_executable = 0; | |
3145 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) | |
3146 { | |
3147 if (strstr(vms_tolower((char*)name),".exe") != NULL | |
3148 || strstr(vms_tolower((char*)name),".com")!= NULL) | |
3149 vms_executable = 1; | |
3150 } | |
3151 return vms_executable; | |
3152 #else | |
7 | 3153 return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0; |
5704 | 3154 #endif |
7 | 3155 } |
3156 | |
3157 /* | |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
3158 * Return TRUE if "name" can be found in $PATH and executed, FALSE if not. |
6695 | 3159 * If "use_path" is FALSE only check if "name" is executable. |
7 | 3160 * Return -1 if unknown. |
3161 */ | |
3162 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3163 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3164 { |
3165 char_u *buf; | |
3166 char_u *p, *e; | |
3167 int retval; | |
3168 | |
6695 | 3169 /* When "use_path" is false and if it's an absolute or relative path don't |
3170 * need to use $PATH. */ | |
3171 if (!use_path || mch_isFullName(name) || (name[0] == '.' | |
3172 && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) | |
5704 | 3173 { |
6695 | 3174 /* There must be a path separator, files in the current directory |
3175 * can't be executed. */ | |
3176 if (gettail(name) != name && executable_file(name)) | |
5782 | 3177 { |
3178 if (path != NULL) | |
3179 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3180 if (name[0] != '/') |
5782 | 3181 *path = FullName_save(name, TRUE); |
3182 else | |
3183 *path = vim_strsave(name); | |
3184 } | |
3185 return TRUE; | |
3186 } | |
3187 return FALSE; | |
5704 | 3188 } |
7 | 3189 |
3190 p = (char_u *)getenv("PATH"); | |
3191 if (p == NULL || *p == NUL) | |
3192 return -1; | |
3193 buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); | |
3194 if (buf == NULL) | |
3195 return -1; | |
3196 | |
3197 /* | |
3198 * Walk through all entries in $PATH to check if "name" exists there and | |
3199 * is an executable file. | |
3200 */ | |
3201 for (;;) | |
3202 { | |
3203 e = (char_u *)strchr((char *)p, ':'); | |
3204 if (e == NULL) | |
3205 e = p + STRLEN(p); | |
3206 if (e - p <= 1) /* empty entry means current dir */ | |
3207 STRCPY(buf, "./"); | |
3208 else | |
3209 { | |
418 | 3210 vim_strncpy(buf, p, e - p); |
7 | 3211 add_pathsep(buf); |
3212 } | |
3213 STRCAT(buf, name); | |
3214 retval = executable_file(buf); | |
3215 if (retval == 1) | |
5782 | 3216 { |
3217 if (path != NULL) | |
3218 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3219 if (buf[0] != '/') |
5782 | 3220 *path = FullName_save(buf, TRUE); |
3221 else | |
3222 *path = vim_strsave(buf); | |
3223 } | |
7 | 3224 break; |
5782 | 3225 } |
7 | 3226 |
3227 if (*e != ':') | |
3228 break; | |
3229 p = e + 1; | |
3230 } | |
3231 | |
3232 vim_free(buf); | |
3233 return retval; | |
3234 } | |
3235 | |
3236 /* | |
3237 * Check what "name" is: | |
3238 * NODE_NORMAL: file or directory (or doesn't exist) | |
3239 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3240 * NODE_OTHER: non-writable things | |
3241 */ | |
3242 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3243 mch_nodetype(char_u *name) |
7 | 3244 { |
3245 struct stat st; | |
3246 | |
3247 if (stat((char *)name, &st)) | |
3248 return NODE_NORMAL; | |
3249 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) | |
3250 return NODE_NORMAL; | |
3251 if (S_ISBLK(st.st_mode)) /* block device isn't writable */ | |
3252 return NODE_OTHER; | |
3253 /* Everything else is writable? */ | |
3254 return NODE_WRITABLE; | |
3255 } | |
3256 | |
3257 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3258 mch_early_init(void) |
7 | 3259 { |
3260 #ifdef HAVE_CHECK_STACK_GROWTH | |
3261 int i; | |
180 | 3262 |
7 | 3263 check_stack_growth((char *)&i); |
3264 | |
180 | 3265 # ifdef HAVE_STACK_LIMIT |
7 | 3266 get_stack_limit(); |
3267 # endif | |
3268 | |
3269 #endif | |
3270 | |
3271 /* | |
3272 * Setup an alternative stack for signals. Helps to catch signals when | |
3273 * running out of stack space. | |
3274 * Use of sigaltstack() is preferred, it's more portable. | |
3275 * Ignore any errors. | |
3276 */ | |
3277 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1737 | 3278 signal_stack = (char *)alloc(SIGSTKSZ); |
7 | 3279 init_signal_stack(); |
3280 #endif | |
3281 } | |
3282 | |
355 | 3283 #if defined(EXITFREE) || defined(PROTO) |
3284 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3285 mch_free_mem(void) |
355 | 3286 { |
359 | 3287 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
3288 if (clip_star.owned) | |
3289 clip_lose_selection(&clip_star); | |
3290 if (clip_plus.owned) | |
3291 clip_lose_selection(&clip_plus); | |
355 | 3292 # endif |
1605 | 3293 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
355 | 3294 if (xterm_Shell != (Widget)0) |
3295 XtDestroyWidget(xterm_Shell); | |
1605 | 3296 # ifndef LESSTIF_VERSION |
3297 /* Lesstif crashes here, lose some memory */ | |
355 | 3298 if (xterm_dpy != NULL) |
3299 XtCloseDisplay(xterm_dpy); | |
3300 if (app_context != (XtAppContext)NULL) | |
1605 | 3301 { |
355 | 3302 XtDestroyApplicationContext(app_context); |
1605 | 3303 # ifdef FEAT_X11 |
3304 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
3305 # endif | |
3306 } | |
3307 # endif | |
355 | 3308 # endif |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
3309 # if defined(FEAT_X11) |
1605 | 3310 if (x11_display != NULL |
3311 # ifdef FEAT_XCLIPBOARD | |
3312 && x11_display != xterm_dpy | |
3313 # endif | |
3314 ) | |
359 | 3315 XCloseDisplay(x11_display); |
3316 # endif | |
3317 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3318 VIM_CLEAR(signal_stack); |
359 | 3319 # endif |
3320 # ifdef FEAT_TITLE | |
3321 vim_free(oldtitle); | |
3322 vim_free(oldicon); | |
3323 # endif | |
355 | 3324 } |
3325 #endif | |
3326 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3327 static void exit_scroll(void); |
7 | 3328 |
3329 /* | |
3330 * Output a newline when exiting. | |
3331 * Make sure the newline goes to the same stream as the text. | |
3332 */ | |
3333 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3334 exit_scroll(void) |
7 | 3335 { |
167 | 3336 if (silent_mode) |
3337 return; | |
7 | 3338 if (newline_on_exit || msg_didout) |
3339 { | |
3340 if (msg_use_printf()) | |
3341 { | |
3342 if (info_message) | |
3343 mch_msg("\n"); | |
3344 else | |
3345 mch_errmsg("\r\n"); | |
3346 } | |
3347 else | |
3348 out_char('\n'); | |
3349 } | |
3350 else | |
3351 { | |
3352 restore_cterm_colors(); /* get original colors back */ | |
3353 msg_clr_eos_force(); /* clear the rest of the display */ | |
3354 windgoto((int)Rows - 1, 0); /* may have moved the cursor */ | |
3355 } | |
3356 } | |
3357 | |
3358 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3359 mch_exit(int r) |
7 | 3360 { |
3361 exiting = TRUE; | |
3362 | |
3363 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
3364 x11_export_final_selection(); | |
3365 #endif | |
3366 | |
3367 #ifdef FEAT_GUI | |
3368 if (!gui.in_use) | |
3369 #endif | |
3370 { | |
3371 settmode(TMODE_COOK); | |
3372 #ifdef FEAT_TITLE | |
3373 mch_restore_title(3); /* restore xterm title and icon name */ | |
3374 #endif | |
3375 /* | |
3376 * When t_ti is not empty but it doesn't cause swapping terminal | |
3377 * pages, need to output a newline when msg_didout is set. But when | |
3378 * t_ti does swap pages it should not go to the shell page. Do this | |
3379 * before stoptermcap(). | |
3380 */ | |
3381 if (swapping_screen() && !newline_on_exit) | |
3382 exit_scroll(); | |
3383 | |
3384 /* Stop termcap: May need to check for T_CRV response, which | |
3385 * requires RAW mode. */ | |
3386 stoptermcap(); | |
3387 | |
3388 /* | |
3389 * A newline is only required after a message in the alternate screen. | |
3390 * This is set to TRUE by wait_return(). | |
3391 */ | |
3392 if (!swapping_screen() || newline_on_exit) | |
3393 exit_scroll(); | |
3394 | |
3395 /* Cursor may have been switched off without calling starttermcap() | |
3396 * when doing "vim -u vimrc" and vimrc contains ":q". */ | |
3397 if (full_screen) | |
3398 cursor_on(); | |
3399 } | |
3400 out_flush(); | |
3401 ml_close_all(TRUE); /* remove all memfiles */ | |
3402 may_core_dump(); | |
3403 #ifdef FEAT_GUI | |
3404 if (gui.in_use) | |
3405 gui_exit(r); | |
3406 #endif | |
167 | 3407 |
765 | 3408 #ifdef MACOS_CONVERT |
167 | 3409 mac_conv_cleanup(); |
3410 #endif | |
3411 | |
7 | 3412 #ifdef __QNX__ |
3413 /* A core dump won't be created if the signal handler | |
3414 * doesn't return, so we can't call exit() */ | |
3415 if (deadly_signal != 0) | |
3416 return; | |
3417 #endif | |
3418 | |
33 | 3419 #ifdef FEAT_NETBEANS_INTG |
2210 | 3420 netbeans_send_disconnect(); |
33 | 3421 #endif |
355 | 3422 |
3423 #ifdef EXITFREE | |
3424 free_all_mem(); | |
3425 #endif | |
3426 | |
7 | 3427 exit(r); |
3428 } | |
3429 | |
3430 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3431 may_core_dump(void) |
7 | 3432 { |
3433 if (deadly_signal != 0) | |
3434 { | |
3435 signal(deadly_signal, SIG_DFL); | |
3436 kill(getpid(), deadly_signal); /* Die using the signal we caught */ | |
3437 } | |
3438 } | |
3439 | |
3440 #ifndef VMS | |
3441 | |
3442 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3443 mch_settmode(int tmode) |
7 | 3444 { |
3445 static int first = TRUE; | |
3446 | |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3447 #ifdef NEW_TTY_SYSTEM |
7 | 3448 # ifdef HAVE_TERMIOS_H |
3449 static struct termios told; | |
3450 struct termios tnew; | |
3451 # else | |
3452 static struct termio told; | |
3453 struct termio tnew; | |
3454 # endif | |
3455 | |
3456 if (first) | |
3457 { | |
3458 first = FALSE; | |
3459 # if defined(HAVE_TERMIOS_H) | |
3460 tcgetattr(read_cmd_fd, &told); | |
3461 # else | |
3462 ioctl(read_cmd_fd, TCGETA, &told); | |
3463 # endif | |
3464 } | |
3465 | |
3466 tnew = told; | |
3467 if (tmode == TMODE_RAW) | |
3468 { | |
3469 /* | |
3470 * ~ICRNL enables typing ^V^M | |
3471 */ | |
3472 tnew.c_iflag &= ~ICRNL; | |
3473 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE | |
3474 # if defined(IEXTEN) && !defined(__MINT__) | |
3475 | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ | |
3476 /* but it breaks function keys on MINT */ | |
3477 # endif | |
3478 ); | |
3479 # ifdef ONLCR /* don't map NL -> CR NL, we do it ourselves */ | |
3480 tnew.c_oflag &= ~ONLCR; | |
3481 # endif | |
3482 tnew.c_cc[VMIN] = 1; /* return after 1 char */ | |
3483 tnew.c_cc[VTIME] = 0; /* don't wait */ | |
3484 } | |
3485 else if (tmode == TMODE_SLEEP) | |
9381
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3486 { |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3487 /* Also reset ICANON here, otherwise on Solaris select() won't see |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3488 * typeahead characters. */ |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3489 tnew.c_lflag &= ~(ICANON | ECHO); |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3490 tnew.c_cc[VMIN] = 1; /* return after 1 char */ |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3491 tnew.c_cc[VTIME] = 0; /* don't wait */ |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3492 } |
7 | 3493 |
3494 # if defined(HAVE_TERMIOS_H) | |
3495 { | |
3496 int n = 10; | |
3497 | |
3498 /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a | |
3499 * few times. */ | |
3500 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 | |
3501 && errno == EINTR && n > 0) | |
3502 --n; | |
3503 } | |
3504 # else | |
3505 ioctl(read_cmd_fd, TCSETA, &tnew); | |
3506 # endif | |
3507 | |
3508 #else | |
3509 /* | |
3510 * for "old" tty systems | |
3511 */ | |
3512 # ifndef TIOCSETN | |
3513 # define TIOCSETN TIOCSETP /* for hpux 9.0 */ | |
3514 # endif | |
3515 static struct sgttyb ttybold; | |
3516 struct sgttyb ttybnew; | |
3517 | |
3518 if (first) | |
3519 { | |
3520 first = FALSE; | |
3521 ioctl(read_cmd_fd, TIOCGETP, &ttybold); | |
3522 } | |
3523 | |
3524 ttybnew = ttybold; | |
3525 if (tmode == TMODE_RAW) | |
3526 { | |
3527 ttybnew.sg_flags &= ~(CRMOD | ECHO); | |
3528 ttybnew.sg_flags |= RAW; | |
3529 } | |
3530 else if (tmode == TMODE_SLEEP) | |
3531 ttybnew.sg_flags &= ~(ECHO); | |
3532 ioctl(read_cmd_fd, TIOCSETN, &ttybnew); | |
3533 #endif | |
3534 curr_tmode = tmode; | |
3535 } | |
3536 | |
3537 /* | |
3538 * Try to get the code for "t_kb" from the stty setting | |
3539 * | |
3540 * Even if termcap claims a backspace key, the user's setting *should* | |
3541 * prevail. stty knows more about reality than termcap does, and if | |
3542 * somebody's usual erase key is DEL (which, for most BSD users, it will | |
3543 * be), they're going to get really annoyed if their erase key starts | |
3544 * doing forward deletes for no reason. (Eric Fischer) | |
3545 */ | |
3546 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3547 get_stty(void) |
7 | 3548 { |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3549 ttyinfo_T info; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3550 char_u buf[2]; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3551 char_u *p; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3552 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3553 if (get_tty_info(read_cmd_fd, &info) == OK) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3554 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3555 intr_char = info.interrupt; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3556 buf[0] = info.backspace; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3557 buf[1] = NUL; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3558 add_termcode((char_u *)"kb", buf, FALSE); |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3559 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3560 /* If <BS> and <DEL> are now the same, redefine <DEL>. */ |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3561 p = find_termcode((char_u *)"kD"); |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3562 if (p != NULL && p[0] == buf[0] && p[1] == buf[1]) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3563 do_fixdel(NULL); |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3564 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3565 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3566 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3567 /* |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3568 * Obtain the characters that Backspace and Enter produce on "fd". |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3569 * Returns OK or FAIL. |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3570 */ |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3571 int |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3572 get_tty_info(int fd, ttyinfo_T *info) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3573 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3574 #ifdef NEW_TTY_SYSTEM |
7 | 3575 # ifdef HAVE_TERMIOS_H |
3576 struct termios keys; | |
3577 # else | |
3578 struct termio keys; | |
3579 # endif | |
3580 | |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3581 if ( |
7 | 3582 # if defined(HAVE_TERMIOS_H) |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3583 tcgetattr(fd, &keys) != -1 |
7 | 3584 # else |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3585 ioctl(fd, TCGETA, &keys) != -1 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3586 # endif |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3587 ) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3588 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3589 info->backspace = keys.c_cc[VERASE]; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3590 info->interrupt = keys.c_cc[VINTR]; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3591 if (keys.c_iflag & ICRNL) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3592 info->enter = NL; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3593 else |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3594 info->enter = CAR; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3595 if (keys.c_oflag & ONLCR) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3596 info->nl_does_cr = TRUE; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3597 else |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3598 info->nl_does_cr = FALSE; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3599 return OK; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3600 } |
7 | 3601 #else |
3602 /* for "old" tty systems */ | |
3603 struct sgttyb keys; | |
3604 | |
12104
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3605 if (ioctl(fd, TIOCGETP, &keys) != -1) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3606 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3607 info->backspace = keys.sg_erase; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3608 info->interrupt = keys.sg_kill; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3609 info->enter = CAR; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3610 info->nl_does_cr = TRUE; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3611 return OK; |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3612 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3613 #endif |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3614 return FAIL; |
7 | 3615 } |
3616 | |
3617 #endif /* VMS */ | |
3618 | |
3619 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3620 static int mouse_ison = FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3621 |
7 | 3622 /* |
3623 * Set mouse clicks on or off. | |
3624 */ | |
3625 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3626 mch_setmouse(int on) |
7 | 3627 { |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
3628 # ifdef FEAT_BEVAL_TERM |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3629 static int bevalterm_ison = FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3630 # endif |
7 | 3631 int xterm_mouse_vers; |
3632 | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3633 if (on == mouse_ison |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
3634 # ifdef FEAT_BEVAL_TERM |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3635 && p_bevalterm == bevalterm_ison |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3636 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3637 ) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3638 /* return quickly if nothing to do */ |
7 | 3639 return; |
3640 | |
3641 xterm_mouse_vers = use_xterm_mouse(); | |
3145 | 3642 |
3643 # ifdef FEAT_MOUSE_URXVT | |
3746 | 3644 if (ttym_flags == TTYM_URXVT) |
3645 { | |
3145 | 3646 out_str_nf((char_u *) |
3647 (on | |
3648 ? IF_EB("\033[?1015h", ESC_STR "[?1015h") | |
3649 : IF_EB("\033[?1015l", ESC_STR "[?1015l"))); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3650 mouse_ison = on; |
3145 | 3651 } |
3652 # endif | |
3653 | |
3746 | 3654 # ifdef FEAT_MOUSE_SGR |
3655 if (ttym_flags == TTYM_SGR) | |
3656 { | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3657 /* SGR mode supports columns above 223 */ |
3746 | 3658 out_str_nf((char_u *) |
3659 (on | |
3660 ? IF_EB("\033[?1006h", ESC_STR "[?1006h") | |
3661 : IF_EB("\033[?1006l", ESC_STR "[?1006l"))); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3662 mouse_ison = on; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3663 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3664 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3665 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
3666 # ifdef FEAT_BEVAL_TERM |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3667 if (bevalterm_ison != (p_bevalterm && on)) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3668 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3669 bevalterm_ison = (p_bevalterm && on); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3670 if (xterm_mouse_vers > 1 && !bevalterm_ison) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3671 /* disable mouse movement events, enabling is below */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3672 out_str_nf((char_u *) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3673 (IF_EB("\033[?1003l", ESC_STR "[?1003l"))); |
3746 | 3674 } |
3675 # endif | |
3676 | |
7 | 3677 if (xterm_mouse_vers > 0) |
3678 { | |
3679 if (on) /* enable mouse events, use mouse tracking if available */ | |
3680 out_str_nf((char_u *) | |
3681 (xterm_mouse_vers > 1 | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3682 ? ( |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
3683 # ifdef FEAT_BEVAL_TERM |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3684 bevalterm_ison |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3685 ? IF_EB("\033[?1003h", ESC_STR "[?1003h") : |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3686 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3687 IF_EB("\033[?1002h", ESC_STR "[?1002h")) |
7 | 3688 : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); |
3689 else /* disable mouse events, could probably always send the same */ | |
3690 out_str_nf((char_u *) | |
3691 (xterm_mouse_vers > 1 | |
3692 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") | |
3693 : IF_EB("\033[?1000l", ESC_STR "[?1000l"))); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3694 mouse_ison = on; |
7 | 3695 } |
3696 | |
3697 # ifdef FEAT_MOUSE_DEC | |
3698 else if (ttym_flags == TTYM_DEC) | |
3699 { | |
3700 if (on) /* enable mouse events */ | |
3701 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); | |
3702 else /* disable mouse events */ | |
3703 out_str_nf((char_u *)"\033['z"); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3704 mouse_ison = on; |
7 | 3705 } |
3706 # endif | |
3707 | |
3708 # ifdef FEAT_MOUSE_GPM | |
3709 else | |
3710 { | |
3711 if (on) | |
3712 { | |
3713 if (gpm_open()) | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3714 mouse_ison = TRUE; |
7 | 3715 } |
3716 else | |
3717 { | |
3718 gpm_close(); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3719 mouse_ison = FALSE; |
7 | 3720 } |
3721 } | |
3722 # endif | |
3723 | |
1620 | 3724 # ifdef FEAT_SYSMOUSE |
3725 else | |
3726 { | |
3727 if (on) | |
3728 { | |
3729 if (sysmouse_open() == OK) | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3730 mouse_ison = TRUE; |
1620 | 3731 } |
3732 else | |
3733 { | |
3734 sysmouse_close(); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3735 mouse_ison = FALSE; |
1620 | 3736 } |
3737 } | |
3738 # endif | |
3739 | |
7 | 3740 # ifdef FEAT_MOUSE_JSB |
3741 else | |
3742 { | |
3743 if (on) | |
3744 { | |
3745 /* D - Enable Mouse up/down messages | |
3746 * L - Enable Left Button Reporting | |
3747 * M - Enable Middle Button Reporting | |
3748 * R - Enable Right Button Reporting | |
3749 * K - Enable SHIFT and CTRL key Reporting | |
3750 * + - Enable Advanced messaging of mouse moves and up/down messages | |
3751 * Q - Quiet No Ack | |
3752 * # - Numeric value of mouse pointer required | |
3753 * 0 = Multiview 2000 cursor, used as standard | |
3754 * 1 = Windows Arrow | |
3755 * 2 = Windows I Beam | |
3756 * 3 = Windows Hour Glass | |
3757 * 4 = Windows Cross Hair | |
3758 * 5 = Windows UP Arrow | |
3759 */ | |
4299 | 3760 # ifdef JSBTERM_MOUSE_NONADVANCED |
3761 /* Disables full feedback of pointer movements */ | |
7 | 3762 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", |
3763 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); | |
4299 | 3764 # else |
7 | 3765 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\", |
3766 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\")); | |
4299 | 3767 # endif |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3768 mouse_ison = TRUE; |
7 | 3769 } |
3770 else | |
3771 { | |
3772 out_str_nf((char_u *)IF_EB("\033[0~ZwQ\033\\", | |
3773 ESC_STR "[0~ZwQ" ESC_STR "\\")); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3774 mouse_ison = FALSE; |
7 | 3775 } |
3776 } | |
3777 # endif | |
3778 # ifdef FEAT_MOUSE_PTERM | |
3779 else | |
3780 { | |
3781 /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ | |
3782 if (on) | |
3783 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); | |
3784 else | |
3785 out_str_nf("\033[>1l\033[>6l\033[>7l\033[>1l\033[>9h"); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3786 mouse_ison = on; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3787 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3788 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3789 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3790 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
3791 #if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3792 /* |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3793 * Called when 'balloonevalterm' changed. |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3794 */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3795 void |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3796 mch_bevalterm_changed(void) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3797 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3798 mch_setmouse(mouse_ison); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3799 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3800 #endif |
7 | 3801 |
3802 /* | |
3803 * Set the mouse termcode, depending on the 'term' and 'ttymouse' options. | |
3804 */ | |
3805 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3806 check_mouse_termcode(void) |
7 | 3807 { |
3808 # ifdef FEAT_MOUSE_XTERM | |
3809 if (use_xterm_mouse() | |
3145 | 3810 # ifdef FEAT_MOUSE_URXVT |
3811 && use_xterm_mouse() != 3 | |
3812 # endif | |
7 | 3813 # ifdef FEAT_GUI |
3814 && !gui.in_use | |
3815 # endif | |
3816 ) | |
3817 { | |
3818 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
180 | 3819 ? IF_EB("\233M", CSI_STR "M") |
3820 : IF_EB("\033[M", ESC_STR "[M"))); | |
7 | 3821 if (*p_mouse != NUL) |
3822 { | |
3823 /* force mouse off and maybe on to send possibly new mouse | |
3824 * activation sequence to the xterm, with(out) drag tracing. */ | |
3825 mch_setmouse(FALSE); | |
3826 setmouse(); | |
3827 } | |
3828 } | |
3829 else | |
3830 del_mouse_termcode(KS_MOUSE); | |
3831 # endif | |
3832 | |
3833 # ifdef FEAT_MOUSE_GPM | |
3834 if (!use_xterm_mouse() | |
3835 # ifdef FEAT_GUI | |
3836 && !gui.in_use | |
3837 # endif | |
3838 ) | |
3839 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MG", ESC_STR "MG")); | |
3840 # endif | |
3841 | |
1620 | 3842 # ifdef FEAT_SYSMOUSE |
3843 if (!use_xterm_mouse() | |
3844 # ifdef FEAT_GUI | |
3845 && !gui.in_use | |
3846 # endif | |
3847 ) | |
3848 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS")); | |
3849 # endif | |
3850 | |
7 | 3851 # ifdef FEAT_MOUSE_JSB |
6102 | 3852 /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ |
7 | 3853 if (!use_xterm_mouse() |
3854 # ifdef FEAT_GUI | |
3855 && !gui.in_use | |
3856 # endif | |
3857 ) | |
3858 set_mouse_termcode(KS_JSBTERM_MOUSE, | |
3859 (char_u *)IF_EB("\033[0~zw", ESC_STR "[0~zw")); | |
3860 else | |
3861 del_mouse_termcode(KS_JSBTERM_MOUSE); | |
3862 # endif | |
3863 | |
3864 # ifdef FEAT_MOUSE_NET | |
180 | 3865 /* There is no conflict, but one may type "ESC }" from Insert mode. Don't |
7 | 3866 * define it in the GUI or when using an xterm. */ |
3867 if (!use_xterm_mouse() | |
3868 # ifdef FEAT_GUI | |
3869 && !gui.in_use | |
3870 # endif | |
3871 ) | |
3872 set_mouse_termcode(KS_NETTERM_MOUSE, | |
3873 (char_u *)IF_EB("\033}", ESC_STR "}")); | |
3874 else | |
3875 del_mouse_termcode(KS_NETTERM_MOUSE); | |
3876 # endif | |
3877 | |
3878 # ifdef FEAT_MOUSE_DEC | |
6102 | 3879 /* Conflicts with xterm mouse: "\033[" and "\033[M" */ |
5932 | 3880 if (!use_xterm_mouse() |
7 | 3881 # ifdef FEAT_GUI |
3882 && !gui.in_use | |
3883 # endif | |
3884 ) | |
180 | 3885 set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME) |
3886 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); | |
7 | 3887 else |
3888 del_mouse_termcode(KS_DEC_MOUSE); | |
3889 # endif | |
3890 # ifdef FEAT_MOUSE_PTERM | |
6102 | 3891 /* same conflict as the dec mouse */ |
5932 | 3892 if (!use_xterm_mouse() |
7 | 3893 # ifdef FEAT_GUI |
3894 && !gui.in_use | |
3895 # endif | |
3896 ) | |
3897 set_mouse_termcode(KS_PTERM_MOUSE, | |
3898 (char_u *) IF_EB("\033[", ESC_STR "[")); | |
3899 else | |
3900 del_mouse_termcode(KS_PTERM_MOUSE); | |
3901 # endif | |
3145 | 3902 # ifdef FEAT_MOUSE_URXVT |
5932 | 3903 if (use_xterm_mouse() == 3 |
3145 | 3904 # ifdef FEAT_GUI |
3905 && !gui.in_use | |
3906 # endif | |
3907 ) | |
3908 { | |
3909 set_mouse_termcode(KS_URXVT_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3910 ? IF_EB("\233*M", CSI_STR "*M") |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3911 : IF_EB("\033[*M", ESC_STR "[*M"))); |
3145 | 3912 |
3913 if (*p_mouse != NUL) | |
3914 { | |
3915 mch_setmouse(FALSE); | |
3916 setmouse(); | |
3917 } | |
3918 } | |
3919 else | |
3920 del_mouse_termcode(KS_URXVT_MOUSE); | |
3921 # endif | |
3746 | 3922 # ifdef FEAT_MOUSE_SGR |
3923 if (use_xterm_mouse() == 4 | |
3924 # ifdef FEAT_GUI | |
3925 && !gui.in_use | |
3926 # endif | |
3927 ) | |
3928 { | |
3929 set_mouse_termcode(KS_SGR_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3930 ? IF_EB("\233<*M", CSI_STR "<*M") |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3931 : IF_EB("\033[<*M", ESC_STR "[<*M"))); |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3932 |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3933 set_mouse_termcode(KS_SGR_MOUSE_RELEASE, (char_u *)(term_is_8bit(T_NAME) |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3934 ? IF_EB("\233<*m", CSI_STR "<*m") |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3935 : IF_EB("\033[<*m", ESC_STR "[<*m"))); |
3746 | 3936 |
3937 if (*p_mouse != NUL) | |
3938 { | |
3939 mch_setmouse(FALSE); | |
3940 setmouse(); | |
3941 } | |
3942 } | |
3943 else | |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3944 { |
3746 | 3945 del_mouse_termcode(KS_SGR_MOUSE); |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3946 del_mouse_termcode(KS_SGR_MOUSE_RELEASE); |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3947 } |
3746 | 3948 # endif |
7 | 3949 } |
3950 #endif | |
3951 | |
3952 /* | |
3953 * set screen mode, always fails. | |
3954 */ | |
3955 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3956 mch_screenmode(char_u *arg UNUSED) |
7 | 3957 { |
3958 EMSG(_(e_screenmode)); | |
3959 return FAIL; | |
3960 } | |
3961 | |
3962 #ifndef VMS | |
3963 | |
3964 /* | |
3965 * Try to get the current window size: | |
3966 * 1. with an ioctl(), most accurate method | |
3967 * 2. from the environment variables LINES and COLUMNS | |
3968 * 3. from the termcap | |
3969 * 4. keep using the old values | |
3970 * Return OK when size could be determined, FAIL otherwise. | |
3971 */ | |
3972 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3973 mch_get_shellsize(void) |
7 | 3974 { |
3975 long rows = 0; | |
3976 long columns = 0; | |
3977 char_u *p; | |
3978 | |
3979 /* | |
3980 * 1. try using an ioctl. It is the most accurate method. | |
3981 * | |
3982 * Try using TIOCGWINSZ first, some systems that have it also define | |
3983 * TIOCGSIZE but don't have a struct ttysize. | |
3984 */ | |
3985 # ifdef TIOCGWINSZ | |
3986 { | |
3987 struct winsize ws; | |
3988 int fd = 1; | |
3989 | |
3990 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
3991 if (!isatty(fd) && isatty(read_cmd_fd)) | |
3992 fd = read_cmd_fd; | |
3993 if (ioctl(fd, TIOCGWINSZ, &ws) == 0) | |
3994 { | |
3995 columns = ws.ws_col; | |
3996 rows = ws.ws_row; | |
3997 } | |
3998 } | |
3999 # else /* TIOCGWINSZ */ | |
4000 # ifdef TIOCGSIZE | |
4001 { | |
4002 struct ttysize ts; | |
4003 int fd = 1; | |
4004 | |
4005 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
4006 if (!isatty(fd) && isatty(read_cmd_fd)) | |
4007 fd = read_cmd_fd; | |
4008 if (ioctl(fd, TIOCGSIZE, &ts) == 0) | |
4009 { | |
4010 columns = ts.ts_cols; | |
4011 rows = ts.ts_lines; | |
4012 } | |
4013 } | |
4014 # endif /* TIOCGSIZE */ | |
4015 # endif /* TIOCGWINSZ */ | |
4016 | |
4017 /* | |
4018 * 2. get size from environment | |
164 | 4019 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules |
4020 * the ioctl() values! | |
7 | 4021 */ |
164 | 4022 if (columns == 0 || rows == 0 || vim_strchr(p_cpo, CPO_TSIZE) != NULL) |
7 | 4023 { |
4024 if ((p = (char_u *)getenv("LINES"))) | |
4025 rows = atoi((char *)p); | |
4026 if ((p = (char_u *)getenv("COLUMNS"))) | |
4027 columns = atoi((char *)p); | |
4028 } | |
4029 | |
4030 #ifdef HAVE_TGETENT | |
4031 /* | |
4032 * 3. try reading "co" and "li" entries from termcap | |
4033 */ | |
4034 if (columns == 0 || rows == 0) | |
4035 getlinecol(&columns, &rows); | |
4036 #endif | |
4037 | |
4038 /* | |
4039 * 4. If everything fails, use the old values | |
4040 */ | |
4041 if (columns <= 0 || rows <= 0) | |
4042 return FAIL; | |
4043 | |
4044 Rows = rows; | |
4045 Columns = columns; | |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
4046 limit_screen_size(); |
7 | 4047 return OK; |
4048 } | |
4049 | |
11741
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4050 #if defined(FEAT_TERMINAL) || defined(PROTO) |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4051 /* |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4052 * Report the windows size "rows" and "cols" to tty "fd". |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4053 */ |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4054 int |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4055 mch_report_winsize(int fd, int rows, int cols) |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4056 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4057 # ifdef TIOCSWINSZ |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4058 struct winsize ws; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4059 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4060 ws.ws_col = cols; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4061 ws.ws_row = rows; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4062 ws.ws_xpixel = cols * 5; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4063 ws.ws_ypixel = rows * 10; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4064 if (ioctl(fd, TIOCSWINSZ, &ws) == 0) |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4065 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4066 ch_log(NULL, "ioctl(TIOCSWINSZ) success"); |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4067 return OK; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4068 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4069 ch_log(NULL, "ioctl(TIOCSWINSZ) failed"); |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4070 # else |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4071 # ifdef TIOCSSIZE |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4072 struct ttysize ts; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4073 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4074 ts.ts_cols = cols; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4075 ts.ts_lines = rows; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4076 if (ioctl(fd, TIOCSSIZE, &ws) == 0) |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4077 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4078 ch_log(NULL, "ioctl(TIOCSSIZE) success"); |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4079 return OK; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4080 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4081 ch_log(NULL, "ioctl(TIOCSSIZE) failed"); |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4082 # endif |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4083 # endif |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4084 return FAIL; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4085 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4086 #endif |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4087 |
7 | 4088 /* |
4089 * Try to set the window size to Rows and Columns. | |
4090 */ | |
4091 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4092 mch_set_shellsize(void) |
7 | 4093 { |
4094 if (*T_CWS) | |
4095 { | |
4096 /* | |
4097 * NOTE: if you get an error here that term_set_winsize() is | |
4098 * undefined, check the output of configure. It could probably not | |
4099 * find a ncurses, termcap or termlib library. | |
4100 */ | |
4101 term_set_winsize((int)Rows, (int)Columns); | |
4102 out_flush(); | |
4103 screen_start(); /* don't know where cursor is now */ | |
4104 } | |
4105 } | |
4106 | |
4107 #endif /* VMS */ | |
4108 | |
4109 /* | |
4110 * Rows and/or Columns has changed. | |
4111 */ | |
4112 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4113 mch_new_shellsize(void) |
7 | 4114 { |
4115 /* Nothing to do. */ | |
4116 } | |
4117 | |
3048 | 4118 /* |
4119 * Wait for process "child" to end. | |
4120 * Return "child" if it exited properly, <= 0 on error. | |
4121 */ | |
4122 static pid_t | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4123 wait4pid(pid_t child, waitstatus *status) |
3048 | 4124 { |
4125 pid_t wait_pid = 0; | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4126 long delay_msec = 1; |
3048 | 4127 |
4128 while (wait_pid != child) | |
4129 { | |
3470 | 4130 /* When compiled with Python threads are probably used, in which case |
4131 * wait() sometimes hangs for no obvious reason. Use waitpid() | |
4132 * instead and loop (like the GUI). Also needed for other interfaces, | |
4133 * they might call system(). */ | |
4134 # ifdef __NeXT__ | |
3048 | 4135 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); |
3470 | 4136 # else |
3048 | 4137 wait_pid = waitpid(child, status, WNOHANG); |
3470 | 4138 # endif |
3048 | 4139 if (wait_pid == 0) |
4140 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4141 /* Wait for 1 to 10 msec before trying again. */ |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4142 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4143 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4144 delay_msec = 10; |
3048 | 4145 continue; |
4146 } | |
4147 if (wait_pid <= 0 | |
4148 # ifdef ECHILD | |
4149 && errno == ECHILD | |
4150 # endif | |
4151 ) | |
4152 break; | |
4153 } | |
4154 return wait_pid; | |
4155 } | |
4156 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4157 #if !defined(USE_SYSTEM) || defined(FEAT_JOB_CHANNEL) |
11898
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4158 /* |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4159 * Set the environment for a child process. |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4160 */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4161 static void |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4162 set_child_environment( |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4163 long rows, |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4164 long columns, |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4165 char *term, |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4166 int is_terminal UNUSED) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4167 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4168 # ifdef HAVE_SETENV |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4169 char envbuf[50]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4170 # else |
11717
30247960c8a7
patch 8.0.0741: cannot build with HPUX
Christian Brabandt <cb@256bit.org>
parents:
11713
diff
changeset
|
4171 static char envbuf_Term[30]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4172 static char envbuf_Rows[20]; |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4173 static char envbuf_Lines[20]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4174 static char envbuf_Columns[20]; |
11731
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4175 static char envbuf_Colors[20]; |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4176 # ifdef FEAT_TERMINAL |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13898
diff
changeset
|
4177 static char envbuf_Version[20]; |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4178 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4179 # ifdef FEAT_CLIENTSERVER |
11898
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4180 static char envbuf_Servername[60]; |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4181 # endif |
11731
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4182 # endif |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4183 long colors = |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4184 # ifdef FEAT_GUI |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4185 gui.in_use ? 256*256*256 : |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4186 # endif |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4187 t_colors; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4188 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4189 # ifdef HAVE_SETENV |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4190 setenv("TERM", term, 1); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4191 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4192 setenv("ROWS", (char *)envbuf, 1); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4193 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4194 setenv("LINES", (char *)envbuf, 1); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4195 sprintf((char *)envbuf, "%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4196 setenv("COLUMNS", (char *)envbuf, 1); |
11731
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4197 sprintf((char *)envbuf, "%ld", colors); |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4198 setenv("COLORS", (char *)envbuf, 1); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4199 # ifdef FEAT_TERMINAL |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4200 if (is_terminal) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4201 { |
14073
a9b141cf99ff
patch 8.1.0054: compiler warning for using %ld for "long long"
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
4202 sprintf((char *)envbuf, "%ld", (long)get_vim_var_nr(VV_VERSION)); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4203 setenv("VIM_TERMINAL", (char *)envbuf, 1); |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4204 } |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4205 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4206 # ifdef FEAT_CLIENTSERVER |
11898
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4207 setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1); |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4208 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4209 # else |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4210 /* |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4211 * Putenv does not copy the string, it has to remain valid. |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4212 * Use a static array to avoid losing allocated memory. |
11898
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4213 * This won't work well when running multiple children... |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4214 */ |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4215 vim_snprintf(envbuf_Term, sizeof(envbuf_Term), "TERM=%s", term); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4216 putenv(envbuf_Term); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4217 vim_snprintf(envbuf_Rows, sizeof(envbuf_Rows), "ROWS=%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4218 putenv(envbuf_Rows); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4219 vim_snprintf(envbuf_Lines, sizeof(envbuf_Lines), "LINES=%ld", rows); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4220 putenv(envbuf_Lines); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4221 vim_snprintf(envbuf_Columns, sizeof(envbuf_Columns), |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4222 "COLUMNS=%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4223 putenv(envbuf_Columns); |
11731
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4224 vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors); |
d06f3576823a
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Christian Brabandt <cb@256bit.org>
parents:
11727
diff
changeset
|
4225 putenv(envbuf_Colors); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4226 # ifdef FEAT_TERMINAL |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4227 if (is_terminal) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4228 { |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4229 vim_snprintf(envbuf_Version, sizeof(envbuf_Version), |
14073
a9b141cf99ff
patch 8.1.0054: compiler warning for using %ld for "long long"
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
4230 "VIM_TERMINAL=%ld", (long)get_vim_var_nr(VV_VERSION)); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4231 putenv(envbuf_Version); |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4232 } |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4233 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4234 # ifdef FEAT_CLIENTSERVER |
11898
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4235 vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername), |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4236 "VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName); |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4237 putenv(envbuf_Servername); |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4238 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4239 # endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4240 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4241 |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4242 static void |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4243 set_default_child_environment(int is_terminal) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4244 { |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4245 set_child_environment(Rows, Columns, "dumb", is_terminal); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4246 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4247 #endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4248 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4249 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL) |
11894
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4250 /* |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4251 * Open a PTY, with FD for the master and slave side. |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4252 * When failing "pty_master_fd" and "pty_slave_fd" are -1. |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4253 * When successful both file descriptors are stored. |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4254 */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4255 static void |
11933
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
4256 open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **namep) |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4257 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4258 char *tty_name; |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4259 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4260 *pty_master_fd = OpenPTY(&tty_name); /* open pty */ |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4261 if (*pty_master_fd >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4262 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4263 /* Leaving out O_NOCTTY may lead to waitpid() always returning |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4264 * 0 on Mac OS X 10.7 thereby causing freezes. Let's assume |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4265 * adding O_NOCTTY always works when defined. */ |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4266 #ifdef O_NOCTTY |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4267 *pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4268 #else |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4269 *pty_slave_fd = open(tty_name, O_RDWR | O_EXTRA, 0); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4270 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4271 if (*pty_slave_fd < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4272 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4273 close(*pty_master_fd); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4274 *pty_master_fd = -1; |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4275 } |
11933
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
4276 else if (namep != NULL) |
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
4277 *namep = vim_strsave((char_u *)tty_name); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4278 } |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4279 } |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4280 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4281 |
11919
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4282 /* |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4283 * Send SIGINT to a child process if "c" is an interrupt character. |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4284 */ |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4285 void |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4286 may_send_sigint(int c UNUSED, pid_t pid UNUSED, pid_t wpid UNUSED) |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4287 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4288 # ifdef SIGINT |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4289 if (c == Ctrl_C || c == intr_char) |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4290 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4291 # ifdef HAVE_SETSID |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4292 kill(-pid, SIGINT); |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4293 # else |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4294 kill(0, SIGINT); |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4295 # endif |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4296 if (wpid > 0) |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4297 kill(wpid, SIGINT); |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4298 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4299 # endif |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4300 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4301 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4302 #if !defined(USE_SYSTEM) || (defined(FEAT_GUI) && defined(FEAT_TERMINAL)) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4303 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4304 static int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4305 build_argv( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4306 char_u *cmd, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4307 char ***argvp, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4308 char_u **sh_tofree, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4309 char_u **shcf_tofree) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4310 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4311 char **argv = NULL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4312 int argc; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4313 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4314 *sh_tofree = vim_strsave(p_sh); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4315 if (*sh_tofree == NULL) /* out of memory */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4316 return FAIL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4317 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4318 if (mch_parse_cmd(*sh_tofree, TRUE, &argv, &argc) == FAIL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4319 return FAIL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4320 *argvp = argv; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4321 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4322 if (cmd != NULL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4323 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4324 char_u *s; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4325 char_u *p; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4326 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4327 if (extra_shell_arg != NULL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4328 argv[argc++] = (char *)extra_shell_arg; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4329 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4330 /* Break 'shellcmdflag' into white separated parts. This doesn't |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4331 * handle quoted strings, they are very unlikely to appear. */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4332 *shcf_tofree = alloc((unsigned)STRLEN(p_shcf) + 1); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4333 if (*shcf_tofree == NULL) /* out of memory */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4334 return FAIL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4335 s = *shcf_tofree; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4336 p = p_shcf; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4337 while (*p != NUL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4338 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4339 argv[argc++] = (char *)s; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4340 while (*p && *p != ' ' && *p != TAB) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4341 *s++ = *p++; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4342 *s++ = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4343 p = skipwhite(p); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4344 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4345 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4346 argv[argc++] = (char *)cmd; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4347 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4348 argv[argc] = NULL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4349 return OK; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4350 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4351 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4352 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4353 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4354 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4355 * Use a terminal window to run a shell command in. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4356 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4357 static int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4358 mch_call_shell_terminal( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4359 char_u *cmd, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4360 int options UNUSED) /* SHELL_*, see vim.h */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4361 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4362 jobopt_T opt; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4363 char **argv = NULL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4364 char_u *tofree1 = NULL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4365 char_u *tofree2 = NULL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4366 int retval = -1; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4367 buf_T *buf; |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4368 job_T *job; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4369 aco_save_T aco; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4370 oparg_T oa; /* operator arguments */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4371 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4372 if (build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4373 goto theend; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4374 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4375 init_job_options(&opt); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4376 ch_log(NULL, "starting terminal for system command '%s'", cmd); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4377 buf = term_start(NULL, argv, &opt, TERM_START_SYSTEM); |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4378 if (buf == NULL) |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4379 goto theend; |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4380 |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4381 job = term_getjob(buf->b_term); |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4382 ++job->jv_refcount; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4383 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4384 /* Find a window to make "buf" curbuf. */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4385 aucmd_prepbuf(&aco, buf); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4386 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4387 clear_oparg(&oa); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4388 while (term_use_loop()) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4389 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4390 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4391 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4392 /* If terminal_loop() returns OK we got a key that is handled |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4393 * in Normal model. We don't do redrawing anyway. */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4394 if (terminal_loop(TRUE) == OK) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4395 normal_cmd(&oa, TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4396 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4397 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4398 normal_cmd(&oa, TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4399 } |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4400 retval = job->jv_exitval; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4401 ch_log(NULL, "system command finished"); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4402 |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4403 job_unref(job); |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4404 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4405 /* restore curwin/curbuf and a few other things */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4406 aucmd_restbuf(&aco); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4407 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4408 wait_return(TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4409 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4410 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4411 theend: |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4412 vim_free(argv); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4413 vim_free(tofree1); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4414 vim_free(tofree2); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4415 return retval; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4416 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4417 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4418 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4419 #ifdef USE_SYSTEM |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4420 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4421 * Use system() to start the shell: simple but slow. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4422 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4423 static int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4424 mch_call_shell_system( |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4425 char_u *cmd, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4426 int options) /* SHELL_*, see vim.h */ |
7 | 4427 { |
4428 #ifdef VMS | |
4429 char *ifn = NULL; | |
4430 char *ofn = NULL; | |
4431 #endif | |
4432 int tmode = cur_tmode; | |
9552
49512aba8e32
commit https://github.com/vim/vim/commit/b2b050ab16565c117f0e7e411ffef3700d99203b
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
4433 char_u *newcmd; /* only needed for unix */ |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
4434 int x; |
7 | 4435 |
4436 out_flush(); | |
4437 | |
4438 if (options & SHELL_COOKED) | |
4439 settmode(TMODE_COOK); /* set to normal mode */ | |
4440 | |
2586 | 4441 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4209 | 4442 save_clipboard(); |
2586 | 4443 loose_clipboard(); |
4444 # endif | |
4445 | |
7 | 4446 if (cmd == NULL) |
4447 x = system((char *)p_sh); | |
4448 else | |
4449 { | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4450 # ifdef VMS |
7 | 4451 if (ofn = strchr((char *)cmd, '>')) |
4452 *ofn++ = '\0'; | |
4453 if (ifn = strchr((char *)cmd, '<')) | |
4454 { | |
4455 char *p; | |
4456 | |
4457 *ifn++ = '\0'; | |
4458 p = strchr(ifn,' '); /* chop off any trailing spaces */ | |
4459 if (p) | |
4460 *p = '\0'; | |
4461 } | |
4462 if (ofn) | |
4463 x = vms_sys((char *)cmd, ofn, ifn); | |
4464 else | |
4465 x = system((char *)cmd); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4466 # else |
7 | 4467 newcmd = lalloc(STRLEN(p_sh) |
4468 + (extra_shell_arg == NULL ? 0 : STRLEN(extra_shell_arg)) | |
4469 + STRLEN(p_shcf) + STRLEN(cmd) + 4, TRUE); | |
4470 if (newcmd == NULL) | |
4471 x = 0; | |
4472 else | |
4473 { | |
4474 sprintf((char *)newcmd, "%s %s %s %s", p_sh, | |
4475 extra_shell_arg == NULL ? "" : (char *)extra_shell_arg, | |
4476 (char *)p_shcf, | |
4477 (char *)cmd); | |
4478 x = system((char *)newcmd); | |
4479 vim_free(newcmd); | |
4480 } | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4481 # endif |
7 | 4482 } |
4483 # ifdef VMS | |
4484 x = vms_sys_status(x); | |
4485 # endif | |
4486 if (emsg_silent) | |
4487 ; | |
4488 else if (x == 127) | |
4489 MSG_PUTS(_("\nCannot execute shell sh\n")); | |
4490 else if (x && !(options & SHELL_SILENT)) | |
4491 { | |
4492 MSG_PUTS(_("\nshell returned ")); | |
4493 msg_outnum((long)x); | |
4494 msg_putchar('\n'); | |
4495 } | |
4496 | |
4497 if (tmode == TMODE_RAW) | |
4498 settmode(TMODE_RAW); /* set to raw mode */ | |
4499 # ifdef FEAT_TITLE | |
4500 resettitle(); | |
4501 # endif | |
4209 | 4502 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4503 restore_clipboard(); | |
4504 # endif | |
7 | 4505 return x; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4506 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4507 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4508 #else /* USE_SYSTEM */ |
7 | 4509 |
167 | 4510 # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use |
4511 127, some shells use that already */ | |
12200
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
4512 # define OPEN_NULL_FAILED 123 /* Exit code if /dev/null can't be opened */ |
7 | 4513 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4514 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4515 * Don't use system(), use fork()/exec(). |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4516 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4517 static int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4518 mch_call_shell_fork( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4519 char_u *cmd, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4520 int options) /* SHELL_*, see vim.h */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4521 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4522 int tmode = cur_tmode; |
7 | 4523 pid_t pid; |
167 | 4524 pid_t wpid = 0; |
7 | 4525 pid_t wait_pid = 0; |
4526 # ifdef HAVE_UNION_WAIT | |
4527 union wait status; | |
4528 # else | |
4529 int status = -1; | |
4530 # endif | |
4531 int retval = -1; | |
4532 char **argv = NULL; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4533 char_u *tofree1 = NULL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4534 char_u *tofree2 = NULL; |
7 | 4535 int i; |
167 | 4536 int pty_master_fd = -1; /* for pty's */ |
7 | 4537 # ifdef FEAT_GUI |
4538 int pty_slave_fd = -1; | |
167 | 4539 # endif |
602 | 4540 int fd_toshell[2]; /* for pipes */ |
7 | 4541 int fd_fromshell[2]; |
4542 int pipe_error = FALSE; | |
602 | 4543 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ |
7 | 4544 |
4545 out_flush(); | |
4546 if (options & SHELL_COOKED) | |
4547 settmode(TMODE_COOK); /* set to normal mode */ | |
4548 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4549 if (build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4550 goto error; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4551 |
167 | 4552 /* |
4553 * For the GUI, when writing the output into the buffer and when reading | |
4554 * input from the buffer: Try using a pseudo-tty to get the stdin/stdout | |
4555 * of the executed command into the Vim window. Or use a pipe. | |
4556 */ | |
4557 if ((options & (SHELL_READ|SHELL_WRITE)) | |
7 | 4558 # ifdef FEAT_GUI |
167 | 4559 || (gui.in_use && show_shell_mess) |
4560 # endif | |
4561 ) | |
7 | 4562 { |
167 | 4563 # ifdef FEAT_GUI |
7 | 4564 /* |
4565 * Try to open a master pty. | |
4566 * If this works, open the slave pty. | |
4567 * If the slave can't be opened, close the master pty. | |
4568 */ | |
167 | 4569 if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE))) |
11933
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
4570 open_pty(&pty_master_fd, &pty_slave_fd, NULL); |
7 | 4571 /* |
4572 * If not opening a pty or it didn't work, try using pipes. | |
4573 */ | |
4574 if (pty_master_fd < 0) | |
167 | 4575 # endif |
7 | 4576 { |
4577 pipe_error = (pipe(fd_toshell) < 0); | |
4578 if (!pipe_error) /* pipe create OK */ | |
4579 { | |
4580 pipe_error = (pipe(fd_fromshell) < 0); | |
4581 if (pipe_error) /* pipe create failed */ | |
4582 { | |
4583 close(fd_toshell[0]); | |
4584 close(fd_toshell[1]); | |
4585 } | |
4586 } | |
4587 if (pipe_error) | |
4588 { | |
4589 MSG_PUTS(_("\nCannot create pipes\n")); | |
4590 out_flush(); | |
4591 } | |
4592 } | |
4593 } | |
4594 | |
4595 if (!pipe_error) /* pty or pipe opened or not used */ | |
4596 { | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4597 SIGSET_DECL(curset) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4598 |
7 | 4599 # ifdef __BEOS__ |
4600 beos_cleanup_read_thread(); | |
4601 # endif | |
602 | 4602 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4603 BLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4604 pid = fork(); /* maybe we should use vfork() */ |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4605 if (pid == -1) |
7 | 4606 { |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4607 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4608 |
7 | 4609 MSG_PUTS(_("\nCannot fork\n")); |
167 | 4610 if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4611 # ifdef FEAT_GUI |
167 | 4612 || (gui.in_use && show_shell_mess) |
4613 # endif | |
4614 ) | |
7 | 4615 { |
167 | 4616 # ifdef FEAT_GUI |
7 | 4617 if (pty_master_fd >= 0) /* close the pseudo tty */ |
4618 { | |
4619 close(pty_master_fd); | |
4620 close(pty_slave_fd); | |
4621 } | |
4622 else /* close the pipes */ | |
167 | 4623 # endif |
7 | 4624 { |
4625 close(fd_toshell[0]); | |
4626 close(fd_toshell[1]); | |
4627 close(fd_fromshell[0]); | |
4628 close(fd_fromshell[1]); | |
4629 } | |
4630 } | |
4631 } | |
4632 else if (pid == 0) /* child */ | |
4633 { | |
4634 reset_signals(); /* handle signals normally */ | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4635 UNBLOCK_SIGNALS(&curset); |
7 | 4636 |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4637 # ifdef FEAT_JOB_CHANNEL |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4638 if (ch_log_active()) |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4639 /* close the log file in the child */ |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4640 ch_logfile((char_u *)"", (char_u *)""); |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4641 # endif |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4642 |
7 | 4643 if (!show_shell_mess || (options & SHELL_EXPAND)) |
4644 { | |
4645 int fd; | |
4646 | |
4647 /* | |
4648 * Don't want to show any message from the shell. Can't just | |
4649 * close stdout and stderr though, because some systems will | |
4650 * break if you try to write to them after that, so we must | |
4651 * use dup() to replace them with something else -- webb | |
4652 * Connect stdin to /dev/null too, so ":n `cat`" doesn't hang, | |
4653 * waiting for input. | |
4654 */ | |
4655 fd = open("/dev/null", O_RDWR | O_EXTRA, 0); | |
4656 fclose(stdin); | |
4657 fclose(stdout); | |
4658 fclose(stderr); | |
4659 | |
4660 /* | |
4661 * If any of these open()'s and dup()'s fail, we just continue | |
4662 * anyway. It's not fatal, and on most systems it will make | |
4663 * no difference at all. On a few it will cause the execvp() | |
4664 * to exit with a non-zero status even when the completion | |
4665 * could be done, which is nothing too serious. If the open() | |
4666 * or dup() failed we'd just do the same thing ourselves | |
4667 * anyway -- webb | |
4668 */ | |
4669 if (fd >= 0) | |
4670 { | |
1757 | 4671 ignored = dup(fd); /* To replace stdin (fd 0) */ |
4672 ignored = dup(fd); /* To replace stdout (fd 1) */ | |
4673 ignored = dup(fd); /* To replace stderr (fd 2) */ | |
7 | 4674 |
4675 /* Don't need this now that we've duplicated it */ | |
4676 close(fd); | |
4677 } | |
4678 } | |
167 | 4679 else if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4680 # ifdef FEAT_GUI |
167 | 4681 || gui.in_use |
4682 # endif | |
4683 ) | |
7 | 4684 { |
4685 | |
167 | 4686 # ifdef HAVE_SETSID |
602 | 4687 /* Create our own process group, so that the child and all its |
4688 * children can be kill()ed. Don't do this when using pipes, | |
1698 | 4689 * because stdin is not a tty, we would lose /dev/tty. */ |
602 | 4690 if (p_stmp) |
1799 | 4691 { |
602 | 4692 (void)setsid(); |
1799 | 4693 # if defined(SIGHUP) |
4694 /* When doing "!xterm&" and 'shell' is bash: the shell | |
4695 * will exit and send SIGHUP to all processes in its | |
4696 * group, killing the just started process. Ignore SIGHUP | |
4697 * to avoid that. (suggested by Simon Schubert) | |
4698 */ | |
4699 signal(SIGHUP, SIG_IGN); | |
4700 # endif | |
4701 } | |
167 | 4702 # endif |
4703 # ifdef FEAT_GUI | |
602 | 4704 if (pty_slave_fd >= 0) |
4705 { | |
4706 /* push stream discipline modules */ | |
4707 if (options & SHELL_COOKED) | |
4708 SetupSlavePTY(pty_slave_fd); | |
7 | 4709 # ifdef TIOCSCTTY |
602 | 4710 /* Try to become controlling tty (probably doesn't work, |
4711 * unless run by root) */ | |
4712 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); | |
7 | 4713 # endif |
602 | 4714 } |
167 | 4715 # endif |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4716 set_default_child_environment(FALSE); |
167 | 4717 |
557 | 4718 /* |
4719 * stderr is only redirected when using the GUI, so that a | |
4720 * program like gpg can still access the terminal to get a | |
4721 * passphrase using stderr. | |
4722 */ | |
167 | 4723 # ifdef FEAT_GUI |
7 | 4724 if (pty_master_fd >= 0) |
4725 { | |
4726 close(pty_master_fd); /* close master side of pty */ | |
4727 | |
4728 /* set up stdin/stdout/stderr for the child */ | |
4729 close(0); | |
1757 | 4730 ignored = dup(pty_slave_fd); |
7 | 4731 close(1); |
1757 | 4732 ignored = dup(pty_slave_fd); |
557 | 4733 if (gui.in_use) |
4734 { | |
4735 close(2); | |
1757 | 4736 ignored = dup(pty_slave_fd); |
557 | 4737 } |
7 | 4738 |
4739 close(pty_slave_fd); /* has been dupped, close it now */ | |
4740 } | |
4741 else | |
167 | 4742 # endif |
7 | 4743 { |
4744 /* set up stdin for the child */ | |
4745 close(fd_toshell[1]); | |
4746 close(0); | |
1757 | 4747 ignored = dup(fd_toshell[0]); |
7 | 4748 close(fd_toshell[0]); |
4749 | |
4750 /* set up stdout for the child */ | |
4751 close(fd_fromshell[0]); | |
4752 close(1); | |
1757 | 4753 ignored = dup(fd_fromshell[1]); |
7 | 4754 close(fd_fromshell[1]); |
4755 | |
557 | 4756 # ifdef FEAT_GUI |
4757 if (gui.in_use) | |
4758 { | |
4759 /* set up stderr for the child */ | |
4760 close(2); | |
1757 | 4761 ignored = dup(1); |
557 | 4762 } |
4763 # endif | |
7 | 4764 } |
4765 } | |
167 | 4766 |
7 | 4767 /* |
4768 * There is no type cast for the argv, because the type may be | |
4769 * different on different machines. This may cause a warning | |
4770 * message with strict compilers, don't worry about it. | |
4771 * Call _exit() instead of exit() to avoid closing the connection | |
4772 * to the X server (esp. with GTK, which uses atexit()). | |
4773 */ | |
4774 execvp(argv[0], argv); | |
4775 _exit(EXEC_FAILED); /* exec failed, return failure code */ | |
4776 } | |
4777 else /* parent */ | |
4778 { | |
4779 /* | |
4780 * While child is running, ignore terminating signals. | |
167 | 4781 * Do catch CTRL-C, so that "got_int" is set. |
7 | 4782 */ |
4783 catch_signals(SIG_IGN, SIG_ERR); | |
167 | 4784 catch_int_signal(); |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4785 UNBLOCK_SIGNALS(&curset); |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4786 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4787 ++dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4788 # endif |
7 | 4789 /* |
4790 * For the GUI we redirect stdin, stdout and stderr to our window. | |
167 | 4791 * This is also used to pipe stdin/stdout to/from the external |
4792 * command. | |
7 | 4793 */ |
167 | 4794 if ((options & (SHELL_READ|SHELL_WRITE)) |
4795 # ifdef FEAT_GUI | |
4796 || (gui.in_use && show_shell_mess) | |
4797 # endif | |
4798 ) | |
7 | 4799 { |
167 | 4800 # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ |
7 | 4801 char_u buffer[BUFLEN + 1]; |
167 | 4802 # ifdef FEAT_MBYTE |
7 | 4803 int buffer_off = 0; /* valid bytes in buffer[] */ |
167 | 4804 # endif |
7 | 4805 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ |
4806 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4807 int len; | |
4808 int p_more_save; | |
4809 int old_State; | |
4810 int c; | |
4811 int toshell_fd; | |
4812 int fromshell_fd; | |
167 | 4813 garray_T ga; |
4814 int noread_cnt; | |
1823 | 4815 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) |
4816 struct timeval start_tv; | |
4817 # endif | |
167 | 4818 |
4819 # ifdef FEAT_GUI | |
7 | 4820 if (pty_master_fd >= 0) |
4821 { | |
4822 fromshell_fd = pty_master_fd; | |
4823 toshell_fd = dup(pty_master_fd); | |
4824 } | |
4825 else | |
167 | 4826 # endif |
7 | 4827 { |
4828 close(fd_toshell[0]); | |
4829 close(fd_fromshell[1]); | |
4830 toshell_fd = fd_toshell[1]; | |
4831 fromshell_fd = fd_fromshell[0]; | |
4832 } | |
4833 | |
4834 /* | |
4835 * Write to the child if there are typed characters. | |
4836 * Read from the child if there are characters available. | |
4837 * Repeat the reading a few times if more characters are | |
4838 * available. Need to check for typed keys now and then, but | |
4839 * not too often (delays when no chars are available). | |
4840 * This loop is quit if no characters can be read from the pty | |
4841 * (WaitForChar detected special condition), or there are no | |
4842 * characters available and the child has exited. | |
4843 * Only check if the child has exited when there is no more | |
4844 * output. The child may exit before all the output has | |
4845 * been printed. | |
4846 * | |
4847 * Currently this busy loops! | |
4848 * This can probably dead-lock when the write blocks! | |
4849 */ | |
4850 p_more_save = p_more; | |
4851 p_more = FALSE; | |
4852 old_State = State; | |
4853 State = EXTERNCMD; /* don't redraw at window resize */ | |
4854 | |
602 | 4855 if ((options & SHELL_WRITE) && toshell_fd >= 0) |
167 | 4856 { |
4857 /* Fork a process that will write the lines to the | |
4858 * external program. */ | |
4859 if ((wpid = fork()) == -1) | |
4860 { | |
4861 MSG_PUTS(_("\nCannot fork\n")); | |
4862 } | |
3048 | 4863 else if (wpid == 0) /* child */ |
167 | 4864 { |
4865 linenr_T lnum = curbuf->b_op_start.lnum; | |
4866 int written = 0; | |
944 | 4867 char_u *lp = ml_get(lnum); |
167 | 4868 size_t l; |
4869 | |
177 | 4870 close(fromshell_fd); |
167 | 4871 for (;;) |
4872 { | |
944 | 4873 l = STRLEN(lp + written); |
167 | 4874 if (l == 0) |
4875 len = 0; | |
944 | 4876 else if (lp[written] == NL) |
167 | 4877 /* NL -> NUL translation */ |
4878 len = write(toshell_fd, "", (size_t)1); | |
4879 else | |
4880 { | |
3263 | 4881 char_u *s = vim_strchr(lp + written, NL); |
4882 | |
944 | 4883 len = write(toshell_fd, (char *)lp + written, |
1877 | 4884 s == NULL ? l |
4885 : (size_t)(s - (lp + written))); | |
167 | 4886 } |
1877 | 4887 if (len == (int)l) |
167 | 4888 { |
4889 /* Finished a line, add a NL, unless this line | |
4890 * should not have one. */ | |
4891 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4892 || (!curbuf->b_p_bin |
4893 && curbuf->b_p_fixeol) | |
2707 | 4894 || (lnum != curbuf->b_no_eol_lnum |
167 | 4895 && (lnum != |
4896 curbuf->b_ml.ml_line_count | |
4897 || curbuf->b_p_eol))) | |
1757 | 4898 ignored = write(toshell_fd, "\n", |
4899 (size_t)1); | |
167 | 4900 ++lnum; |
4901 if (lnum > curbuf->b_op_end.lnum) | |
4902 { | |
4903 /* finished all the lines, close pipe */ | |
4904 close(toshell_fd); | |
4905 toshell_fd = -1; | |
4906 break; | |
4907 } | |
944 | 4908 lp = ml_get(lnum); |
167 | 4909 written = 0; |
4910 } | |
4911 else if (len > 0) | |
4912 written += len; | |
4913 } | |
4914 _exit(0); | |
4915 } | |
3048 | 4916 else /* parent */ |
167 | 4917 { |
4918 close(toshell_fd); | |
4919 toshell_fd = -1; | |
4920 } | |
4921 } | |
4922 | |
4923 if (options & SHELL_READ) | |
4924 ga_init2(&ga, 1, BUFLEN); | |
4925 | |
4926 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4927 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4928 ELAPSED_INIT(start_tv); |
1823 | 4929 # endif |
7 | 4930 for (;;) |
4931 { | |
4932 /* | |
4933 * Check if keys have been typed, write them to the child | |
592 | 4934 * if there are any. |
4935 * Don't do this if we are expanding wild cards (would eat | |
4936 * typeahead). | |
4937 * Don't do this when filtering and terminal is in cooked | |
4938 * mode, the shell command will handle the I/O. Avoids | |
4939 * that a typed password is echoed for ssh or gpg command. | |
602 | 4940 * Don't get characters when the child has already |
4941 * finished (wait_pid == 0). | |
167 | 4942 * Don't read characters unless we didn't get output for a |
1823 | 4943 * while (noread_cnt > 4), avoids that ":r !ls" eats |
4944 * typeahead. | |
7 | 4945 */ |
4946 len = 0; | |
4947 if (!(options & SHELL_EXPAND) | |
592 | 4948 && ((options & |
4949 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4950 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
1823 | 4951 # ifdef FEAT_GUI |
592 | 4952 || gui.in_use |
1823 | 4953 # endif |
592 | 4954 ) |
602 | 4955 && wait_pid == 0 |
1823 | 4956 && (ta_len > 0 || noread_cnt > 4)) |
7 | 4957 { |
1823 | 4958 if (ta_len == 0) |
4959 { | |
4960 /* Get extra characters when we don't have any. | |
4961 * Reset the counter and timer. */ | |
4962 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4963 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4964 ELAPSED_INIT(start_tv); |
1823 | 4965 # endif |
4966 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4967 } | |
4968 if (ta_len > 0 || len > 0) | |
4969 { | |
7 | 4970 /* |
4971 * For pipes: | |
4972 * Check for CTRL-C: send interrupt signal to child. | |
4973 * Check for CTRL-D: EOF, close pipe to child. | |
4974 */ | |
4975 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) | |
4976 { | |
4977 /* | |
4978 * Send SIGINT to the child's group or all | |
4979 * processes in our group. | |
4980 */ | |
11919
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4981 may_send_sigint(ta_buf[ta_len], pid, wpid); |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4982 |
7 | 4983 if (pty_master_fd < 0 && toshell_fd >= 0 |
4984 && ta_buf[ta_len] == Ctrl_D) | |
4985 { | |
4986 close(toshell_fd); | |
4987 toshell_fd = -1; | |
4988 } | |
4989 } | |
4990 | |
4991 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4992 for (i = ta_len; i < ta_len + len; ++i) | |
4993 { | |
4994 if (ta_buf[i] == CSI && len - i > 2) | |
4995 { | |
4996 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4997 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4998 { | |
4999 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
5000 (size_t)(len - i - 2)); | |
5001 if (c == K_DEL || c == K_KDEL) | |
5002 ta_buf[i] = DEL; | |
5003 else | |
5004 ta_buf[i] = Ctrl_H; | |
5005 len -= 2; | |
5006 } | |
5007 } | |
5008 else if (ta_buf[i] == '\r') | |
5009 ta_buf[i] = '\n'; | |
167 | 5010 # ifdef FEAT_MBYTE |
7 | 5011 if (has_mbyte) |
1903 | 5012 i += (*mb_ptr2len_len)(ta_buf + i, |
5013 ta_len + len - i) - 1; | |
167 | 5014 # endif |
7 | 5015 } |
5016 | |
5017 /* | |
5018 * For pipes: echo the typed characters. | |
5019 * For a pty this does not seem to work. | |
5020 */ | |
5021 if (pty_master_fd < 0) | |
5022 { | |
5023 for (i = ta_len; i < ta_len + len; ++i) | |
5024 { | |
5025 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
5026 msg_putchar(ta_buf[i]); | |
167 | 5027 # ifdef FEAT_MBYTE |
7 | 5028 else if (has_mbyte) |
5029 { | |
474 | 5030 int l = (*mb_ptr2len)(ta_buf + i); |
7 | 5031 |
5032 msg_outtrans_len(ta_buf + i, l); | |
5033 i += l - 1; | |
5034 } | |
167 | 5035 # endif |
7 | 5036 else |
5037 msg_outtrans_len(ta_buf + i, 1); | |
5038 } | |
5039 windgoto(msg_row, msg_col); | |
5040 out_flush(); | |
5041 } | |
5042 | |
5043 ta_len += len; | |
5044 | |
5045 /* | |
5046 * Write the characters to the child, unless EOF has | |
5047 * been typed for pipes. Write one character at a | |
1698 | 5048 * time, to avoid losing too much typeahead. |
167 | 5049 * When writing buffer lines, drop the typed |
5050 * characters (only check for CTRL-C). | |
7 | 5051 */ |
167 | 5052 if (options & SHELL_WRITE) |
5053 ta_len = 0; | |
5054 else if (toshell_fd >= 0) | |
7 | 5055 { |
5056 len = write(toshell_fd, (char *)ta_buf, (size_t)1); | |
5057 if (len > 0) | |
5058 { | |
5059 ta_len -= len; | |
5060 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
5061 } | |
5062 } | |
1823 | 5063 } |
7 | 5064 } |
5065 | |
167 | 5066 if (got_int) |
5067 { | |
5068 /* CTRL-C sends a signal to the child, we ignore it | |
5069 * ourselves */ | |
5070 # ifdef HAVE_SETSID | |
5071 kill(-pid, SIGINT); | |
5072 # else | |
5073 kill(0, SIGINT); | |
5074 # endif | |
5075 if (wpid > 0) | |
5076 kill(wpid, SIGINT); | |
5077 got_int = FALSE; | |
5078 } | |
5079 | |
7 | 5080 /* |
5081 * Check if the child has any characters to be printed. | |
5082 * Read them and write them to our window. Repeat this as | |
5083 * long as there is something to do, avoid the 10ms wait | |
5084 * for mch_inchar(), or sending typeahead characters to | |
5085 * the external process. | |
5086 * TODO: This should handle escape sequences, compatible | |
5087 * to some terminal (vt52?). | |
5088 */ | |
167 | 5089 ++noread_cnt; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5090 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL)) |
7 | 5091 { |
2664 | 5092 len = read_eintr(fromshell_fd, buffer |
167 | 5093 # ifdef FEAT_MBYTE |
7 | 5094 + buffer_off, (size_t)(BUFLEN - buffer_off) |
167 | 5095 # else |
7 | 5096 , (size_t)BUFLEN |
167 | 5097 # endif |
7 | 5098 ); |
5099 if (len <= 0) /* end of file or error */ | |
5100 goto finished; | |
167 | 5101 |
5102 noread_cnt = 0; | |
5103 if (options & SHELL_READ) | |
5104 { | |
5105 /* Do NUL -> NL translation, append NL separated | |
5106 * lines to the current buffer. */ | |
5107 for (i = 0; i < len; ++i) | |
5108 { | |
5109 if (buffer[i] == NL) | |
5110 append_ga_line(&ga); | |
5111 else if (buffer[i] == NUL) | |
5112 ga_append(&ga, NL); | |
5113 else | |
5114 ga_append(&ga, buffer[i]); | |
5115 } | |
5116 } | |
5117 # ifdef FEAT_MBYTE | |
5118 else if (has_mbyte) | |
7 | 5119 { |
5120 int l; | |
13478
601d797cca88
patch 8.0.1613: warning for unused variable in tiny build
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
5121 char_u *p; |
7 | 5122 |
167 | 5123 len += buffer_off; |
5124 buffer[len] = NUL; | |
5125 | |
7 | 5126 /* Check if the last character in buffer[] is |
5127 * incomplete, keep these bytes for the next | |
5128 * round. */ | |
5129 for (p = buffer; p < buffer + len; p += l) | |
5130 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9873
diff
changeset
|
5131 l = MB_CPTR2LEN(p); |
7 | 5132 if (l == 0) |
5133 l = 1; /* NUL byte? */ | |
5134 else if (MB_BYTE2LEN(*p) != l) | |
5135 break; | |
5136 } | |
5137 if (p == buffer) /* no complete character */ | |
5138 { | |
5139 /* avoid getting stuck at an illegal byte */ | |
5140 if (len >= 12) | |
5141 ++p; | |
5142 else | |
5143 { | |
5144 buffer_off = len; | |
5145 continue; | |
5146 } | |
5147 } | |
5148 c = *p; | |
5149 *p = NUL; | |
5150 msg_puts(buffer); | |
5151 if (p < buffer + len) | |
5152 { | |
5153 *p = c; | |
5154 buffer_off = (buffer + len) - p; | |
5155 mch_memmove(buffer, p, buffer_off); | |
5156 continue; | |
5157 } | |
5158 buffer_off = 0; | |
5159 } | |
167 | 5160 # endif /* FEAT_MBYTE */ |
7 | 5161 else |
5162 { | |
5163 buffer[len] = NUL; | |
5164 msg_puts(buffer); | |
5165 } | |
5166 | |
5167 windgoto(msg_row, msg_col); | |
5168 cursor_on(); | |
5169 out_flush(); | |
5170 if (got_int) | |
5171 break; | |
1823 | 5172 |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5173 # ifdef ELAPSED_FUNC |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5174 if (wait_pid == 0) |
1823 | 5175 { |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5176 long msec = ELAPSED_FUNC(start_tv); |
1823 | 5177 |
5178 /* Avoid that we keep looping here without | |
5179 * checking for a CTRL-C for a long time. Don't | |
5180 * break out too often to avoid losing typeahead. */ | |
5181 if (msec > 2000) | |
5182 { | |
5183 noread_cnt = 5; | |
5184 break; | |
5185 } | |
5186 } | |
5187 # endif | |
7 | 5188 } |
5189 | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5190 /* If we already detected the child has finished, continue |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5191 * reading output for a short while. Some text may be |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5192 * buffered. */ |
602 | 5193 if (wait_pid == pid) |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5194 { |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5195 if (noread_cnt < 5) |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5196 continue; |
602 | 5197 break; |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5198 } |
602 | 5199 |
7 | 5200 /* |
5201 * Check if the child still exists, before checking for | |
1698 | 5202 * typed characters (otherwise we would lose typeahead). |
7 | 5203 */ |
167 | 5204 # ifdef __NeXT__ |
3048 | 5205 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); |
167 | 5206 # else |
7 | 5207 wait_pid = waitpid(pid, &status, WNOHANG); |
167 | 5208 # endif |
7 | 5209 if ((wait_pid == (pid_t)-1 && errno == ECHILD) |
5210 || (wait_pid == pid && WIFEXITED(status))) | |
5211 { | |
602 | 5212 /* Don't break the loop yet, try reading more |
5213 * characters from "fromshell_fd" first. When using | |
5214 * pipes there might still be something to read and | |
5215 * then we'll break the loop at the "break" above. */ | |
7 | 5216 wait_pid = pid; |
5217 } | |
602 | 5218 else |
5219 wait_pid = 0; | |
4230 | 5220 |
4248 | 5221 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5222 /* Handle any X events, e.g. serving the clipboard. */ |
5223 clip_update(); | |
5224 # endif | |
7 | 5225 } |
5226 finished: | |
5227 p_more = p_more_save; | |
167 | 5228 if (options & SHELL_READ) |
5229 { | |
5230 if (ga.ga_len > 0) | |
5231 { | |
5232 append_ga_line(&ga); | |
5233 /* remember that the NL was missing */ | |
2707 | 5234 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
167 | 5235 } |
5236 else | |
2707 | 5237 curbuf->b_no_eol_lnum = 0; |
167 | 5238 ga_clear(&ga); |
5239 } | |
5240 | |
7 | 5241 /* |
5242 * Give all typeahead that wasn't used back to ui_inchar(). | |
5243 */ | |
5244 if (ta_len) | |
5245 ui_inchar_undo(ta_buf, ta_len); | |
5246 State = old_State; | |
5247 if (toshell_fd >= 0) | |
5248 close(toshell_fd); | |
5249 close(fromshell_fd); | |
5250 } | |
4248 | 5251 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5252 else |
5253 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5254 long delay_msec = 1; |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5255 |
4230 | 5256 /* |
5257 * Similar to the loop above, but only handle X events, no | |
5258 * I/O. | |
5259 */ | |
5260 for (;;) | |
5261 { | |
5262 if (got_int) | |
5263 { | |
5264 /* CTRL-C sends a signal to the child, we ignore it | |
5265 * ourselves */ | |
5266 # ifdef HAVE_SETSID | |
5267 kill(-pid, SIGINT); | |
5268 # else | |
5269 kill(0, SIGINT); | |
5270 # endif | |
5271 got_int = FALSE; | |
5272 } | |
5273 # ifdef __NeXT__ | |
5274 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); | |
5275 # else | |
5276 wait_pid = waitpid(pid, &status, WNOHANG); | |
5277 # endif | |
5278 if ((wait_pid == (pid_t)-1 && errno == ECHILD) | |
5279 || (wait_pid == pid && WIFEXITED(status))) | |
5280 { | |
5281 wait_pid = pid; | |
5282 break; | |
5283 } | |
5284 | |
5285 /* Handle any X events, e.g. serving the clipboard. */ | |
5286 clip_update(); | |
5287 | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5288 /* Wait for 1 to 10 msec. 1 is faster but gives the child |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5289 * less time. */ |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5290 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5291 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5292 delay_msec = 10; |
4230 | 5293 } |
5294 } | |
5295 # endif | |
7 | 5296 |
5297 /* | |
5298 * Wait until our child has exited. | |
5299 * Ignore wait() returning pids of other children and returning | |
5300 * because of some signal like SIGWINCH. | |
5301 * Don't wait if wait_pid was already set above, indicating the | |
5302 * child already exited. | |
5303 */ | |
3048 | 5304 if (wait_pid != pid) |
5305 wait_pid = wait4pid(pid, &status); | |
7 | 5306 |
2600 | 5307 # ifdef FEAT_GUI |
5308 /* Close slave side of pty. Only do this after the child has | |
5309 * exited, otherwise the child may hang when it tries to write on | |
5310 * the pty. */ | |
5311 if (pty_master_fd >= 0) | |
5312 close(pty_slave_fd); | |
5313 # endif | |
5314 | |
167 | 5315 /* Make sure the child that writes to the external program is |
5316 * dead. */ | |
5317 if (wpid > 0) | |
3048 | 5318 { |
167 | 5319 kill(wpid, SIGKILL); |
3048 | 5320 wait4pid(wpid, NULL); |
5321 } | |
167 | 5322 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5323 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5324 --dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5325 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5326 |
7 | 5327 /* |
5328 * Set to raw mode right now, otherwise a CTRL-C after | |
5329 * catch_signals() will kill Vim. | |
5330 */ | |
5331 if (tmode == TMODE_RAW) | |
5332 settmode(TMODE_RAW); | |
5333 did_settmode = TRUE; | |
5334 set_signals(); | |
5335 | |
5336 if (WIFEXITED(status)) | |
5337 { | |
129 | 5338 /* LINTED avoid "bitwise operation on signed value" */ |
7 | 5339 retval = WEXITSTATUS(status); |
4074 | 5340 if (retval != 0 && !emsg_silent) |
7 | 5341 { |
5342 if (retval == EXEC_FAILED) | |
5343 { | |
5344 MSG_PUTS(_("\nCannot execute shell ")); | |
5345 msg_outtrans(p_sh); | |
5346 msg_putchar('\n'); | |
5347 } | |
5348 else if (!(options & SHELL_SILENT)) | |
5349 { | |
5350 MSG_PUTS(_("\nshell returned ")); | |
5351 msg_outnum((long)retval); | |
5352 msg_putchar('\n'); | |
5353 } | |
5354 } | |
5355 } | |
5356 else | |
5357 MSG_PUTS(_("\nCommand terminated\n")); | |
5358 } | |
5359 } | |
5360 | |
5361 error: | |
5362 if (!did_settmode) | |
5363 if (tmode == TMODE_RAW) | |
5364 settmode(TMODE_RAW); /* set to raw mode */ | |
5365 # ifdef FEAT_TITLE | |
5366 resettitle(); | |
5367 # endif | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5368 vim_free(argv); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5369 vim_free(tofree1); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5370 vim_free(tofree2); |
7 | 5371 |
5372 return retval; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5373 } |
7 | 5374 #endif /* USE_SYSTEM */ |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5375 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5376 int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5377 mch_call_shell( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5378 char_u *cmd, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5379 int options) /* SHELL_*, see vim.h */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5380 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5381 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5382 if (gui.in_use && vim_strchr(p_go, GO_TERMINAL) != NULL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5383 return mch_call_shell_terminal(cmd, options); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5384 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5385 #ifdef USE_SYSTEM |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5386 return mch_call_shell_system(cmd, options); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5387 #else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5388 return mch_call_shell_fork(cmd, options); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5389 #endif |
7 | 5390 } |
5391 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5392 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5393 void |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5394 mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5395 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5396 pid_t pid; |
11933
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
5397 int fd_in[2] = {-1, -1}; /* for stdin */ |
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
5398 int fd_out[2] = {-1, -1}; /* for stdout */ |
d033653d3df8
patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents:
11925
diff
changeset
|
5399 int fd_err[2] = {-1, -1}; /* for stderr */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5400 int pty_master_fd = -1; |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5401 int pty_slave_fd = -1; |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
5402 channel_T *channel = NULL; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5403 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5404 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5405 int use_null_for_err = options->jo_io[PART_ERR] == JIO_NULL; |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5406 int use_file_for_in = options->jo_io[PART_IN] == JIO_FILE; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5407 int use_file_for_out = options->jo_io[PART_OUT] == JIO_FILE; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5408 int use_file_for_err = options->jo_io[PART_ERR] == JIO_FILE; |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5409 int use_buffer_for_in = options->jo_io[PART_IN] == JIO_BUFFER; |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5410 int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT; |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5411 SIGSET_DECL(curset) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5412 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5413 if (use_out_for_err && use_null_for_out) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5414 use_null_for_err = TRUE; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5415 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5416 /* default is to fail */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5417 job->jv_status = JOB_FAILED; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5418 |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5419 if (options->jo_pty |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5420 && (!(use_file_for_in || use_null_for_in) |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5421 || !(use_file_for_in || use_null_for_out) |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5422 || !(use_out_for_err || use_file_for_err || use_null_for_err))) |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5423 { |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5424 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out); |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5425 if (job->jv_tty_out != NULL) |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5426 job->jv_tty_in = vim_strsave(job->jv_tty_out); |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5427 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5428 |
8068
9c6740f2204f
commit https://github.com/vim/vim/commit/12dcf024e90ab511f04a08b20fe7eedbe92096d2
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5429 /* TODO: without the channel feature connect the child to /dev/null? */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5430 /* Open pipes for stdin, stdout, stderr. */ |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5431 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5432 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5433 char_u *fname = options->jo_io_name[PART_IN]; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5434 |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5435 fd_in[0] = mch_open((char *)fname, O_RDONLY, 0); |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5436 if (fd_in[0] < 0) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5437 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5438 EMSG2(_(e_notopen), fname); |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5439 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5440 } |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5441 } |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5442 else |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5443 /* When writing buffer lines to the input don't use the pty, so that |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5444 * the pipe can be closed when all lines were written. */ |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5445 if (!use_null_for_in && (pty_master_fd < 0 || use_buffer_for_in) |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5446 && pipe(fd_in) < 0) |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5447 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5448 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5449 if (use_file_for_out) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5450 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5451 char_u *fname = options->jo_io_name[PART_OUT]; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5452 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5453 fd_out[1] = mch_open((char *)fname, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5454 if (fd_out[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5455 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5456 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5457 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5458 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5459 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5460 else if (!use_null_for_out && pty_master_fd < 0 && pipe(fd_out) < 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5461 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5462 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5463 if (use_file_for_err) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5464 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5465 char_u *fname = options->jo_io_name[PART_ERR]; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5466 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5467 fd_err[1] = mch_open((char *)fname, O_WRONLY | O_CREAT | O_TRUNC, 0600); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5468 if (fd_err[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5469 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5470 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5471 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5472 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5473 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5474 else if (!use_out_for_err && !use_null_for_err |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5475 && pty_master_fd < 0 && pipe(fd_err) < 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5476 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5477 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5478 if (!use_null_for_in || !use_null_for_out || !use_null_for_err) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5479 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5480 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5481 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5482 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5483 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5484 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5485 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5486 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5487 channel = add_channel(); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5488 if (channel == NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5489 goto failed; |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5490 if (job->jv_tty_out != NULL) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5491 ch_log(channel, "using pty %s on fd %d", |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5492 job->jv_tty_out, pty_master_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5493 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5494 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5495 BLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5496 pid = fork(); /* maybe we should use vfork() */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5497 if (pid == -1) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5498 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5499 /* failed to fork */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5500 UNBLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5501 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5502 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5503 if (pid == 0) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5504 { |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5505 int null_fd = -1; |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5506 int stderr_works = TRUE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5507 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5508 /* child */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5509 reset_signals(); /* handle signals normally */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5510 UNBLOCK_SIGNALS(&curset); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5511 |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5512 # ifdef FEAT_JOB_CHANNEL |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5513 if (ch_log_active()) |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5514 /* close the log file in the child */ |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5515 ch_logfile((char_u *)"", (char_u *)""); |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5516 # endif |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5517 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5518 # ifdef HAVE_SETSID |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5519 /* Create our own process group, so that the child and all its |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5520 * children can be kill()ed. Don't do this when using pipes, |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5521 * because stdin is not a tty, we would lose /dev/tty. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5522 (void)setsid(); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5523 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5524 |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5525 # ifdef FEAT_TERMINAL |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5526 if (options->jo_term_rows > 0) |
13585
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5527 { |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5528 char *term = (char *)T_NAME; |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5529 |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5530 #ifdef FEAT_GUI |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5531 if (term_is_gui(T_NAME)) |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5532 /* In the GUI 'term' is not what we want, use $TERM. */ |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5533 term = getenv("TERM"); |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5534 #endif |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5535 /* Use 'term' or $TERM if it starts with "xterm", otherwise fall |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5536 * back to "xterm". */ |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5537 if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0) |
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5538 term = "xterm"; |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5539 set_child_environment( |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5540 (long)options->jo_term_rows, |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5541 (long)options->jo_term_cols, |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5542 term, |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5543 is_terminal); |
13585
03224283bafc
patch 8.0.1665: when running a terminal from the GUI 'term' is not useful
Christian Brabandt <cb@256bit.org>
parents:
13511
diff
changeset
|
5544 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5545 else |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5546 # endif |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5547 set_default_child_environment(is_terminal); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5548 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5549 if (options->jo_env != NULL) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5550 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5551 dict_T *dict = options->jo_env; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5552 hashitem_T *hi; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5553 int todo = (int)dict->dv_hashtab.ht_used; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5554 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5555 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5556 if (!HASHITEM_EMPTY(hi)) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5557 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5558 typval_T *item = &dict_lookup(hi)->di_tv; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5559 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5560 vim_setenv((char_u*)hi->hi_key, get_tv_string(item)); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5561 --todo; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5562 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5563 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5564 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5565 if (use_null_for_in || use_null_for_out || use_null_for_err) |
12200
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5566 { |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5567 null_fd = open("/dev/null", O_RDWR | O_EXTRA, 0); |
12200
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5568 if (null_fd < 0) |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5569 { |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5570 perror("opening /dev/null failed"); |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5571 _exit(OPEN_NULL_FAILED); |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5572 } |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5573 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5574 |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5575 if (pty_slave_fd >= 0) |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5576 { |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5577 /* push stream discipline modules */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5578 SetupSlavePTY(pty_slave_fd); |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5579 # ifdef TIOCSCTTY |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5580 /* Try to become controlling tty (probably doesn't work, |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5581 * unless run by root) */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5582 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5583 # endif |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5584 } |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5585 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5586 /* set up stdin for the child */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5587 close(0); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5588 if (use_null_for_in && null_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5589 ignored = dup(null_fd); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5590 else if (fd_in[0] < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5591 ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5592 else |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5593 ignored = dup(fd_in[0]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5594 |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5595 /* set up stderr for the child */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5596 close(2); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5597 if (use_null_for_err && null_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5598 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5599 ignored = dup(null_fd); |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5600 stderr_works = FALSE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5601 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5602 else if (use_out_for_err) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5603 ignored = dup(fd_out[1]); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5604 else if (fd_err[1] < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5605 ignored = dup(pty_slave_fd); |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5606 else |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5607 ignored = dup(fd_err[1]); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5608 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5609 /* set up stdout for the child */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5610 close(1); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5611 if (use_null_for_out && null_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5612 ignored = dup(null_fd); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5613 else if (fd_out[1] < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5614 ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5615 else |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5616 ignored = dup(fd_out[1]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5617 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5618 if (fd_in[0] >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5619 close(fd_in[0]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5620 if (fd_in[1] >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5621 close(fd_in[1]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5622 if (fd_out[0] >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5623 close(fd_out[0]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5624 if (fd_out[1] >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5625 close(fd_out[1]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5626 if (fd_err[0] >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5627 close(fd_err[0]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5628 if (fd_err[1] >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5629 close(fd_err[1]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5630 if (pty_master_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5631 { |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5632 close(pty_master_fd); /* not used in the child */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5633 close(pty_slave_fd); /* was duped above */ |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5634 } |
9074
3aab62b76363
commit https://github.com/vim/vim/commit/ea83bf06b92baeb6d68a10d8e8ffad289d31dae2
Christian Brabandt <cb@256bit.org>
parents:
9009
diff
changeset
|
5635 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5636 if (null_fd >= 0) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5637 close(null_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5638 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5639 if (options->jo_cwd != NULL && mch_chdir((char *)options->jo_cwd) != 0) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5640 _exit(EXEC_FAILED); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5641 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5642 /* See above for type of argv. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5643 execvp(argv[0], argv); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5644 |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5645 if (stderr_works) |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5646 perror("executing job failed"); |
11919
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
5647 # ifdef EXITFREE |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5648 /* calling free_all_mem() here causes problems. Ignore valgrind |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5649 * reporting possibly leaked memory. */ |
11919
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
5650 # endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5651 _exit(EXEC_FAILED); /* exec failed, return failure code */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5652 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5653 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5654 /* parent */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5655 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5656 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5657 job->jv_pid = pid; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5658 job->jv_status = JOB_STARTED; |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5659 job->jv_channel = channel; /* ch_refcount was set above */ |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5660 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5661 if (pty_master_fd >= 0) |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5662 close(pty_slave_fd); /* not used in the parent */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5663 /* close child stdin, stdout and stderr */ |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5664 if (fd_in[0] >= 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5665 close(fd_in[0]); |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5666 if (fd_out[1] >= 0) |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5667 close(fd_out[1]); |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5668 if (fd_err[1] >= 0) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5669 close(fd_err[1]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5670 if (channel != NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5671 { |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5672 int in_fd = use_file_for_in || use_null_for_in |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5673 ? INVALID_FD : fd_in[1] < 0 ? pty_master_fd : fd_in[1]; |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5674 int out_fd = use_file_for_out || use_null_for_out |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5675 ? INVALID_FD : fd_out[0] < 0 ? pty_master_fd : fd_out[0]; |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5676 /* When using pty_master_fd only set it for stdout, do not duplicate it |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5677 * for stderr, it only needs to be read once. */ |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5678 int err_fd = use_out_for_err || use_file_for_err || use_null_for_err |
13898
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5679 ? INVALID_FD |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5680 : fd_err[0] >= 0 |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5681 ? fd_err[0] |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5682 : (out_fd == pty_master_fd |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5683 ? INVALID_FD |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5684 : pty_master_fd); |
13778
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5685 |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5686 channel_set_pipes(channel, in_fd, out_fd, err_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5687 channel_set_job(channel, job, options); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5688 } |
11894
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5689 else |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5690 { |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5691 if (fd_in[1] >= 0) |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5692 close(fd_in[1]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5693 if (fd_out[0] >= 0) |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5694 close(fd_out[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5695 if (fd_err[0] >= 0) |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5696 close(fd_err[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5697 if (pty_master_fd >= 0) |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5698 close(pty_master_fd); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5699 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5700 |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5701 /* success! */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5702 return; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5703 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5704 failed: |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5705 channel_unref(channel); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5706 if (fd_in[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5707 close(fd_in[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5708 if (fd_in[1] >= 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5709 close(fd_in[1]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5710 if (fd_out[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5711 close(fd_out[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5712 if (fd_out[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5713 close(fd_out[1]); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5714 if (fd_err[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5715 close(fd_err[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5716 if (fd_err[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5717 close(fd_err[1]); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5718 if (pty_master_fd >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5719 close(pty_master_fd); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5720 if (pty_slave_fd >= 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5721 close(pty_slave_fd); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5722 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5723 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5724 char * |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5725 mch_job_status(job_T *job) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5726 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5727 # ifdef HAVE_UNION_WAIT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5728 union wait status; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5729 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5730 int status = -1; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5731 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5732 pid_t wait_pid = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5733 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5734 # ifdef __NeXT__ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5735 wait_pid = wait4(job->jv_pid, &status, WNOHANG, (struct rusage *)0); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5736 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5737 wait_pid = waitpid(job->jv_pid, &status, WNOHANG); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5738 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5739 if (wait_pid == -1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5740 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5741 /* process must have exited */ |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5742 if (job->jv_status < JOB_ENDED) |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5743 ch_log(job->jv_channel, "Job no longer exists: %s", |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5744 strerror(errno)); |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5745 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5746 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5747 if (wait_pid == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5748 return "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5749 if (WIFEXITED(status)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5750 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5751 /* LINTED avoid "bitwise operation on signed value" */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5752 job->jv_exitval = WEXITSTATUS(status); |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5753 if (job->jv_status < JOB_ENDED) |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5754 ch_log(job->jv_channel, "Job exited with %d", job->jv_exitval); |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5755 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5756 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5757 if (WIFSIGNALED(status)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5758 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5759 job->jv_exitval = -1; |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5760 if (job->jv_status < JOB_ENDED) |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5761 ch_log(job->jv_channel, "Job terminated by a signal"); |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5762 goto return_dead; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5763 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5764 return "run"; |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5765 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5766 return_dead: |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5767 if (job->jv_status < JOB_ENDED) |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5768 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5769 return "dead"; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5770 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5771 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5772 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5773 mch_detect_ended_job(job_T *job_list) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5774 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5775 # ifdef HAVE_UNION_WAIT |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5776 union wait status; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5777 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5778 int status = -1; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5779 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5780 pid_t wait_pid = 0; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5781 job_T *job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5782 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5783 # ifndef USE_SYSTEM |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5784 /* Do not do this when waiting for a shell command to finish, we would get |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5785 * the exit value here (and discard it), the exit value obtained there |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5786 * would then be wrong. */ |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5787 if (dont_check_job_ended > 0) |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5788 return NULL; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5789 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5790 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5791 # ifdef __NeXT__ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5792 wait_pid = wait4(-1, &status, WNOHANG, (struct rusage *)0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5793 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5794 wait_pid = waitpid(-1, &status, WNOHANG); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5795 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5796 if (wait_pid <= 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5797 /* no process ended */ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5798 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5799 for (job = job_list; job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5800 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5801 if (job->jv_pid == wait_pid) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5802 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5803 if (WIFEXITED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5804 /* LINTED avoid "bitwise operation on signed value" */ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5805 job->jv_exitval = WEXITSTATUS(status); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5806 else if (WIFSIGNALED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5807 job->jv_exitval = -1; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5808 if (job->jv_status < JOB_ENDED) |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5809 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5810 ch_log(job->jv_channel, "Job ended"); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5811 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5812 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5813 return job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5814 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5815 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5816 return NULL; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5817 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5818 |
10320
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5819 /* |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5820 * Send a (deadly) signal to "job". |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5821 * Return FAIL if "how" is not a valid name. |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5822 */ |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5823 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
5824 mch_signal_job(job_T *job, char_u *how) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5825 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5826 int sig = -1; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5827 pid_t job_pid; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5828 |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5829 if (*how == NUL || STRCMP(how, "term") == 0) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5830 sig = SIGTERM; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5831 else if (STRCMP(how, "hup") == 0) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5832 sig = SIGHUP; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5833 else if (STRCMP(how, "quit") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5834 sig = SIGQUIT; |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5835 else if (STRCMP(how, "int") == 0) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5836 sig = SIGINT; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5837 else if (STRCMP(how, "kill") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5838 sig = SIGKILL; |
11741
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
5839 #ifdef SIGWINCH |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
5840 else if (STRCMP(how, "winch") == 0) |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
5841 sig = SIGWINCH; |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
5842 #endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5843 else if (isdigit(*how)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5844 sig = atoi((char *)how); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5845 else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5846 return FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5847 |
7999
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
5848 /* TODO: have an option to only kill the process, not the group? */ |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5849 job_pid = job->jv_pid; |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
5850 #ifdef HAVE_GETPGID |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5851 if (job_pid == getpgid(job_pid)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5852 job_pid = -job_pid; |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
5853 #endif |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5854 |
11727
cb1dc90d22cc
patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
5855 /* Never kill ourselves! */ |
cb1dc90d22cc
patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
5856 if (job_pid != 0) |
cb1dc90d22cc
patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
5857 kill(job_pid, sig); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5858 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5859 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5860 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5861 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5862 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5863 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5864 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5865 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5866 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5867 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5868 /* call waitpid because child process may become zombie */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5869 # ifdef __NeXT__ |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5870 (void)wait4(job->jv_pid, NULL, WNOHANG, (struct rusage *)0); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5871 # else |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5872 (void)waitpid(job->jv_pid, NULL, WNOHANG); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5873 # endif |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5874 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5875 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5876 |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5877 #if defined(FEAT_TERMINAL) || defined(PROTO) |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5878 int |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5879 mch_create_pty_channel(job_T *job, jobopt_T *options) |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5880 { |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5881 int pty_master_fd = -1; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5882 int pty_slave_fd = -1; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5883 channel_T *channel; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5884 |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5885 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out); |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5886 if (job->jv_tty_out != NULL) |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5887 job->jv_tty_in = vim_strsave(job->jv_tty_out); |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5888 close(pty_slave_fd); |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5889 |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5890 channel = add_channel(); |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5891 if (channel == NULL) |
12369
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5892 { |
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5893 close(pty_master_fd); |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5894 return FAIL; |
12369
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5895 } |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5896 if (job->jv_tty_out != NULL) |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5897 ch_log(channel, "using pty %s on fd %d", |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5898 job->jv_tty_out, pty_master_fd); |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5899 job->jv_channel = channel; /* ch_refcount was set by add_channel() */ |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5900 channel->ch_keep_open = TRUE; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5901 |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5902 /* Only set the pty_master_fd for stdout, do not duplicate it for stderr, |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5903 * it only needs to be read once. */ |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5904 channel_set_pipes(channel, pty_master_fd, pty_master_fd, INVALID_FD); |
12240
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5905 channel_set_job(channel, job, options); |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5906 return OK; |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5907 } |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5908 #endif |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5909 |
7 | 5910 /* |
5911 * Check for CTRL-C typed by reading all available characters. | |
5912 * In cooked mode we should get SIGINT, no need to check. | |
5913 */ | |
5914 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5915 mch_breakcheck(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5916 { |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5917 if ((curr_tmode == TMODE_RAW || force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5918 && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL)) |
7 | 5919 fill_input_buf(FALSE); |
5920 } | |
5921 | |
5922 /* | |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5923 * Wait "msec" msec until a character is available from the mouse, keyboard, |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5924 * from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5925 * "msec" == -1 will block forever. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5926 * Invokes timer callbacks when needed. |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5927 * When "ignore_input" is TRUE even check for pending input when input is |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5928 * already available. |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5929 * "interrupted" (if not NULL) is set to TRUE when no character is available |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5930 * but something else needs to be done. |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5931 * Returns TRUE when a character is available. |
7 | 5932 * When a GUI is being used, this will never get called -- webb |
5933 */ | |
5934 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5935 WaitForChar(long msec, int *interrupted, int ignore_input) |
7 | 5936 { |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5937 #ifdef FEAT_TIMERS |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5938 return ui_wait_for_chars_or_timer( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5939 msec, WaitForCharOrMouse, interrupted, ignore_input) == OK; |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5940 #else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5941 return WaitForCharOrMouse(msec, interrupted, ignore_input); |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5942 #endif |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5943 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5944 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5945 /* |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5946 * Wait "msec" msec until a character is available from the mouse or keyboard |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5947 * or from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5948 * "msec" == -1 will block forever. |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5949 * for "ignore_input" see WaitForCharOr(). |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5950 * "interrupted" (if not NULL) is set to TRUE when no character is available |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5951 * but something else needs to be done. |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5952 * When a GUI is being used, this will never get called -- webb |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5953 */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5954 static int |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5955 WaitForCharOrMouse(long msec, int *interrupted, int ignore_input) |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5956 { |
7 | 5957 #ifdef FEAT_MOUSE_GPM |
5958 int gpm_process_wanted; | |
5959 #endif | |
5960 #ifdef FEAT_XCLIPBOARD | |
5961 int rest; | |
5962 #endif | |
5963 int avail; | |
5964 | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5965 if (!ignore_input && input_available()) /* something in inbuf[] */ |
7 | 5966 return 1; |
5967 | |
5968 #if defined(FEAT_MOUSE_DEC) | |
5969 /* May need to query the mouse position. */ | |
5970 if (WantQueryMouse) | |
5971 { | |
227 | 5972 WantQueryMouse = FALSE; |
7 | 5973 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5); |
5974 } | |
5975 #endif | |
5976 | |
5977 /* | |
5978 * For FEAT_MOUSE_GPM and FEAT_XCLIPBOARD we loop here to process mouse | |
5979 * events. This is a bit complicated, because they might both be defined. | |
5980 */ | |
5981 #if defined(FEAT_MOUSE_GPM) || defined(FEAT_XCLIPBOARD) | |
5982 # ifdef FEAT_XCLIPBOARD | |
5983 rest = 0; | |
5984 if (do_xterm_trace()) | |
5985 rest = msec; | |
5986 # endif | |
5987 do | |
5988 { | |
5989 # ifdef FEAT_XCLIPBOARD | |
5990 if (rest != 0) | |
5991 { | |
5992 msec = XT_TRACE_DELAY; | |
5993 if (rest >= 0 && rest < XT_TRACE_DELAY) | |
5994 msec = rest; | |
5995 if (rest >= 0) | |
5996 rest -= msec; | |
5997 } | |
5998 # endif | |
5999 # ifdef FEAT_MOUSE_GPM | |
6000 gpm_process_wanted = 0; | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6001 avail = RealWaitForChar(read_cmd_fd, msec, |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6002 &gpm_process_wanted, interrupted); |
7 | 6003 # else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6004 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 6005 # endif |
6006 if (!avail) | |
6007 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
6008 if (!ignore_input && input_available()) |
7 | 6009 return 1; |
6010 # ifdef FEAT_XCLIPBOARD | |
6011 if (rest == 0 || !do_xterm_trace()) | |
6012 # endif | |
6013 break; | |
6014 } | |
6015 } | |
6016 while (FALSE | |
6017 # ifdef FEAT_MOUSE_GPM | |
6018 || (gpm_process_wanted && mch_gpm_process() == 0) | |
6019 # endif | |
6020 # ifdef FEAT_XCLIPBOARD | |
6021 || (!avail && rest != 0) | |
6022 # endif | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6023 ) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6024 ; |
7 | 6025 |
6026 #else | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6027 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 6028 #endif |
6029 return avail; | |
6030 } | |
6031 | |
5541 | 6032 #ifndef VMS |
7 | 6033 /* |
6034 * Wait "msec" msec until a character is available from file descriptor "fd". | |
3046 | 6035 * "msec" == 0 will check for characters once. |
6036 * "msec" == -1 will block until a character is available. | |
7 | 6037 * When a GUI is being used, this will not be used for input -- webb |
6038 * Or when a Linux GPM mouse event is waiting. | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6039 * Or when a clientserver message is on the queue. |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6040 * "interrupted" (if not NULL) is set to TRUE when no character is available |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6041 * but something else needs to be done. |
7 | 6042 */ |
6043 #if defined(__BEOS__) | |
6044 int | |
6045 #else | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6046 static int |
7 | 6047 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6048 RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted) |
7 | 6049 { |
6050 int ret; | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6051 int result; |
14 | 6052 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) |
7 | 6053 static int busy = FALSE; |
6054 | |
6055 /* May retry getting characters after an event was handled. */ | |
6056 # define MAY_LOOP | |
6057 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6058 # ifdef ELAPSED_FUNC |
7 | 6059 /* Remember at what time we started, so that we know how much longer we |
6060 * should wait after being interrupted. */ | |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
6061 long start_msec = msec; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6062 ELAPSED_TYPE start_tv; |
7 | 6063 |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
6064 if (msec > 0) |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6065 ELAPSED_INIT(start_tv); |
7 | 6066 # endif |
6067 | |
6068 /* Handle being called recursively. This may happen for the session | |
6069 * manager stuff, it may save the file, which does a breakcheck. */ | |
6070 if (busy) | |
6071 return 0; | |
6072 #endif | |
6073 | |
6074 #ifdef MAY_LOOP | |
407 | 6075 for (;;) |
7 | 6076 #endif |
6077 { | |
6078 #ifdef MAY_LOOP | |
6079 int finished = TRUE; /* default is to 'loop' just once */ | |
14 | 6080 # ifdef FEAT_MZSCHEME |
6081 int mzquantum_used = FALSE; | |
6082 # endif | |
7 | 6083 #endif |
6084 #ifndef HAVE_SELECT | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6085 /* each channel may use in, out and err */ |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6086 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; |
7 | 6087 int nfd; |
6088 # ifdef FEAT_XCLIPBOARD | |
6089 int xterm_idx = -1; | |
6090 # endif | |
6091 # ifdef FEAT_MOUSE_GPM | |
6092 int gpm_idx = -1; | |
6093 # endif | |
6094 # ifdef USE_XSMP | |
6095 int xsmp_idx = -1; | |
6096 # endif | |
14 | 6097 int towait = (int)msec; |
6098 | |
6099 # ifdef FEAT_MZSCHEME | |
6100 mzvim_check_threads(); | |
6101 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
6102 { | |
6103 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ | |
6104 mzquantum_used = TRUE; | |
6105 } | |
6106 # endif | |
7 | 6107 fds[0].fd = fd; |
6108 fds[0].events = POLLIN; | |
6109 nfd = 1; | |
6110 | |
6111 # ifdef FEAT_XCLIPBOARD | |
6383 | 6112 may_restore_clipboard(); |
7 | 6113 if (xterm_Shell != (Widget)0) |
6114 { | |
6115 xterm_idx = nfd; | |
6116 fds[nfd].fd = ConnectionNumber(xterm_dpy); | |
6117 fds[nfd].events = POLLIN; | |
6118 nfd++; | |
6119 } | |
6120 # endif | |
6121 # ifdef FEAT_MOUSE_GPM | |
6122 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
6123 { | |
6124 gpm_idx = nfd; | |
6125 fds[nfd].fd = gpm_fd; | |
6126 fds[nfd].events = POLLIN; | |
6127 nfd++; | |
6128 } | |
6129 # endif | |
6130 # ifdef USE_XSMP | |
6131 if (xsmp_icefd != -1) | |
6132 { | |
6133 xsmp_idx = nfd; | |
6134 fds[nfd].fd = xsmp_icefd; | |
6135 fds[nfd].events = POLLIN; | |
6136 nfd++; | |
6137 } | |
6138 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6139 #ifdef FEAT_JOB_CHANNEL |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
6140 nfd = channel_poll_setup(nfd, &fds, &towait); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
6141 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6142 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6143 *interrupted = FALSE; |
7 | 6144 |
14 | 6145 ret = poll(fds, nfd, towait); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6146 |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6147 result = ret > 0 && (fds[0].revents & POLLIN); |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6148 if (result == 0 && interrupted != NULL && ret > 0) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6149 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6150 |
14 | 6151 # ifdef FEAT_MZSCHEME |
6152 if (ret == 0 && mzquantum_used) | |
1450 | 6153 /* MzThreads scheduling is required and timeout occurred */ |
14 | 6154 finished = FALSE; |
6155 # endif | |
7 | 6156 |
6157 # ifdef FEAT_XCLIPBOARD | |
6158 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) | |
6159 { | |
6160 xterm_update(); /* Maybe we should hand out clipboard */ | |
6161 if (--ret == 0 && !input_available()) | |
6162 /* Try again */ | |
6163 finished = FALSE; | |
6164 } | |
6165 # endif | |
6166 # ifdef FEAT_MOUSE_GPM | |
6167 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN)) | |
6168 { | |
6169 *check_for_gpm = 1; | |
6170 } | |
6171 # endif | |
6172 # ifdef USE_XSMP | |
6173 if (xsmp_idx >= 0 && (fds[xsmp_idx].revents & (POLLIN | POLLHUP))) | |
6174 { | |
6175 if (fds[xsmp_idx].revents & POLLIN) | |
6176 { | |
6177 busy = TRUE; | |
6178 xsmp_handle_requests(); | |
6179 busy = FALSE; | |
6180 } | |
6181 else if (fds[xsmp_idx].revents & POLLHUP) | |
6182 { | |
6183 if (p_verbose > 0) | |
292 | 6184 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 6185 xsmp_close(); |
6186 } | |
6187 if (--ret == 0) | |
14 | 6188 finished = FALSE; /* Try again */ |
7 | 6189 } |
6190 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6191 #ifdef FEAT_JOB_CHANNEL |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
6192 /* also call when ret == 0, we may be polling a keep-open channel */ |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
6193 if (ret >= 0) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
6194 ret = channel_poll_check(ret, &fds); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
6195 #endif |
7 | 6196 |
6197 #else /* HAVE_SELECT */ | |
6198 | |
6199 struct timeval tv; | |
14 | 6200 struct timeval *tvp; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6201 fd_set rfds, wfds, efds; |
7 | 6202 int maxfd; |
14 | 6203 long towait = msec; |
6204 | |
6205 # ifdef FEAT_MZSCHEME | |
6206 mzvim_check_threads(); | |
6207 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
6208 { | |
6209 towait = p_mzq; /* don't wait longer than 'mzquantum' */ | |
6210 mzquantum_used = TRUE; | |
6211 } | |
6212 # endif | |
7 | 6213 |
14 | 6214 if (towait >= 0) |
7 | 6215 { |
14 | 6216 tv.tv_sec = towait / 1000; |
6217 tv.tv_usec = (towait % 1000) * (1000000/1000); | |
6218 tvp = &tv; | |
7 | 6219 } |
14 | 6220 else |
6221 tvp = NULL; | |
7 | 6222 |
6223 /* | |
6224 * Select on ready for reading and exceptional condition (end of file). | |
6225 */ | |
3046 | 6226 select_eintr: |
6227 FD_ZERO(&rfds); | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6228 FD_ZERO(&wfds); |
7 | 6229 FD_ZERO(&efds); |
6230 FD_SET(fd, &rfds); | |
6231 # if !defined(__QNX__) && !defined(__CYGWIN32__) | |
6232 /* For QNX select() always returns 1 if this is set. Why? */ | |
6233 FD_SET(fd, &efds); | |
6234 # endif | |
6235 maxfd = fd; | |
6236 | |
6237 # ifdef FEAT_XCLIPBOARD | |
6383 | 6238 may_restore_clipboard(); |
7 | 6239 if (xterm_Shell != (Widget)0) |
6240 { | |
6241 FD_SET(ConnectionNumber(xterm_dpy), &rfds); | |
6242 if (maxfd < ConnectionNumber(xterm_dpy)) | |
6243 maxfd = ConnectionNumber(xterm_dpy); | |
3748 | 6244 |
6245 /* An event may have already been read but not handled. In | |
6246 * particulary, XFlush may cause this. */ | |
6247 xterm_update(); | |
7 | 6248 } |
6249 # endif | |
6250 # ifdef FEAT_MOUSE_GPM | |
6251 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
6252 { | |
6253 FD_SET(gpm_fd, &rfds); | |
6254 FD_SET(gpm_fd, &efds); | |
6255 if (maxfd < gpm_fd) | |
6256 maxfd = gpm_fd; | |
6257 } | |
6258 # endif | |
6259 # ifdef USE_XSMP | |
6260 if (xsmp_icefd != -1) | |
6261 { | |
6262 FD_SET(xsmp_icefd, &rfds); | |
6263 FD_SET(xsmp_icefd, &efds); | |
6264 if (maxfd < xsmp_icefd) | |
6265 maxfd = xsmp_icefd; | |
6266 } | |
6267 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6268 # ifdef FEAT_JOB_CHANNEL |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
6269 maxfd = channel_select_setup(maxfd, &rfds, &wfds, &tv, &tvp); |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6270 # endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6271 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6272 *interrupted = FALSE; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6273 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6274 ret = select(maxfd + 1, &rfds, &wfds, &efds, tvp); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6275 result = ret > 0 && FD_ISSET(fd, &rfds); |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6276 if (result) |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6277 --ret; |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6278 else if (interrupted != NULL && ret > 0) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6279 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6280 |
3046 | 6281 # ifdef EINTR |
6282 if (ret == -1 && errno == EINTR) | |
3133 | 6283 { |
6284 /* Check whether window has been resized, EINTR may be caused by | |
6285 * SIGWINCH. */ | |
6286 if (do_resize) | |
6287 handle_resize(); | |
6288 | |
3046 | 6289 /* Interrupted by a signal, need to try again. We ignore msec |
6290 * here, because we do want to check even after a timeout if | |
6291 * characters are available. Needed for reading output of an | |
6292 * external command after the process has finished. */ | |
6293 goto select_eintr; | |
3133 | 6294 } |
3046 | 6295 # endif |
1076 | 6296 # ifdef __TANDEM |
6297 if (ret == -1 && errno == ENOTSUP) | |
6298 { | |
6299 FD_ZERO(&rfds); | |
6300 FD_ZERO(&efds); | |
6301 ret = 0; | |
6302 } | |
3046 | 6303 # endif |
14 | 6304 # ifdef FEAT_MZSCHEME |
6305 if (ret == 0 && mzquantum_used) | |
1450 | 6306 /* loop if MzThreads must be scheduled and timeout occurred */ |
14 | 6307 finished = FALSE; |
7 | 6308 # endif |
6309 | |
6310 # ifdef FEAT_XCLIPBOARD | |
6311 if (ret > 0 && xterm_Shell != (Widget)0 | |
6312 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) | |
6313 { | |
6314 xterm_update(); /* Maybe we should hand out clipboard */ | |
6315 /* continue looping when we only got the X event and the input | |
6316 * buffer is empty */ | |
6317 if (--ret == 0 && !input_available()) | |
6318 { | |
6319 /* Try again */ | |
6320 finished = FALSE; | |
6321 } | |
6322 } | |
6323 # endif | |
6324 # ifdef FEAT_MOUSE_GPM | |
6325 if (ret > 0 && gpm_flag && check_for_gpm != NULL && gpm_fd >= 0) | |
6326 { | |
6327 if (FD_ISSET(gpm_fd, &efds)) | |
6328 gpm_close(); | |
6329 else if (FD_ISSET(gpm_fd, &rfds)) | |
6330 *check_for_gpm = 1; | |
6331 } | |
6332 # endif | |
6333 # ifdef USE_XSMP | |
6334 if (ret > 0 && xsmp_icefd != -1) | |
6335 { | |
6336 if (FD_ISSET(xsmp_icefd, &efds)) | |
6337 { | |
6338 if (p_verbose > 0) | |
292 | 6339 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 6340 xsmp_close(); |
6341 if (--ret == 0) | |
6342 finished = FALSE; /* keep going if event was only one */ | |
6343 } | |
6344 else if (FD_ISSET(xsmp_icefd, &rfds)) | |
6345 { | |
6346 busy = TRUE; | |
6347 xsmp_handle_requests(); | |
6348 busy = FALSE; | |
6349 if (--ret == 0) | |
6350 finished = FALSE; /* keep going if event was only one */ | |
6351 } | |
6352 } | |
6353 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6354 #ifdef FEAT_JOB_CHANNEL |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
6355 /* also call when ret == 0, we may be polling a keep-open channel */ |
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
6356 if (ret >= 0) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6357 ret = channel_select_check(ret, &rfds, &wfds); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
6358 #endif |
7 | 6359 |
6360 #endif /* HAVE_SELECT */ | |
6361 | |
6362 #ifdef MAY_LOOP | |
6363 if (finished || msec == 0) | |
6364 break; | |
6365 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6366 # ifdef FEAT_CLIENTSERVER |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6367 if (server_waiting()) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6368 break; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6369 # endif |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6370 |
7 | 6371 /* We're going to loop around again, find out for how long */ |
6372 if (msec > 0) | |
6373 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6374 # ifdef ELAPSED_FUNC |
7 | 6375 /* Compute remaining wait time. */ |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6376 msec = start_msec - ELAPSED_FUNC(start_tv); |
7 | 6377 # else |
6378 /* Guess we got interrupted halfway. */ | |
6379 msec = msec / 2; | |
6380 # endif | |
6381 if (msec <= 0) | |
6382 break; /* waited long enough */ | |
6383 } | |
6384 #endif | |
6385 } | |
6386 | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6387 return result; |
7 | 6388 } |
6389 | |
6390 #ifndef NO_EXPANDPATH | |
6391 /* | |
444 | 6392 * Expand a path into all matching files and/or directories. Handles "*", |
6393 * "?", "[a-z]", "**", etc. | |
6394 * "path" has backslashes before chars that are not to be expanded. | |
6395 * Returns the number of matches found. | |
7 | 6396 */ |
6397 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6398 mch_expandpath( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6399 garray_T *gap, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6400 char_u *path, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6401 int flags) /* EW_* flags */ |
7 | 6402 { |
444 | 6403 return unix_expandpath(gap, path, 0, flags, FALSE); |
7 | 6404 } |
6405 #endif | |
6406 | |
6407 /* | |
6408 * mch_expand_wildcards() - this code does wild-card pattern matching using | |
6409 * the shell | |
6410 * | |
6411 * return OK for success, FAIL for error (you may lose some memory) and put | |
6412 * an error message in *file. | |
6413 * | |
6414 * num_pat is number of input patterns | |
6415 * pat is array of pointers to input patterns | |
6416 * num_file is pointer to number of matched file names | |
6417 * file is pointer to array of pointers to matched file names | |
6418 */ | |
6419 | |
6420 #ifndef SEEK_SET | |
6421 # define SEEK_SET 0 | |
6422 #endif | |
6423 #ifndef SEEK_END | |
6424 # define SEEK_END 2 | |
6425 #endif | |
6426 | |
822 | 6427 #define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
628 | 6428 |
7 | 6429 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6430 mch_expand_wildcards( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6431 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6432 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6433 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6434 char_u ***file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6435 int flags) /* EW_* flags */ |
7 | 6436 { |
6437 int i; | |
6438 size_t len; | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6439 long llen; |
7 | 6440 char_u *p; |
6441 int dir; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
6442 |
1508 | 6443 /* |
6444 * This is the non-OS/2 implementation (really Unix). | |
6445 */ | |
7 | 6446 int j; |
6447 char_u *tempname; | |
6448 char_u *command; | |
6449 FILE *fd; | |
6450 char_u *buffer; | |
1508 | 6451 #define STYLE_ECHO 0 /* use "echo", the default */ |
6452 #define STYLE_GLOB 1 /* use "glob", for csh */ | |
6453 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
6454 #define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
6455 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
6456 * directly */ | |
7 | 6457 int shell_style = STYLE_ECHO; |
6458 int check_spaces; | |
6459 static int did_find_nul = FALSE; | |
6460 int ampersent = FALSE; | |
1508 | 6461 /* vimglob() function to define for Posix shell */ |
1620 | 6462 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; |
7 | 6463 |
6464 *num_file = 0; /* default: no files found */ | |
6465 *file = NULL; | |
6466 | |
6467 /* | |
6468 * If there are no wildcards, just copy the names to allocated memory. | |
6469 * Saves a lot of time, because we don't have to start a new shell. | |
6470 */ | |
6471 if (!have_wildcard(num_pat, pat)) | |
6472 return save_patterns(num_pat, pat, num_file, file); | |
6473 | |
428 | 6474 # ifdef HAVE_SANDBOX |
6475 /* Don't allow any shell command in the sandbox. */ | |
6476 if (sandbox != 0 && check_secure()) | |
6477 return FAIL; | |
6478 # endif | |
6479 | |
7 | 6480 /* |
6481 * Don't allow the use of backticks in secure and restricted mode. | |
6482 */ | |
428 | 6483 if (secure || restricted) |
7 | 6484 for (i = 0; i < num_pat; ++i) |
6485 if (vim_strchr(pat[i], '`') != NULL | |
6486 && (check_restricted() || check_secure())) | |
6487 return FAIL; | |
6488 | |
6489 /* | |
6490 * get a name for the temp file | |
6491 */ | |
6721 | 6492 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 6493 { |
6494 EMSG(_(e_notmp)); | |
6495 return FAIL; | |
6496 } | |
6497 | |
6498 /* | |
6499 * Let the shell expand the patterns and write the result into the temp | |
1508 | 6500 * file. |
6501 * STYLE_BT: NL separated | |
6502 * If expanding `cmd` execute it directly. | |
6503 * STYLE_GLOB: NUL separated | |
6504 * If we use *csh, "glob" will work better than "echo". | |
6505 * STYLE_PRINT: NL or NUL separated | |
6506 * If we use *zsh, "print -N" will work better than "glob". | |
6507 * STYLE_VIMGLOB: NL separated | |
6508 * If we use *sh*, we define "vimglob()". | |
6509 * STYLE_ECHO: space separated. | |
6510 * A shell we don't know, stay safe and use "echo". | |
7 | 6511 */ |
6512 if (num_pat == 1 && *pat[0] == '`' | |
6513 && (len = STRLEN(pat[0])) > 2 | |
6514 && *(pat[0] + len - 1) == '`') | |
6515 shell_style = STYLE_BT; | |
6516 else if ((len = STRLEN(p_sh)) >= 3) | |
6517 { | |
6518 if (STRCMP(p_sh + len - 3, "csh") == 0) | |
6519 shell_style = STYLE_GLOB; | |
6520 else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
6521 shell_style = STYLE_PRINT; | |
6522 } | |
1508 | 6523 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), |
6524 "sh") != NULL) | |
6525 shell_style = STYLE_VIMGLOB; | |
6526 | |
6527 /* Compute the length of the command. We need 2 extra bytes: for the | |
6528 * optional '&' and for the NUL. | |
6529 * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
7 | 6530 len = STRLEN(tempname) + 29; |
1508 | 6531 if (shell_style == STYLE_VIMGLOB) |
6532 len += STRLEN(sh_vimglob_func); | |
6533 | |
147 | 6534 for (i = 0; i < num_pat; ++i) |
6535 { | |
6536 /* Count the length of the patterns in the same way as they are put in | |
6537 * "command" below. */ | |
6538 #ifdef USE_SYSTEM | |
7 | 6539 len += STRLEN(pat[i]) + 3; /* add space and two quotes */ |
147 | 6540 #else |
6541 ++len; /* add space */ | |
628 | 6542 for (j = 0; pat[i][j] != NUL; ++j) |
6543 { | |
6544 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
6545 ++len; /* may add a backslash */ | |
6546 ++len; | |
6547 } | |
147 | 6548 #endif |
6549 } | |
7 | 6550 command = alloc(len); |
6551 if (command == NULL) | |
6552 { | |
6553 /* out of memory */ | |
6554 vim_free(tempname); | |
6555 return FAIL; | |
6556 } | |
6557 | |
6558 /* | |
6559 * Build the shell command: | |
6560 * - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell | |
6561 * recognizes this). | |
6562 * - Add the shell command to print the expanded names. | |
6563 * - Add the temp file name. | |
6564 * - Add the file name patterns. | |
6565 */ | |
6566 if (shell_style == STYLE_BT) | |
6567 { | |
628 | 6568 /* change `command; command& ` to (command; command ) */ |
6569 STRCPY(command, "("); | |
6570 STRCAT(command, pat[0] + 1); /* exclude first backtick */ | |
7 | 6571 p = command + STRLEN(command) - 1; |
628 | 6572 *p-- = ')'; /* remove last backtick */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6573 while (p > command && VIM_ISWHITE(*p)) |
7 | 6574 --p; |
6575 if (*p == '&') /* remove trailing '&' */ | |
6576 { | |
6577 ampersent = TRUE; | |
6578 *p = ' '; | |
6579 } | |
6580 STRCAT(command, ">"); | |
6581 } | |
6582 else | |
6583 { | |
6584 if (flags & EW_NOTFOUND) | |
6585 STRCPY(command, "set nonomatch; "); | |
6586 else | |
6587 STRCPY(command, "unset nonomatch; "); | |
6588 if (shell_style == STYLE_GLOB) | |
6589 STRCAT(command, "glob >"); | |
6590 else if (shell_style == STYLE_PRINT) | |
6591 STRCAT(command, "print -N >"); | |
1508 | 6592 else if (shell_style == STYLE_VIMGLOB) |
6593 STRCAT(command, sh_vimglob_func); | |
7 | 6594 else |
6595 STRCAT(command, "echo >"); | |
6596 } | |
1508 | 6597 |
7 | 6598 STRCAT(command, tempname); |
1508 | 6599 |
7 | 6600 if (shell_style != STYLE_BT) |
6601 for (i = 0; i < num_pat; ++i) | |
6602 { | |
6603 /* When using system() always add extra quotes, because the shell | |
628 | 6604 * is started twice. Otherwise put a backslash before special |
1450 | 6605 * characters, except inside ``. */ |
7 | 6606 #ifdef USE_SYSTEM |
6607 STRCAT(command, " \""); | |
6608 STRCAT(command, pat[i]); | |
6609 STRCAT(command, "\""); | |
6610 #else | |
233 | 6611 int intick = FALSE; |
6612 | |
7 | 6613 p = command + STRLEN(command); |
6614 *p++ = ' '; | |
628 | 6615 for (j = 0; pat[i][j] != NUL; ++j) |
233 | 6616 { |
6617 if (pat[i][j] == '`') | |
6618 intick = !intick; | |
628 | 6619 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) |
6620 { | |
644 | 6621 /* Remove a backslash, take char literally. But keep |
652 | 6622 * backslash inside backticks, before a special character |
6623 * and before a backtick. */ | |
644 | 6624 if (intick |
652 | 6625 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL |
6626 || pat[i][j + 1] == '`') | |
644 | 6627 *p++ = '\\'; |
648 | 6628 ++j; |
628 | 6629 } |
6174 | 6630 else if (!intick |
6631 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') | |
6632 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
628 | 6633 /* Put a backslash before a special character, but not |
6174 | 6634 * when inside ``. And not for $var when EW_KEEPDOLLAR is |
6635 * set. */ | |
628 | 6636 *p++ = '\\'; |
648 | 6637 |
6638 /* Copy one character. */ | |
6639 *p++ = pat[i][j]; | |
233 | 6640 } |
7 | 6641 *p = NUL; |
6642 #endif | |
6643 } | |
6644 if (flags & EW_SILENT) | |
6645 show_shell_mess = FALSE; | |
6646 if (ampersent) | |
1508 | 6647 STRCAT(command, "&"); /* put the '&' after the redirection */ |
7 | 6648 |
6649 /* | |
6650 * Using zsh -G: If a pattern has no matches, it is just deleted from | |
6651 * the argument list, otherwise zsh gives an error message and doesn't | |
6652 * expand any other pattern. | |
6653 */ | |
6654 if (shell_style == STYLE_PRINT) | |
6655 extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ | |
6656 | |
6657 /* | |
6658 * If we use -f then shell variables set in .cshrc won't get expanded. | |
6659 * vi can do it, so we will too, but it is only necessary if there is a "$" | |
6660 * in one of the patterns, otherwise we can still use the fast option. | |
6661 */ | |
6662 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) | |
6663 extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ | |
6664 | |
6665 /* | |
6666 * execute the shell command | |
6667 */ | |
6668 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); | |
6669 | |
6670 /* When running in the background, give it some time to create the temp | |
6671 * file, but don't wait for it to finish. */ | |
6672 if (ampersent) | |
6673 mch_delay(10L, TRUE); | |
6674 | |
6675 extra_shell_arg = NULL; /* cleanup */ | |
6676 show_shell_mess = TRUE; | |
6677 vim_free(command); | |
6678 | |
1508 | 6679 if (i != 0) /* mch_call_shell() failed */ |
7 | 6680 { |
6681 mch_remove(tempname); | |
6682 vim_free(tempname); | |
6683 /* | |
6684 * With interactive completion, the error message is not printed. | |
6685 * However with USE_SYSTEM, I don't know how to turn off error messages | |
6686 * from the shell, so screen may still get messed up -- webb. | |
6687 */ | |
6688 #ifndef USE_SYSTEM | |
6689 if (!(flags & EW_SILENT)) | |
6690 #endif | |
6691 { | |
6692 redraw_later_clear(); /* probably messed up screen */ | |
6693 msg_putchar('\n'); /* clear bottom line quickly */ | |
6694 cmdline_row = Rows - 1; /* continue on last line */ | |
6695 #ifdef USE_SYSTEM | |
6696 if (!(flags & EW_SILENT)) | |
6697 #endif | |
6698 { | |
6699 MSG(_(e_wildexpand)); | |
6700 msg_start(); /* don't overwrite this message */ | |
6701 } | |
6702 } | |
6703 /* If a `cmd` expansion failed, don't list `cmd` as a match, even when | |
6704 * EW_NOTFOUND is given */ | |
6705 if (shell_style == STYLE_BT) | |
6706 return FAIL; | |
6707 goto notfound; | |
6708 } | |
6709 | |
6710 /* | |
6711 * read the names from the file into memory | |
6712 */ | |
6713 fd = fopen((char *)tempname, READBIN); | |
6714 if (fd == NULL) | |
6715 { | |
6716 /* Something went wrong, perhaps a file name with a special char. */ | |
6717 if (!(flags & EW_SILENT)) | |
6718 { | |
6719 MSG(_(e_wildexpand)); | |
6720 msg_start(); /* don't overwrite this message */ | |
6721 } | |
6722 vim_free(tempname); | |
6723 goto notfound; | |
6724 } | |
6725 fseek(fd, 0L, SEEK_END); | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6726 llen = ftell(fd); /* get size of temp file */ |
7 | 6727 fseek(fd, 0L, SEEK_SET); |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6728 if (llen < 0) |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6729 /* just in case ftell() would fail */ |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6730 buffer = NULL; |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6731 else |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6732 buffer = alloc(llen + 1); |
7 | 6733 if (buffer == NULL) |
6734 { | |
6735 /* out of memory */ | |
6736 mch_remove(tempname); | |
6737 vim_free(tempname); | |
6738 fclose(fd); | |
6739 return FAIL; | |
6740 } | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6741 len = llen; |
7 | 6742 i = fread((char *)buffer, 1, len, fd); |
6743 fclose(fd); | |
6744 mch_remove(tempname); | |
1877 | 6745 if (i != (int)len) |
7 | 6746 { |
6747 /* unexpected read error */ | |
6748 EMSG2(_(e_notread), tempname); | |
6749 vim_free(tempname); | |
6750 vim_free(buffer); | |
6751 return FAIL; | |
6752 } | |
6753 vim_free(tempname); | |
6754 | |
1508 | 6755 # if defined(__CYGWIN__) || defined(__CYGWIN32__) |
7 | 6756 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ |
6757 p = buffer; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
6758 for (i = 0; i < (int)len; ++i) |
7 | 6759 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) |
6760 *p++ = buffer[i]; | |
6761 len = p - buffer; | |
6762 # endif | |
6763 | |
6764 | |
6765 /* file names are separated with Space */ | |
6766 if (shell_style == STYLE_ECHO) | |
6767 { | |
6768 buffer[len] = '\n'; /* make sure the buffer ends in NL */ | |
6769 p = buffer; | |
6770 for (i = 0; *p != '\n'; ++i) /* count number of entries */ | |
6771 { | |
6772 while (*p != ' ' && *p != '\n') | |
6773 ++p; | |
6774 p = skipwhite(p); /* skip to next entry */ | |
6775 } | |
6776 } | |
6777 /* file names are separated with NL */ | |
1508 | 6778 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) |
7 | 6779 { |
6780 buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
6781 p = buffer; | |
6782 for (i = 0; *p != NUL; ++i) /* count number of entries */ | |
6783 { | |
6784 while (*p != '\n' && *p != NUL) | |
6785 ++p; | |
6786 if (*p != NUL) | |
6787 ++p; | |
6788 p = skipwhite(p); /* skip leading white space */ | |
6789 } | |
6790 } | |
6791 /* file names are separated with NUL */ | |
6792 else | |
6793 { | |
6794 /* | |
6795 * Some versions of zsh use spaces instead of NULs to separate | |
6796 * results. Only do this when there is no NUL before the end of the | |
6797 * buffer, otherwise we would never be able to use file names with | |
6798 * embedded spaces when zsh does use NULs. | |
6799 * When we found a NUL once, we know zsh is OK, set did_find_nul and | |
6800 * don't check for spaces again. | |
6801 */ | |
6802 check_spaces = FALSE; | |
6803 if (shell_style == STYLE_PRINT && !did_find_nul) | |
6804 { | |
6805 /* If there is a NUL, set did_find_nul, else set check_spaces */ | |
2768 | 6806 buffer[len] = NUL; |
5533 | 6807 if (len && (int)STRLEN(buffer) < (int)len) |
7 | 6808 did_find_nul = TRUE; |
6809 else | |
6810 check_spaces = TRUE; | |
6811 } | |
6812 | |
6813 /* | |
6814 * Make sure the buffer ends with a NUL. For STYLE_PRINT there | |
6815 * already is one, for STYLE_GLOB it needs to be added. | |
6816 */ | |
6817 if (len && buffer[len - 1] == NUL) | |
6818 --len; | |
6819 else | |
6820 buffer[len] = NUL; | |
6821 i = 0; | |
6822 for (p = buffer; p < buffer + len; ++p) | |
6823 if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ | |
6824 { | |
6825 ++i; | |
6826 *p = NUL; | |
6827 } | |
6828 if (len) | |
6829 ++i; /* count last entry */ | |
6830 } | |
6831 if (i == 0) | |
6832 { | |
6833 /* | |
6834 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I". | |
6835 * /bin/sh will happily expand it to nothing rather than returning an | |
6836 * error; and hey, it's good to check anyway -- webb. | |
6837 */ | |
6838 vim_free(buffer); | |
6839 goto notfound; | |
6840 } | |
6841 *num_file = i; | |
6842 *file = (char_u **)alloc(sizeof(char_u *) * i); | |
6843 if (*file == NULL) | |
6844 { | |
6845 /* out of memory */ | |
6846 vim_free(buffer); | |
6847 return FAIL; | |
6848 } | |
6849 | |
6850 /* | |
6851 * Isolate the individual file names. | |
6852 */ | |
6853 p = buffer; | |
6854 for (i = 0; i < *num_file; ++i) | |
6855 { | |
6856 (*file)[i] = p; | |
6857 /* Space or NL separates */ | |
1508 | 6858 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT |
6859 || shell_style == STYLE_VIMGLOB) | |
7 | 6860 { |
652 | 6861 while (!(shell_style == STYLE_ECHO && *p == ' ') |
6862 && *p != '\n' && *p != NUL) | |
7 | 6863 ++p; |
6864 if (p == buffer + len) /* last entry */ | |
6865 *p = NUL; | |
6866 else | |
6867 { | |
6868 *p++ = NUL; | |
6869 p = skipwhite(p); /* skip to next entry */ | |
6870 } | |
6871 } | |
6872 else /* NUL separates */ | |
6873 { | |
6874 while (*p && p < buffer + len) /* skip entry */ | |
6875 ++p; | |
6876 ++p; /* skip NUL */ | |
6877 } | |
6878 } | |
6879 | |
6880 /* | |
6881 * Move the file names to allocated memory. | |
6882 */ | |
6883 for (j = 0, i = 0; i < *num_file; ++i) | |
6884 { | |
6885 /* Require the files to exist. Helps when using /bin/sh */ | |
6886 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) | |
6887 continue; | |
6888 | |
6889 /* check if this entry should be included */ | |
6890 dir = (mch_isdir((*file)[i])); | |
6891 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) | |
6892 continue; | |
6893 | |
715 | 6894 /* Skip files that are not executable if we check for that. */ |
6695 | 6895 if (!dir && (flags & EW_EXEC) |
6896 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) | |
715 | 6897 continue; |
6898 | |
7 | 6899 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); |
6900 if (p) | |
6901 { | |
6902 STRCPY(p, (*file)[i]); | |
6903 if (dir) | |
1479 | 6904 add_pathsep(p); /* add '/' to a directory name */ |
7 | 6905 (*file)[j++] = p; |
6906 } | |
6907 } | |
6908 vim_free(buffer); | |
6909 *num_file = j; | |
6910 | |
6911 if (*num_file == 0) /* rejected all entries */ | |
6912 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
6913 VIM_CLEAR(*file); |
7 | 6914 goto notfound; |
6915 } | |
6916 | |
6917 return OK; | |
6918 | |
6919 notfound: | |
6920 if (flags & EW_NOTFOUND) | |
6921 return save_patterns(num_pat, pat, num_file, file); | |
6922 return FAIL; | |
6923 } | |
6924 | |
6925 #endif /* VMS */ | |
6926 | |
6927 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6928 save_patterns( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6929 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6930 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6931 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6932 char_u ***file) |
7 | 6933 { |
6934 int i; | |
99 | 6935 char_u *s; |
7 | 6936 |
6937 *file = (char_u **)alloc(num_pat * sizeof(char_u *)); | |
6938 if (*file == NULL) | |
6939 return FAIL; | |
6940 for (i = 0; i < num_pat; i++) | |
99 | 6941 { |
6942 s = vim_strsave(pat[i]); | |
6943 if (s != NULL) | |
6944 /* Be compatible with expand_filename(): halve the number of | |
6945 * backslashes. */ | |
6946 backslash_halve(s); | |
6947 (*file)[i] = s; | |
6948 } | |
7 | 6949 *num_file = num_pat; |
6950 return OK; | |
6951 } | |
6952 | |
6953 /* | |
6954 * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can | |
6955 * expand. | |
6956 */ | |
6957 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6958 mch_has_exp_wildcard(char_u *p) |
7 | 6959 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
6960 for ( ; *p; MB_PTR_ADV(p)) |
7 | 6961 { |
6962 if (*p == '\\' && p[1] != NUL) | |
6963 ++p; | |
6964 else | |
6965 if (vim_strchr((char_u *) | |
6966 #ifdef VMS | |
6967 "*?%" | |
6968 #else | |
6969 "*?[{'" | |
6970 #endif | |
6971 , *p) != NULL) | |
6972 return TRUE; | |
6973 } | |
6974 return FALSE; | |
6975 } | |
6976 | |
6977 /* | |
6978 * Return TRUE if the string "p" contains a wildcard. | |
6979 * Don't recognize '~' at the end as a wildcard. | |
6980 */ | |
6981 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6982 mch_has_wildcard(char_u *p) |
7 | 6983 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
6984 for ( ; *p; MB_PTR_ADV(p)) |
7 | 6985 { |
6986 if (*p == '\\' && p[1] != NUL) | |
6987 ++p; | |
6988 else | |
6989 if (vim_strchr((char_u *) | |
6990 #ifdef VMS | |
6991 "*?%$" | |
6992 #else | |
6993 "*?[{`'$" | |
6994 #endif | |
6995 , *p) != NULL | |
6996 || (*p == '~' && p[1] != NUL)) | |
6997 return TRUE; | |
6998 } | |
6999 return FALSE; | |
7000 } | |
7001 | |
7002 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7003 have_wildcard(int num, char_u **file) |
7 | 7004 { |
7005 int i; | |
7006 | |
7007 for (i = 0; i < num; i++) | |
7008 if (mch_has_wildcard(file[i])) | |
7009 return 1; | |
7010 return 0; | |
7011 } | |
7012 | |
7013 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7014 have_dollars(int num, char_u **file) |
7 | 7015 { |
7016 int i; | |
7017 | |
7018 for (i = 0; i < num; i++) | |
7019 if (vim_strchr(file[i], '$') != NULL) | |
7020 return TRUE; | |
7021 return FALSE; | |
7022 } | |
7023 | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7024 #if !defined(HAVE_RENAME) || defined(PROTO) |
7 | 7025 /* |
7026 * Scaled-down version of rename(), which is missing in Xenix. | |
7027 * This version can only move regular files and will fail if the | |
7028 * destination exists. | |
7029 */ | |
7030 int | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7031 mch_rename(const char *src, const char *dest) |
7 | 7032 { |
7033 struct stat st; | |
7034 | |
7035 if (stat(dest, &st) >= 0) /* fail if destination exists */ | |
7036 return -1; | |
7037 if (link(src, dest) != 0) /* link file to new name */ | |
7038 return -1; | |
7039 if (mch_remove(src) == 0) /* delete link to old name */ | |
7040 return 0; | |
7041 return -1; | |
7042 } | |
7043 #endif /* !HAVE_RENAME */ | |
7044 | |
7045 #ifdef FEAT_MOUSE_GPM | |
7046 /* | |
7047 * Initializes connection with gpm (if it isn't already opened) | |
7048 * Return 1 if succeeded (or connection already opened), 0 if failed | |
7049 */ | |
7050 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7051 gpm_open(void) |
7 | 7052 { |
7053 static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ | |
7054 | |
7055 if (!gpm_flag) | |
7056 { | |
7057 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); | |
7058 gpm_connect.defaultMask = ~GPM_HARD; | |
7059 /* Default handling for mouse move*/ | |
7060 gpm_connect.minMod = 0; /* Handle any modifier keys */ | |
7061 gpm_connect.maxMod = 0xffff; | |
7062 if (Gpm_Open(&gpm_connect, 0) > 0) | |
7063 { | |
7064 /* gpm library tries to handling TSTP causes | |
7065 * problems. Anyways, we close connection to Gpm whenever | |
7066 * we are going to suspend or starting an external process | |
1450 | 7067 * so we shouldn't have problem with this |
7 | 7068 */ |
1832 | 7069 # ifdef SIGTSTP |
7 | 7070 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); |
1832 | 7071 # endif |
7 | 7072 return 1; /* succeed */ |
7073 } | |
7074 if (gpm_fd == -2) | |
7075 Gpm_Close(); /* We don't want to talk to xterm via gpm */ | |
7076 return 0; | |
7077 } | |
7078 return 1; /* already open */ | |
7079 } | |
7080 | |
7081 /* | |
7082 * Closes connection to gpm | |
7083 */ | |
7084 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7085 gpm_close(void) |
7 | 7086 { |
7087 if (gpm_flag && gpm_fd >= 0) /* if Open */ | |
7088 Gpm_Close(); | |
7089 } | |
7090 | |
7091 /* Reads gpm event and adds special keys to input buf. Returns length of | |
7092 * generated key sequence. | |
5782 | 7093 * This function is styled after gui_send_mouse_event(). |
7 | 7094 */ |
7095 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7096 mch_gpm_process(void) |
7 | 7097 { |
7098 int button; | |
7099 static Gpm_Event gpm_event; | |
7100 char_u string[6]; | |
7101 int_u vim_modifiers; | |
7102 int row,col; | |
7103 unsigned char buttons_mask; | |
7104 unsigned char gpm_modifiers; | |
7105 static unsigned char old_buttons = 0; | |
7106 | |
7107 Gpm_GetEvent(&gpm_event); | |
7108 | |
7109 #ifdef FEAT_GUI | |
7110 /* Don't put events in the input queue now. */ | |
7111 if (hold_gui_events) | |
7112 return 0; | |
7113 #endif | |
7114 | |
7115 row = gpm_event.y - 1; | |
7116 col = gpm_event.x - 1; | |
7117 | |
7118 string[0] = ESC; /* Our termcode */ | |
7119 string[1] = 'M'; | |
7120 string[2] = 'G'; | |
7121 switch (GPM_BARE_EVENTS(gpm_event.type)) | |
7122 { | |
7123 case GPM_DRAG: | |
7124 string[3] = MOUSE_DRAG; | |
7125 break; | |
7126 case GPM_DOWN: | |
7127 buttons_mask = gpm_event.buttons & ~old_buttons; | |
7128 old_buttons = gpm_event.buttons; | |
7129 switch (buttons_mask) | |
7130 { | |
7131 case GPM_B_LEFT: | |
7132 button = MOUSE_LEFT; | |
7133 break; | |
7134 case GPM_B_MIDDLE: | |
7135 button = MOUSE_MIDDLE; | |
7136 break; | |
7137 case GPM_B_RIGHT: | |
7138 button = MOUSE_RIGHT; | |
7139 break; | |
7140 default: | |
7141 return 0; | |
7142 /*Don't know what to do. Can more than one button be | |
7143 * reported in one event? */ | |
7144 } | |
7145 string[3] = (char_u)(button | 0x20); | |
7146 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); | |
7147 break; | |
7148 case GPM_UP: | |
7149 string[3] = MOUSE_RELEASE; | |
7150 old_buttons &= ~gpm_event.buttons; | |
7151 break; | |
7152 default: | |
7153 return 0; | |
7154 } | |
7155 /*This code is based on gui_x11_mouse_cb in gui_x11.c */ | |
7156 gpm_modifiers = gpm_event.modifiers; | |
7157 vim_modifiers = 0x0; | |
7158 /* I ignore capslock stats. Aren't we all just hate capslock mixing with | |
7159 * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and | |
7160 * K_CAPSSHIFT is defined 8, so it probably isn't even reported | |
7161 */ | |
7162 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) | |
7163 vim_modifiers |= MOUSE_SHIFT; | |
7164 | |
7165 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL))) | |
7166 vim_modifiers |= MOUSE_CTRL; | |
7167 if (gpm_modifiers & ((1 << KG_ALT) | (1 << KG_ALTGR))) | |
7168 vim_modifiers |= MOUSE_ALT; | |
7169 string[3] |= vim_modifiers; | |
7170 string[4] = (char_u)(col + ' ' + 1); | |
7171 string[5] = (char_u)(row + ' ' + 1); | |
7172 add_to_input_buf(string, 6); | |
7173 return 6; | |
7174 } | |
7175 #endif /* FEAT_MOUSE_GPM */ | |
7176 | |
1620 | 7177 #ifdef FEAT_SYSMOUSE |
7178 /* | |
7179 * Initialize connection with sysmouse. | |
7180 * Let virtual console inform us with SIGUSR2 for pending sysmouse | |
7181 * output, any sysmouse output than will be processed via sig_sysmouse(). | |
7182 * Return OK if succeeded, FAIL if failed. | |
7183 */ | |
7184 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7185 sysmouse_open(void) |
1620 | 7186 { |
7187 struct mouse_info mouse; | |
7188 | |
7189 mouse.operation = MOUSE_MODE; | |
7190 mouse.u.mode.mode = 0; | |
7191 mouse.u.mode.signal = SIGUSR2; | |
7192 if (ioctl(1, CONS_MOUSECTL, &mouse) != -1) | |
7193 { | |
7194 signal(SIGUSR2, (RETSIGTYPE (*)())sig_sysmouse); | |
7195 mouse.operation = MOUSE_SHOW; | |
7196 ioctl(1, CONS_MOUSECTL, &mouse); | |
7197 return OK; | |
7198 } | |
7199 return FAIL; | |
7200 } | |
7201 | |
7202 /* | |
7203 * Stop processing SIGUSR2 signals, and also make sure that | |
7204 * virtual console do not send us any sysmouse related signal. | |
7205 */ | |
7206 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7207 sysmouse_close(void) |
1620 | 7208 { |
7209 struct mouse_info mouse; | |
7210 | |
7211 signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL); | |
7212 mouse.operation = MOUSE_MODE; | |
7213 mouse.u.mode.mode = 0; | |
7214 mouse.u.mode.signal = 0; | |
7215 ioctl(1, CONS_MOUSECTL, &mouse); | |
7216 } | |
7217 | |
7218 /* | |
7219 * Gets info from sysmouse and adds special keys to input buf. | |
7220 */ | |
7221 static RETSIGTYPE | |
7222 sig_sysmouse SIGDEFARG(sigarg) | |
7223 { | |
7224 struct mouse_info mouse; | |
7225 struct video_info video; | |
7226 char_u string[6]; | |
7227 int row, col; | |
7228 int button; | |
7229 int buttons; | |
7230 static int oldbuttons = 0; | |
7231 | |
7232 #ifdef FEAT_GUI | |
7233 /* Don't put events in the input queue now. */ | |
7234 if (hold_gui_events) | |
7235 return; | |
7236 #endif | |
7237 | |
7238 mouse.operation = MOUSE_GETINFO; | |
7239 if (ioctl(1, FBIO_GETMODE, &video.vi_mode) != -1 | |
7240 && ioctl(1, FBIO_MODEINFO, &video) != -1 | |
7241 && ioctl(1, CONS_MOUSECTL, &mouse) != -1 | |
7242 && video.vi_cheight > 0 && video.vi_cwidth > 0) | |
7243 { | |
7244 row = mouse.u.data.y / video.vi_cheight; | |
7245 col = mouse.u.data.x / video.vi_cwidth; | |
7246 buttons = mouse.u.data.buttons; | |
7247 string[0] = ESC; /* Our termcode */ | |
7248 string[1] = 'M'; | |
7249 string[2] = 'S'; | |
7250 if (oldbuttons == buttons && buttons != 0) | |
7251 { | |
7252 button = MOUSE_DRAG; | |
7253 } | |
7254 else | |
7255 { | |
7256 switch (buttons) | |
7257 { | |
7258 case 0: | |
7259 button = MOUSE_RELEASE; | |
7260 break; | |
7261 case 1: | |
7262 button = MOUSE_LEFT; | |
7263 break; | |
7264 case 2: | |
7265 button = MOUSE_MIDDLE; | |
7266 break; | |
7267 case 4: | |
7268 button = MOUSE_RIGHT; | |
7269 break; | |
7270 default: | |
7271 return; | |
7272 } | |
7273 oldbuttons = buttons; | |
7274 } | |
7275 string[3] = (char_u)(button); | |
7276 string[4] = (char_u)(col + ' ' + 1); | |
7277 string[5] = (char_u)(row + ' ' + 1); | |
7278 add_to_input_buf(string, 6); | |
7279 } | |
7280 return; | |
7281 } | |
7282 #endif /* FEAT_SYSMOUSE */ | |
7283 | |
7 | 7284 #if defined(FEAT_LIBCALL) || defined(PROTO) |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7285 typedef char_u * (*STRPROCSTR)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7286 typedef char_u * (*INTPROCSTR)(int); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7287 typedef int (*STRPROCINT)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7288 typedef int (*INTPROCINT)(int); |
7 | 7289 |
7290 /* | |
7291 * Call a DLL routine which takes either a string or int param | |
7292 * and returns an allocated string. | |
7293 */ | |
7294 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7295 mch_libcall( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7296 char_u *libname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7297 char_u *funcname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7298 char_u *argstring, /* NULL when using a argint */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7299 int argint, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7300 char_u **string_result,/* NULL when using number_result */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7301 int *number_result) |
7 | 7302 { |
7303 # if defined(USE_DLOPEN) | |
7304 void *hinstLib; | |
12 | 7305 char *dlerr = NULL; |
7 | 7306 # else |
7307 shl_t hinstLib; | |
7308 # endif | |
7309 STRPROCSTR ProcAdd; | |
7310 INTPROCSTR ProcAddI; | |
7311 char_u *retval_str = NULL; | |
7312 int retval_int = 0; | |
7313 int success = FALSE; | |
7314 | |
900 | 7315 /* |
7316 * Get a handle to the DLL module. | |
7317 */ | |
7 | 7318 # if defined(USE_DLOPEN) |
900 | 7319 /* First clear any error, it's not cleared by the dlopen() call. */ |
7320 (void)dlerror(); | |
7321 | |
7 | 7322 hinstLib = dlopen((char *)libname, RTLD_LAZY |
7323 # ifdef RTLD_LOCAL | |
7324 | RTLD_LOCAL | |
7325 # endif | |
7326 ); | |
12 | 7327 if (hinstLib == NULL) |
7328 { | |
7329 /* "dlerr" must be used before dlclose() */ | |
7330 dlerr = (char *)dlerror(); | |
7331 if (dlerr != NULL) | |
7332 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7333 } | |
7 | 7334 # else |
7335 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); | |
7336 # endif | |
7337 | |
7338 /* If the handle is valid, try to get the function address. */ | |
7339 if (hinstLib != NULL) | |
7340 { | |
7341 # ifdef HAVE_SETJMP_H | |
7342 /* | |
7343 * Catch a crash when calling the library function. For example when | |
7344 * using a number where a string pointer is expected. | |
7345 */ | |
7346 mch_startjmp(); | |
7347 if (SETJMP(lc_jump_env) != 0) | |
7348 { | |
7349 success = FALSE; | |
857 | 7350 # if defined(USE_DLOPEN) |
12 | 7351 dlerr = NULL; |
857 | 7352 # endif |
7 | 7353 mch_didjmp(); |
7354 } | |
7355 else | |
7356 # endif | |
7357 { | |
7358 retval_str = NULL; | |
7359 retval_int = 0; | |
7360 | |
7361 if (argstring != NULL) | |
7362 { | |
7363 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7364 *(void **)(&ProcAdd) = dlsym(hinstLib, (const char *)funcname); |
12 | 7365 dlerr = (char *)dlerror(); |
7 | 7366 # else |
7367 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7368 TYPE_PROCEDURE, (void *)&ProcAdd) < 0) | |
7369 ProcAdd = NULL; | |
7370 # endif | |
12 | 7371 if ((success = (ProcAdd != NULL |
7372 # if defined(USE_DLOPEN) | |
7373 && dlerr == NULL | |
7374 # endif | |
7375 ))) | |
7 | 7376 { |
7377 if (string_result == NULL) | |
7378 retval_int = ((STRPROCINT)ProcAdd)(argstring); | |
7379 else | |
7380 retval_str = (ProcAdd)(argstring); | |
7381 } | |
7382 } | |
7383 else | |
7384 { | |
7385 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7386 *(void **)(&ProcAddI) = dlsym(hinstLib, (const char *)funcname); |
12 | 7387 dlerr = (char *)dlerror(); |
7 | 7388 # else |
7389 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7390 TYPE_PROCEDURE, (void *)&ProcAddI) < 0) | |
7391 ProcAddI = NULL; | |
7392 # endif | |
12 | 7393 if ((success = (ProcAddI != NULL |
7394 # if defined(USE_DLOPEN) | |
7395 && dlerr == NULL | |
7396 # endif | |
7397 ))) | |
7 | 7398 { |
7399 if (string_result == NULL) | |
7400 retval_int = ((INTPROCINT)ProcAddI)(argint); | |
7401 else | |
7402 retval_str = (ProcAddI)(argint); | |
7403 } | |
7404 } | |
7405 | |
7406 /* Save the string before we free the library. */ | |
7407 /* Assume that a "1" or "-1" result is an illegal pointer. */ | |
7408 if (string_result == NULL) | |
7409 *number_result = retval_int; | |
7410 else if (retval_str != NULL | |
7411 && retval_str != (char_u *)1 | |
7412 && retval_str != (char_u *)-1) | |
7413 *string_result = vim_strsave(retval_str); | |
7414 } | |
7415 | |
7416 # ifdef HAVE_SETJMP_H | |
7417 mch_endjmp(); | |
7418 # ifdef SIGHASARG | |
7419 if (lc_signal != 0) | |
7420 { | |
7421 int i; | |
7422 | |
7423 /* try to find the name of this signal */ | |
7424 for (i = 0; signal_info[i].sig != -1; i++) | |
7425 if (lc_signal == signal_info[i].sig) | |
7426 break; | |
7427 EMSG2("E368: got SIG%s in libcall()", signal_info[i].name); | |
7428 } | |
7429 # endif | |
7430 # endif | |
7431 | |
12 | 7432 # if defined(USE_DLOPEN) |
7433 /* "dlerr" must be used before dlclose() */ | |
7434 if (dlerr != NULL) | |
7435 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7436 | |
7 | 7437 /* Free the DLL module. */ |
7438 (void)dlclose(hinstLib); | |
7439 # else | |
7440 (void)shl_unload(hinstLib); | |
7441 # endif | |
7442 } | |
7443 | |
7444 if (!success) | |
7445 { | |
7446 EMSG2(_(e_libcall), funcname); | |
7447 return FAIL; | |
7448 } | |
7449 | |
7450 return OK; | |
7451 } | |
7452 #endif | |
7453 | |
7454 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) | |
7455 static int xterm_trace = -1; /* default: disabled */ | |
7456 static int xterm_button; | |
7457 | |
7458 /* | |
7459 * Setup a dummy window for X selections in a terminal. | |
7460 */ | |
7461 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7462 setup_term_clip(void) |
7 | 7463 { |
7464 int z = 0; | |
7465 char *strp = ""; | |
7466 Widget AppShell; | |
7467 | |
7468 if (!x_connect_to_server()) | |
7469 return; | |
7470 | |
7471 open_app_context(); | |
7472 if (app_context != NULL && xterm_Shell == (Widget)0) | |
7473 { | |
7474 int (*oldhandler)(); | |
7475 #if defined(HAVE_SETJMP_H) | |
7476 int (*oldIOhandler)(); | |
7477 #endif | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7478 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7479 ELAPSED_TYPE start_tv; |
7 | 7480 |
7481 if (p_verbose > 0) | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7482 ELAPSED_INIT(start_tv); |
7 | 7483 # endif |
7484 | |
7485 /* Ignore X errors while opening the display */ | |
7486 oldhandler = XSetErrorHandler(x_error_check); | |
7487 | |
7488 #if defined(HAVE_SETJMP_H) | |
7489 /* Ignore X IO errors while opening the display */ | |
7490 oldIOhandler = XSetIOErrorHandler(x_IOerror_check); | |
7491 mch_startjmp(); | |
7492 if (SETJMP(lc_jump_env) != 0) | |
7493 { | |
7494 mch_didjmp(); | |
7495 xterm_dpy = NULL; | |
7496 } | |
7497 else | |
7498 #endif | |
7499 { | |
7500 xterm_dpy = XtOpenDisplay(app_context, xterm_display, | |
7501 "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); | |
7502 #if defined(HAVE_SETJMP_H) | |
7503 mch_endjmp(); | |
7504 #endif | |
7505 } | |
7506 | |
7507 #if defined(HAVE_SETJMP_H) | |
7508 /* Now handle X IO errors normally. */ | |
7509 (void)XSetIOErrorHandler(oldIOhandler); | |
7510 #endif | |
7511 /* Now handle X errors normally. */ | |
7512 (void)XSetErrorHandler(oldhandler); | |
7513 | |
7514 if (xterm_dpy == NULL) | |
7515 { | |
7516 if (p_verbose > 0) | |
292 | 7517 verb_msg((char_u *)_("Opening the X display failed")); |
7 | 7518 return; |
7519 } | |
7520 | |
7521 /* Catch terminating error of the X server connection. */ | |
7522 (void)XSetIOErrorHandler(x_IOerror_handler); | |
7523 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7524 # ifdef ELAPSED_FUNC |
7 | 7525 if (p_verbose > 0) |
292 | 7526 { |
7527 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7528 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 7529 verbose_leave(); |
7530 } | |
7 | 7531 # endif |
7532 | |
7533 /* Create a Shell to make converters work. */ | |
7534 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", | |
7535 applicationShellWidgetClass, xterm_dpy, | |
7536 NULL); | |
7537 if (AppShell == (Widget)0) | |
7538 return; | |
7539 xterm_Shell = XtVaCreatePopupShell("VIM", | |
7540 topLevelShellWidgetClass, AppShell, | |
7541 XtNmappedWhenManaged, 0, | |
7542 XtNwidth, 1, | |
7543 XtNheight, 1, | |
7544 NULL); | |
7545 if (xterm_Shell == (Widget)0) | |
7546 return; | |
7547 | |
7548 x11_setup_atoms(xterm_dpy); | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
7549 x11_setup_selection(xterm_Shell); |
7 | 7550 if (x11_display == NULL) |
7551 x11_display = xterm_dpy; | |
7552 | |
7553 XtRealizeWidget(xterm_Shell); | |
7554 XSync(xterm_dpy, False); | |
7555 xterm_update(); | |
7556 } | |
7557 if (xterm_Shell != (Widget)0) | |
7558 { | |
7559 clip_init(TRUE); | |
7560 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) | |
7561 x11_window = (Window)atol(strp); | |
7562 /* Check if $WINDOWID is valid. */ | |
7563 if (test_x11_window(xterm_dpy) == FAIL) | |
7564 x11_window = 0; | |
7565 if (x11_window != 0) | |
7566 xterm_trace = 0; | |
7567 } | |
7568 } | |
7569 | |
7570 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7571 start_xterm_trace(int button) |
7 | 7572 { |
7573 if (x11_window == 0 || xterm_trace < 0 || xterm_Shell == (Widget)0) | |
7574 return; | |
7575 xterm_trace = 1; | |
7576 xterm_button = button; | |
7577 do_xterm_trace(); | |
7578 } | |
7579 | |
7580 | |
7581 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7582 stop_xterm_trace(void) |
7 | 7583 { |
7584 if (xterm_trace < 0) | |
7585 return; | |
7586 xterm_trace = 0; | |
7587 } | |
7588 | |
7589 /* | |
7590 * Query the xterm pointer and generate mouse termcodes if necessary | |
7591 * return TRUE if dragging is active, else FALSE | |
7592 */ | |
7593 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7594 do_xterm_trace(void) |
7 | 7595 { |
7596 Window root, child; | |
7597 int root_x, root_y; | |
7598 int win_x, win_y; | |
7599 int row, col; | |
7600 int_u mask_return; | |
7601 char_u buf[50]; | |
7602 char_u *strp; | |
7603 long got_hints; | |
7604 static char_u *mouse_code; | |
7605 static char_u mouse_name[2] = {KS_MOUSE, KE_FILLER}; | |
7606 static int prev_row = 0, prev_col = 0; | |
7607 static XSizeHints xterm_hints; | |
7608 | |
7609 if (xterm_trace <= 0) | |
7610 return FALSE; | |
7611 | |
7612 if (xterm_trace == 1) | |
7613 { | |
7614 /* Get the hints just before tracking starts. The font size might | |
1510 | 7615 * have changed recently. */ |
7616 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) | |
7617 || !(got_hints & PResizeInc) | |
7 | 7618 || xterm_hints.width_inc <= 1 |
7619 || xterm_hints.height_inc <= 1) | |
7620 { | |
7621 xterm_trace = -1; /* Not enough data -- disable tracing */ | |
7622 return FALSE; | |
7623 } | |
7624 | |
7625 /* Rely on the same mouse code for the duration of this */ | |
7626 mouse_code = find_termcode(mouse_name); | |
7627 prev_row = mouse_row; | |
7009 | 7628 prev_col = mouse_col; |
7 | 7629 xterm_trace = 2; |
7630 | |
7631 /* Find the offset of the chars, there might be a scrollbar on the | |
7632 * left of the window and/or a menu on the top (eterm etc.) */ | |
7633 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7634 &win_x, &win_y, &mask_return); | |
7635 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) | |
7636 - (xterm_hints.height_inc / 2); | |
7637 if (xterm_hints.y <= xterm_hints.height_inc / 2) | |
7638 xterm_hints.y = 2; | |
7639 xterm_hints.x = win_x - (xterm_hints.width_inc * mouse_col) | |
7640 - (xterm_hints.width_inc / 2); | |
7641 if (xterm_hints.x <= xterm_hints.width_inc / 2) | |
7642 xterm_hints.x = 2; | |
7643 return TRUE; | |
7644 } | |
2768 | 7645 if (mouse_code == NULL || STRLEN(mouse_code) > 45) |
7 | 7646 { |
7647 xterm_trace = 0; | |
7648 return FALSE; | |
7649 } | |
7650 | |
7651 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7652 &win_x, &win_y, &mask_return); | |
7653 | |
7654 row = check_row((win_y - xterm_hints.y) / xterm_hints.height_inc); | |
7655 col = check_col((win_x - xterm_hints.x) / xterm_hints.width_inc); | |
7656 if (row == prev_row && col == prev_col) | |
7657 return TRUE; | |
7658 | |
7659 STRCPY(buf, mouse_code); | |
7660 strp = buf + STRLEN(buf); | |
7661 *strp++ = (xterm_button | MOUSE_DRAG) & ~0x20; | |
7662 *strp++ = (char_u)(col + ' ' + 1); | |
7663 *strp++ = (char_u)(row + ' ' + 1); | |
7664 *strp = 0; | |
7665 add_to_input_buf(buf, STRLEN(buf)); | |
7666 | |
7667 prev_row = row; | |
7668 prev_col = col; | |
7669 return TRUE; | |
7670 } | |
7671 | |
7672 # if defined(FEAT_GUI) || defined(PROTO) | |
7673 /* | |
7674 * Destroy the display, window and app_context. Required for GTK. | |
7675 */ | |
7676 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7677 clear_xterm_clip(void) |
7 | 7678 { |
7679 if (xterm_Shell != (Widget)0) | |
7680 { | |
7681 XtDestroyWidget(xterm_Shell); | |
7682 xterm_Shell = (Widget)0; | |
7683 } | |
7684 if (xterm_dpy != NULL) | |
7685 { | |
1605 | 7686 # if 0 |
7 | 7687 /* Lesstif and Solaris crash here, lose some memory */ |
7688 XtCloseDisplay(xterm_dpy); | |
1605 | 7689 # endif |
7 | 7690 if (x11_display == xterm_dpy) |
7691 x11_display = NULL; | |
7692 xterm_dpy = NULL; | |
7693 } | |
1605 | 7694 # if 0 |
7 | 7695 if (app_context != (XtAppContext)NULL) |
7696 { | |
7697 /* Lesstif and Solaris crash here, lose some memory */ | |
7698 XtDestroyApplicationContext(app_context); | |
7699 app_context = (XtAppContext)NULL; | |
7700 } | |
1605 | 7701 # endif |
7 | 7702 } |
7703 # endif | |
7704 | |
7705 /* | |
4230 | 7706 * Catch up with GUI or X events. |
7707 */ | |
7708 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7709 clip_update(void) |
4230 | 7710 { |
7711 # ifdef FEAT_GUI | |
7712 if (gui.in_use) | |
7713 gui_mch_update(); | |
7714 else | |
7715 # endif | |
7716 if (xterm_Shell != (Widget)0) | |
7717 xterm_update(); | |
7718 } | |
7719 | |
7720 /* | |
7 | 7721 * Catch up with any queued X events. This may put keyboard input into the |
7722 * input buffer, call resize call-backs, trigger timers etc. If there is | |
7723 * nothing in the X event queue (& no timers pending), then we return | |
7724 * immediately. | |
7725 */ | |
7726 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7727 xterm_update(void) |
7 | 7728 { |
7729 XEvent event; | |
7730 | |
6683 | 7731 for (;;) |
7 | 7732 { |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7733 XtInputMask mask = XtAppPending(app_context); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7734 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7735 if (mask == 0 || vim_is_input_buf_full()) |
6683 | 7736 break; |
7737 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7738 if (mask & XtIMXEvent) |
7 | 7739 { |
6683 | 7740 /* There is an event to process. */ |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7741 XtAppNextEvent(app_context, &event); |
6683 | 7742 #ifdef FEAT_CLIENTSERVER |
7743 { | |
7744 XPropertyEvent *e = (XPropertyEvent *)&event; | |
7745 | |
7746 if (e->type == PropertyNotify && e->window == commWindow | |
7 | 7747 && e->atom == commProperty && e->state == PropertyNewValue) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7748 serverEventProc(xterm_dpy, &event, 0); |
6683 | 7749 } |
7750 #endif | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7751 XtDispatchEvent(&event); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7752 } |
6683 | 7753 else |
7754 { | |
7755 /* There is something else than an event to process. */ | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7756 XtAppProcessEvent(app_context, mask); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7757 } |
7 | 7758 } |
7759 } | |
7760 | |
7761 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7762 clip_xterm_own_selection(VimClipboard *cbd) |
7 | 7763 { |
7764 if (xterm_Shell != (Widget)0) | |
7765 return clip_x11_own_selection(xterm_Shell, cbd); | |
7766 return FAIL; | |
7767 } | |
7768 | |
7769 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7770 clip_xterm_lose_selection(VimClipboard *cbd) |
7 | 7771 { |
7772 if (xterm_Shell != (Widget)0) | |
7773 clip_x11_lose_selection(xterm_Shell, cbd); | |
7774 } | |
7775 | |
7776 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7777 clip_xterm_request_selection(VimClipboard *cbd) |
7 | 7778 { |
7779 if (xterm_Shell != (Widget)0) | |
7780 clip_x11_request_selection(xterm_Shell, xterm_dpy, cbd); | |
7781 } | |
7782 | |
7783 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7784 clip_xterm_set_selection(VimClipboard *cbd) |
7 | 7785 { |
7786 clip_x11_set_selection(cbd); | |
7787 } | |
7788 #endif | |
7789 | |
7790 | |
7791 #if defined(USE_XSMP) || defined(PROTO) | |
7792 /* | |
7793 * Code for X Session Management Protocol. | |
7794 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7795 static void xsmp_handle_save_yourself(SmcConn smc_conn, SmPointer client_data, int save_type, Bool shutdown, int interact_style, Bool fast); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7796 static void xsmp_die(SmcConn smc_conn, SmPointer client_data); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7797 static void xsmp_save_complete(SmcConn smc_conn, SmPointer client_data); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7798 static void xsmp_shutdown_cancelled(SmcConn smc_conn, SmPointer client_data); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7799 static void xsmp_ice_connection(IceConn iceConn, IcePointer clientData, Bool opening, IcePointer *watchData); |
7 | 7800 |
7801 | |
7802 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7803 static void xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data); |
7 | 7804 |
7805 /* | |
7806 * This is our chance to ask the user if they want to save, | |
7807 * or abort the logout | |
7808 */ | |
7809 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7810 xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data UNUSED) |
7 | 7811 { |
7812 cmdmod_T save_cmdmod; | |
7813 int cancel_shutdown = False; | |
7814 | |
7815 save_cmdmod = cmdmod; | |
7816 cmdmod.confirm = TRUE; | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7420
diff
changeset
|
7817 if (check_changed_any(FALSE, FALSE)) |
7 | 7818 /* Mustn't logout */ |
7819 cancel_shutdown = True; | |
7820 cmdmod = save_cmdmod; | |
7821 setcursor(); /* position cursor */ | |
7822 out_flush(); | |
7823 | |
7824 /* Done interaction */ | |
7825 SmcInteractDone(smc_conn, cancel_shutdown); | |
7826 | |
7827 /* Finish off | |
7828 * Only end save-yourself here if we're not cancelling shutdown; | |
7829 * we'll get a cancelled callback later in which we'll end it. | |
7830 * Hopefully get around glitchy SMs (like GNOME-1) | |
7831 */ | |
7832 if (!cancel_shutdown) | |
7833 { | |
7834 xsmp.save_yourself = False; | |
7835 SmcSaveYourselfDone(smc_conn, True); | |
7836 } | |
7837 } | |
7838 # endif | |
7839 | |
7840 /* | |
7841 * Callback that starts save-yourself. | |
7842 */ | |
7843 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7844 xsmp_handle_save_yourself( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7845 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7846 SmPointer client_data UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7847 int save_type UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7848 Bool shutdown, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7849 int interact_style UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7850 Bool fast UNUSED) |
7 | 7851 { |
7852 /* Handle already being in saveyourself */ | |
7853 if (xsmp.save_yourself) | |
7854 SmcSaveYourselfDone(smc_conn, True); | |
7855 xsmp.save_yourself = True; | |
7856 xsmp.shutdown = shutdown; | |
7857 | |
7858 /* First up, preserve all files */ | |
7859 out_flush(); | |
7860 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
7861 | |
7862 if (p_verbose > 0) | |
292 | 7863 verb_msg((char_u *)_("XSMP handling save-yourself request")); |
7 | 7864 |
7865 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7866 /* Now see if we can ask about unsaved files */ | |
7867 if (shutdown && !fast && gui.in_use) | |
7868 /* Need to interact with user, but need SM's permission */ | |
7869 SmcInteractRequest(smc_conn, SmDialogError, | |
7870 xsmp_handle_interaction, client_data); | |
7871 else | |
7872 # endif | |
7873 { | |
7874 /* Can stop the cycle here */ | |
7875 SmcSaveYourselfDone(smc_conn, True); | |
7876 xsmp.save_yourself = False; | |
7877 } | |
7878 } | |
7879 | |
7880 | |
7881 /* | |
7882 * Callback to warn us of imminent death. | |
7883 */ | |
7884 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7885 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED) |
7 | 7886 { |
7887 xsmp_close(); | |
7888 | |
7889 /* quit quickly leaving swapfiles for modified buffers behind */ | |
7890 getout_preserve_modified(0); | |
7891 } | |
7892 | |
7893 | |
7894 /* | |
7895 * Callback to tell us that save-yourself has completed. | |
7896 */ | |
7897 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7898 xsmp_save_complete( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7899 SmcConn smc_conn UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7900 SmPointer client_data UNUSED) |
7 | 7901 { |
7902 xsmp.save_yourself = False; | |
7903 } | |
7904 | |
7905 | |
7906 /* | |
7907 * Callback to tell us that an instigated shutdown was cancelled | |
7908 * (maybe even by us) | |
7909 */ | |
7910 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7911 xsmp_shutdown_cancelled( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7912 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7913 SmPointer client_data UNUSED) |
7 | 7914 { |
7915 if (xsmp.save_yourself) | |
7916 SmcSaveYourselfDone(smc_conn, True); | |
7917 xsmp.save_yourself = False; | |
7918 xsmp.shutdown = False; | |
7919 } | |
7920 | |
7921 | |
7922 /* | |
7923 * Callback to tell us that a new ICE connection has been established. | |
7924 */ | |
7925 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7926 xsmp_ice_connection( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7927 IceConn iceConn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7928 IcePointer clientData UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7929 Bool opening, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7930 IcePointer *watchData UNUSED) |
7 | 7931 { |
7932 /* Intercept creation of ICE connection fd */ | |
7933 if (opening) | |
7934 { | |
7935 xsmp_icefd = IceConnectionNumber(iceConn); | |
7936 IceRemoveConnectionWatch(xsmp_ice_connection, NULL); | |
7937 } | |
7938 } | |
7939 | |
7940 | |
7941 /* Handle any ICE processing that's required; return FAIL if SM lost */ | |
7942 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7943 xsmp_handle_requests(void) |
7 | 7944 { |
7945 Bool rep; | |
7946 | |
7947 if (IceProcessMessages(xsmp.iceconn, NULL, &rep) | |
7948 == IceProcessMessagesIOError) | |
7949 { | |
7950 /* Lost ICE */ | |
7951 if (p_verbose > 0) | |
292 | 7952 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 7953 xsmp_close(); |
7954 return FAIL; | |
7955 } | |
7956 else | |
7957 return OK; | |
7958 } | |
7959 | |
7960 static int dummy; | |
7961 | |
7962 /* Set up X Session Management Protocol */ | |
7963 void | |
7964 xsmp_init(void) | |
7965 { | |
7966 char errorstring[80]; | |
7967 SmcCallbacks smcallbacks; | |
7968 #if 0 | |
7969 SmPropValue smname; | |
7970 SmProp smnameprop; | |
7971 SmProp *smprops[1]; | |
7972 #endif | |
7973 | |
7974 if (p_verbose > 0) | |
292 | 7975 verb_msg((char_u *)_("XSMP opening connection")); |
7 | 7976 |
7977 xsmp.save_yourself = xsmp.shutdown = False; | |
7978 | |
7979 /* Set up SM callbacks - must have all, even if they're not used */ | |
7980 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; | |
7981 smcallbacks.save_yourself.client_data = NULL; | |
7982 smcallbacks.die.callback = xsmp_die; | |
7983 smcallbacks.die.client_data = NULL; | |
7984 smcallbacks.save_complete.callback = xsmp_save_complete; | |
7985 smcallbacks.save_complete.client_data = NULL; | |
7986 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; | |
7987 smcallbacks.shutdown_cancelled.client_data = NULL; | |
7988 | |
7989 /* Set up a watch on ICE connection creations. The "dummy" argument is | |
7990 * apparently required for FreeBSD (we get a BUS error when using NULL). */ | |
7991 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) | |
7992 { | |
7993 if (p_verbose > 0) | |
292 | 7994 verb_msg((char_u *)_("XSMP ICE connection watch failed")); |
7 | 7995 return; |
7996 } | |
7997 | |
7998 /* Create an SM connection */ | |
7999 xsmp.smcconn = SmcOpenConnection( | |
8000 NULL, | |
8001 NULL, | |
8002 SmProtoMajor, | |
8003 SmProtoMinor, | |
8004 SmcSaveYourselfProcMask | SmcDieProcMask | |
8005 | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
8006 &smcallbacks, | |
8007 NULL, | |
1605 | 8008 &xsmp.clientid, |
7 | 8009 sizeof(errorstring), |
8010 errorstring); | |
8011 if (xsmp.smcconn == NULL) | |
8012 { | |
8013 char errorreport[132]; | |
273 | 8014 |
292 | 8015 if (p_verbose > 0) |
8016 { | |
8017 vim_snprintf(errorreport, sizeof(errorreport), | |
273 | 8018 _("XSMP SmcOpenConnection failed: %s"), errorstring); |
292 | 8019 verb_msg((char_u *)errorreport); |
8020 } | |
7 | 8021 return; |
8022 } | |
8023 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); | |
8024 | |
8025 #if 0 | |
8026 /* ID ourselves */ | |
8027 smname.value = "vim"; | |
8028 smname.length = 3; | |
8029 smnameprop.name = "SmProgram"; | |
8030 smnameprop.type = "SmARRAY8"; | |
8031 smnameprop.num_vals = 1; | |
8032 smnameprop.vals = &smname; | |
8033 | |
8034 smprops[0] = &smnameprop; | |
8035 SmcSetProperties(xsmp.smcconn, 1, smprops); | |
8036 #endif | |
8037 } | |
8038 | |
8039 | |
8040 /* Shut down XSMP comms. */ | |
8041 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8042 xsmp_close(void) |
7 | 8043 { |
8044 if (xsmp_icefd != -1) | |
8045 { | |
8046 SmcCloseConnection(xsmp.smcconn, 0, NULL); | |
1737 | 8047 if (xsmp.clientid != NULL) |
8048 free(xsmp.clientid); | |
1605 | 8049 xsmp.clientid = NULL; |
7 | 8050 xsmp_icefd = -1; |
8051 } | |
8052 } | |
8053 #endif /* USE_XSMP */ | |
8054 | |
8055 | |
8056 #ifdef EBCDIC | |
8057 /* Translate character to its CTRL- value */ | |
8058 char CtrlTable[] = | |
8059 { | |
8060 /* 00 - 5E */ | |
8061 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8062 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8063 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8064 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8065 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8066 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8067 /* ^ */ 0x1E, | |
8068 /* - */ 0x1F, | |
8069 /* 61 - 6C */ | |
8070 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8071 /* _ */ 0x1F, | |
8072 /* 6E - 80 */ | |
8073 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8074 /* a */ 0x01, | |
8075 /* b */ 0x02, | |
8076 /* c */ 0x03, | |
8077 /* d */ 0x37, | |
8078 /* e */ 0x2D, | |
8079 /* f */ 0x2E, | |
8080 /* g */ 0x2F, | |
8081 /* h */ 0x16, | |
8082 /* i */ 0x05, | |
8083 /* 8A - 90 */ | |
8084 0, 0, 0, 0, 0, 0, 0, | |
8085 /* j */ 0x15, | |
8086 /* k */ 0x0B, | |
8087 /* l */ 0x0C, | |
8088 /* m */ 0x0D, | |
8089 /* n */ 0x0E, | |
8090 /* o */ 0x0F, | |
8091 /* p */ 0x10, | |
8092 /* q */ 0x11, | |
8093 /* r */ 0x12, | |
8094 /* 9A - A1 */ | |
8095 0, 0, 0, 0, 0, 0, 0, 0, | |
8096 /* s */ 0x13, | |
8097 /* t */ 0x3C, | |
8098 /* u */ 0x3D, | |
8099 /* v */ 0x32, | |
8100 /* w */ 0x26, | |
8101 /* x */ 0x18, | |
8102 /* y */ 0x19, | |
8103 /* z */ 0x3F, | |
8104 /* AA - AC */ | |
8105 0, 0, 0, | |
8106 /* [ */ 0x27, | |
8107 /* AE - BC */ | |
8108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8109 /* ] */ 0x1D, | |
8110 /* BE - C0 */ 0, 0, 0, | |
8111 /* A */ 0x01, | |
8112 /* B */ 0x02, | |
8113 /* C */ 0x03, | |
8114 /* D */ 0x37, | |
8115 /* E */ 0x2D, | |
8116 /* F */ 0x2E, | |
8117 /* G */ 0x2F, | |
8118 /* H */ 0x16, | |
8119 /* I */ 0x05, | |
8120 /* CA - D0 */ 0, 0, 0, 0, 0, 0, 0, | |
8121 /* J */ 0x15, | |
8122 /* K */ 0x0B, | |
8123 /* L */ 0x0C, | |
8124 /* M */ 0x0D, | |
8125 /* N */ 0x0E, | |
8126 /* O */ 0x0F, | |
8127 /* P */ 0x10, | |
8128 /* Q */ 0x11, | |
8129 /* R */ 0x12, | |
8130 /* DA - DF */ 0, 0, 0, 0, 0, 0, | |
8131 /* \ */ 0x1C, | |
8132 /* E1 */ 0, | |
8133 /* S */ 0x13, | |
8134 /* T */ 0x3C, | |
8135 /* U */ 0x3D, | |
8136 /* V */ 0x32, | |
8137 /* W */ 0x26, | |
8138 /* X */ 0x18, | |
8139 /* Y */ 0x19, | |
8140 /* Z */ 0x3F, | |
8141 /* EA - FF*/ 0, 0, 0, 0, 0, 0, | |
8142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8143 }; | |
8144 | |
8145 char MetaCharTable[]= | |
8146 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
8147 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, | |
8148 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, | |
8149 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, | |
8150 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0 | |
8151 }; | |
8152 | |
8153 | |
8154 /* TODO: Use characters NOT numbers!!! */ | |
8155 char CtrlCharTable[]= | |
8156 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
8157 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, | |
8158 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, | |
8159 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, | |
8160 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233, | |
8161 }; | |
8162 | |
8163 | |
8164 #endif |