Mercurial > vim
annotate src/os_unix.c @ 14673:f1b7d308de2f v8.1.0349
patch 8.1.0349: crash when wiping buffer in a callback
commit https://github.com/vim/vim/commit/ed5a9d661248a2160368f1b0ab3a1bf74831db04
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 6 13:14:43 2018 +0200
patch 8.1.0349: crash when wiping buffer in a callback
Problem: Crash when wiping buffer in a callback.
Solution: Do not handle messages when only peeking for a character.
(closes #2107) Add "redraw_flag" to test_override().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 06 Sep 2018 13:15:05 +0200 |
parents | 2c9a467c82fa |
children | cf33c47d66aa |
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; | |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
164 static volatile sig_atomic_t oldtitle_outdated = FALSE; |
7 | 165 static int did_set_title = FALSE; |
166 static char_u *oldicon = NULL; | |
167 static int did_set_icon = FALSE; | |
168 #endif | |
169 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
170 static void may_core_dump(void); |
7 | 171 |
3048 | 172 #ifdef HAVE_UNION_WAIT |
173 typedef union wait waitstatus; | |
174 #else | |
175 typedef int waitstatus; | |
176 #endif | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
177 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
|
178 |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
179 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
|
180 static int WaitForCharOrMouse(long msec, int *interrupted, int ignore_input); |
5541 | 181 #if defined(__BEOS__) || defined(VMS) |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
182 int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 183 #else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
184 static int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 185 #endif |
186 | |
187 #ifdef FEAT_XCLIPBOARD | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
188 static int do_xterm_trace(void); |
331 | 189 # define XT_TRACE_DELAY 50 /* delay for xterm tracing */ |
7 | 190 #endif |
191 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
192 static void handle_resize(void); |
7 | 193 |
194 #if defined(SIGWINCH) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
195 static RETSIGTYPE sig_winch SIGPROTOARG; |
7 | 196 #endif |
197 #if defined(SIGINT) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
198 static RETSIGTYPE catch_sigint SIGPROTOARG; |
7 | 199 #endif |
200 #if defined(SIGPWR) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
201 static RETSIGTYPE catch_sigpwr SIGPROTOARG; |
7 | 202 #endif |
203 #if defined(SIGALRM) && defined(FEAT_X11) \ | |
204 && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) | |
205 # define SET_SIG_ALARM | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
206 static RETSIGTYPE sig_alarm SIGPROTOARG; |
1832 | 207 /* volatile because it is used in signal handler sig_alarm(). */ |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
208 static volatile sig_atomic_t sig_alarm_called; |
7 | 209 #endif |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
210 static RETSIGTYPE deathtrap SIGPROTOARG; |
7 | 211 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
212 static void catch_int_signal(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
213 static void set_signals(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
214 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
|
215 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
216 # 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
|
217 # 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
|
218 # 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
|
219 #else |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
220 # define SIGSET_DECL(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
221 # 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
|
222 # 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
|
223 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
224 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
|
225 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
|
226 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
227 static int save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file); |
7 | 228 |
229 #ifndef SIG_ERR | |
1879 | 230 # define SIG_ERR ((RETSIGTYPE (*)())-1) |
7 | 231 #endif |
232 | |
1832 | 233 /* volatile because it is used in signal handler sig_winch(). */ |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
234 static volatile sig_atomic_t do_resize = FALSE; |
7 | 235 static char_u *extra_shell_arg = NULL; |
236 static int show_shell_mess = TRUE; | |
1832 | 237 /* volatile because it is used in signal handler deathtrap(). */ |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
238 static volatile sig_atomic_t deadly_signal = 0; /* The signal we caught */ |
1832 | 239 /* volatile because it is used in signal handler deathtrap(). */ |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
240 static volatile sig_atomic_t in_mch_delay = FALSE; /* sleeping in mch_delay() */ |
7 | 241 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
242 #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
|
243 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
|
244 #endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
245 |
7 | 246 static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ |
247 | |
248 #ifdef USE_XSMP | |
249 typedef struct | |
250 { | |
251 SmcConn smcconn; /* The SM connection ID */ | |
252 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
|
253 char *clientid; /* The client ID for the current smc session */ |
7 | 254 Bool save_yourself; /* If we're in the middle of a save_yourself */ |
255 Bool shutdown; /* If we're in shutdown mode */ | |
256 } xsmp_config_T; | |
257 | |
258 static xsmp_config_T xsmp; | |
259 #endif | |
260 | |
261 #ifdef SYS_SIGLIST_DECLARED | |
262 /* | |
263 * I have seen | |
264 * extern char *_sys_siglist[NSIG]; | |
265 * on Irix, Linux, NetBSD and Solaris. It contains a nice list of strings | |
266 * that describe the signals. That is nearly what we want here. But | |
267 * autoconf does only check for sys_siglist (without the underscore), I | |
268 * 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
|
269 * This is why AC_DECL_SYS_SIGLIST is commented out in configure.ac. |
7 | 270 */ |
271 #endif | |
272 | |
273 static struct signalinfo | |
274 { | |
275 int sig; /* Signal number, eg. SIGSEGV etc */ | |
276 char *name; /* Signal name (not char_u!). */ | |
277 char deadly; /* Catch as a deadly signal? */ | |
278 } signal_info[] = | |
279 { | |
280 #ifdef SIGHUP | |
281 {SIGHUP, "HUP", TRUE}, | |
282 #endif | |
283 #ifdef SIGQUIT | |
284 {SIGQUIT, "QUIT", TRUE}, | |
285 #endif | |
286 #ifdef SIGILL | |
287 {SIGILL, "ILL", TRUE}, | |
288 #endif | |
289 #ifdef SIGTRAP | |
290 {SIGTRAP, "TRAP", TRUE}, | |
291 #endif | |
292 #ifdef SIGABRT | |
293 {SIGABRT, "ABRT", TRUE}, | |
294 #endif | |
295 #ifdef SIGEMT | |
296 {SIGEMT, "EMT", TRUE}, | |
297 #endif | |
298 #ifdef SIGFPE | |
299 {SIGFPE, "FPE", TRUE}, | |
300 #endif | |
301 #ifdef SIGBUS | |
302 {SIGBUS, "BUS", TRUE}, | |
303 #endif | |
4074 | 304 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) |
305 /* MzScheme uses SEGV in its garbage collector */ | |
7 | 306 {SIGSEGV, "SEGV", TRUE}, |
307 #endif | |
308 #ifdef SIGSYS | |
309 {SIGSYS, "SYS", TRUE}, | |
310 #endif | |
311 #ifdef SIGALRM | |
312 {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ | |
313 #endif | |
314 #ifdef SIGTERM | |
315 {SIGTERM, "TERM", TRUE}, | |
316 #endif | |
2701 | 317 #if defined(SIGVTALRM) && !defined(FEAT_RUBY) |
7 | 318 {SIGVTALRM, "VTALRM", TRUE}, |
319 #endif | |
1560 | 320 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) |
321 /* MzScheme uses SIGPROF for its own needs; On Linux with profiling | |
322 * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ | |
7 | 323 {SIGPROF, "PROF", TRUE}, |
324 #endif | |
325 #ifdef SIGXCPU | |
326 {SIGXCPU, "XCPU", TRUE}, | |
327 #endif | |
328 #ifdef SIGXFSZ | |
329 {SIGXFSZ, "XFSZ", TRUE}, | |
330 #endif | |
331 #ifdef SIGUSR1 | |
332 {SIGUSR1, "USR1", TRUE}, | |
333 #endif | |
1620 | 334 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) |
335 /* Used for sysmouse handling */ | |
7 | 336 {SIGUSR2, "USR2", TRUE}, |
337 #endif | |
338 #ifdef SIGINT | |
339 {SIGINT, "INT", FALSE}, | |
340 #endif | |
341 #ifdef SIGWINCH | |
342 {SIGWINCH, "WINCH", FALSE}, | |
343 #endif | |
344 #ifdef SIGTSTP | |
345 {SIGTSTP, "TSTP", FALSE}, | |
346 #endif | |
347 #ifdef SIGPIPE | |
348 {SIGPIPE, "PIPE", FALSE}, | |
349 #endif | |
350 {-1, "Unknown!", FALSE} | |
351 }; | |
352 | |
1935 | 353 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
354 mch_chdir(char *path) |
1935 | 355 { |
356 if (p_verbose >= 5) | |
357 { | |
358 verbose_enter(); | |
359 smsg((char_u *)"chdir(%s)", path); | |
360 verbose_leave(); | |
361 } | |
362 # ifdef VMS | |
363 return chdir(vms_fixfilename(path)); | |
364 # else | |
365 return chdir(path); | |
366 # endif | |
367 } | |
368 | |
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
|
369 /* 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
|
370 #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
|
371 # 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
|
372 #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
|
373 |
1757 | 374 /* |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
375 * Write s[len] to the screen (stdout). |
1757 | 376 */ |
7 | 377 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
378 mch_write(char_u *s, int len) |
7 | 379 { |
1757 | 380 ignored = (int)write(1, (char *)s, len); |
7 | 381 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
|
382 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); |
7 | 383 } |
384 | |
385 /* | |
1450 | 386 * mch_inchar(): low level input function. |
7 | 387 * Get a characters from the keyboard. |
388 * Return the number of characters that are available. | |
389 * If wtime == 0 do not wait for characters. | |
390 * If wtime == n wait a short time for characters. | |
391 * If wtime == -1 wait forever for characters. | |
392 */ | |
393 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
394 mch_inchar( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
395 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
396 int maxlen, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
397 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
|
398 int tb_change_cnt) |
7 | 399 { |
400 int len; | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
401 int interrupted = FALSE; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
402 int did_start_blocking = FALSE; |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
403 long wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
404 long elapsed_time = 0; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
405 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
406 ELAPSED_TYPE start_tv; |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
407 |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
408 ELAPSED_INIT(start_tv); |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
409 #endif |
7 | 410 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
411 /* 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
|
412 for (;;) |
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
413 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
414 /* 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
|
415 * columns=99" command was used. */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
416 while (do_resize) |
7 | 417 handle_resize(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
418 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
419 #ifdef MESSAGE_QUEUE |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
420 // Only process messages when waiting. |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
421 if (wtime != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
422 { |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
423 parse_queued_messages(); |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
424 // If input was put directly in typeahead buffer bail out here. |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
425 if (typebuf_changed(tb_change_cnt)) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
426 return 0; |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
427 } |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
428 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
429 if (wtime < 0 && did_start_blocking) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
430 /* 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
|
431 wait_time = -1; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
432 else |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
433 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
434 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
435 wait_time = wtime; |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
436 else |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
437 /* going to block after p_ut */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
438 wait_time = p_ut; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
439 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
440 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
|
441 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
442 wait_time -= elapsed_time; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
443 if (wait_time < 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
444 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
445 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
446 /* no character available within "wtime" */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
447 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
448 |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
449 else |
10309
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 /* no character available within 'updatetime' */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
452 did_start_blocking = TRUE; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
453 if (trigger_cursorhold() && maxlen >= 3 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
454 && !typebuf_changed(tb_change_cnt)) |
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 buf[0] = K_SPECIAL; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
457 buf[1] = KS_EXTRA; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
458 buf[2] = (int)KE_CURSORHOLD; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
459 return 3; |
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 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
462 * 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
|
463 * 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
|
464 * Also done when interrupted by SIGWINCH. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
465 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
466 before_blocking(); |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
467 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
468 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
469 } |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
470 } |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
471 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
472 #ifdef FEAT_JOB_CHANNEL |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
473 /* 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
|
474 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
|
475 wait_time = 100L; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
476 /* 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
|
477 * should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
478 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
|
479 wait_time = 10L; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
480 #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
|
481 #ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
482 if (p_beval && wait_time > 100L) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
483 /* 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
|
484 * 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
|
485 wait_time = 100L; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
486 #endif |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
487 |
7 | 488 /* |
2436 | 489 * We want to be interrupted by the winch signal |
490 * or by an event on the monitored file descriptors. | |
7 | 491 */ |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
492 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
|
493 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
494 /* 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
|
495 if (typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
496 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
497 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
498 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
499 * 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
|
500 * 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
|
501 * trying until none is available |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
502 * 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
|
503 * do it. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
504 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
505 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
|
506 if (len > 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
507 return len; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
508 continue; |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
509 } |
7 | 510 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
511 /* no character available */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
512 #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
|
513 /* estimate the elapsed time */ |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
514 elapsed_time += wait_time; |
10309
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 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
517 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
|
518 #ifdef FEAT_CLIENTSERVER |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
519 || server_waiting() |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
520 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
521 #ifdef MESSAGE_QUEUE |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
522 || interrupted |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
523 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
524 || 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
|
525 || (wtime < 0 && !did_start_blocking)) |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
526 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
527 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
528 /* no character available or interrupted */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
529 break; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
530 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
531 return 0; |
7 | 532 } |
533 | |
534 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
535 handle_resize(void) |
7 | 536 { |
537 do_resize = FALSE; | |
538 shell_resized(); | |
539 } | |
540 | |
541 /* | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
542 * Return non-zero if a character is available. |
7 | 543 */ |
544 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
545 mch_char_avail(void) |
7 | 546 { |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
547 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
|
548 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
549 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
550 #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
|
551 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
552 * 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
|
553 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
554 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
555 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
556 { |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
557 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
|
558 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
559 #endif |
7 | 560 |
561 #if defined(HAVE_TOTAL_MEM) || defined(PROTO) | |
562 # ifdef HAVE_SYS_RESOURCE_H | |
1879 | 563 # include <sys/resource.h> |
7 | 564 # endif |
565 # if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTL) | |
566 # include <sys/sysctl.h> | |
567 # endif | |
568 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) | |
569 # include <sys/sysinfo.h> | |
570 # endif | |
13396
5252ca53093a
patch 8.0.1572: Mac: getting memory size doesn't work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13388
diff
changeset
|
571 # 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
|
572 # 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
|
573 # 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
|
574 # endif |
7 | 575 |
576 /* | |
1110 | 577 * Return total amount of memory available in Kbyte. |
578 * Doesn't change when memory has been allocated. | |
7 | 579 */ |
580 long_u | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
581 mch_total_mem(int special UNUSED) |
7 | 582 { |
583 long_u mem = 0; | |
1110 | 584 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ |
7 | 585 |
13396
5252ca53093a
patch 8.0.1572: Mac: getting memory size doesn't work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13388
diff
changeset
|
586 # 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
|
587 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
588 /* 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
|
589 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
|
590 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
|
591 # 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
|
592 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
|
593 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
|
594 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
595 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
|
596 (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
|
597 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
598 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
|
599 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
|
600 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
601 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
|
602 (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
|
603 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
604 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
|
605 /* 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
|
606 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
|
607 + 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
|
608 # 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
|
609 + 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
|
610 # endif |
13511
8db9449b5c79
patch 8.0.1629: Mac: getpagesize() is deprecated
Christian Brabandt <cb@256bit.org>
parents:
13478
diff
changeset
|
611 ) * 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
|
612 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
|
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 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
615 |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
616 # 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
|
617 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
|
618 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
619 /* 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
|
620 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
|
621 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
|
622 # 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
|
623 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
|
624 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
625 /* 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
|
626 union { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
627 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
|
628 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
|
629 } physmem; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
630 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
631 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
632 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
|
633 # 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
|
634 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
|
635 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
636 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
|
637 # endif |
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 (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
|
639 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
640 # 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
|
641 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
|
642 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
643 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
|
644 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
|
645 else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
646 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
|
647 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
648 } |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
649 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
650 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
651 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
652 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) |
7 | 653 if (mem == 0) |
654 { | |
655 struct sysinfo sinfo; | |
656 | |
657 /* Linux way of getting amount of RAM available */ | |
658 if (sysinfo(&sinfo) == 0) | |
1110 | 659 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
660 # ifdef HAVE_SYSINFO_MEM_UNIT |
1110 | 661 /* avoid overflow as much as possible */ |
662 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) | |
663 { | |
664 sinfo.mem_unit = sinfo.mem_unit >> 1; | |
665 --shiftright; | |
666 } | |
667 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
|
668 # else |
7 | 669 mem = sinfo.totalram; |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
670 # endif |
1110 | 671 } |
7 | 672 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
673 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
674 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
675 # ifdef HAVE_SYSCONF |
7 | 676 if (mem == 0) |
677 { | |
678 long pagesize, pagecount; | |
679 | |
680 /* Solaris way of getting amount of RAM available */ | |
681 pagesize = sysconf(_SC_PAGESIZE); | |
682 pagecount = sysconf(_SC_PHYS_PAGES); | |
683 if (pagesize > 0 && pagecount > 0) | |
1110 | 684 { |
685 /* avoid overflow as much as possible */ | |
686 while (shiftright > 0 && (pagesize & 1) == 0) | |
687 { | |
1204 | 688 pagesize = (long_u)pagesize >> 1; |
1110 | 689 --shiftright; |
690 } | |
7 | 691 mem = (long_u)pagesize * pagecount; |
1110 | 692 } |
7 | 693 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
694 # endif |
7 | 695 |
696 /* Return the minimum of the physical memory and the user limit, because | |
697 * 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
|
698 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) |
7 | 699 { |
700 struct rlimit rlp; | |
701 | |
702 if (getrlimit(RLIMIT_DATA, &rlp) == 0 | |
703 && 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
|
704 # ifdef RLIM_INFINITY |
7 | 705 && rlp.rlim_cur != RLIM_INFINITY |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
706 # endif |
1110 | 707 && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright) |
7 | 708 ) |
1110 | 709 { |
710 mem = (long_u)rlp.rlim_cur; | |
711 shiftright = 10; | |
712 } | |
7 | 713 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
714 # endif |
7 | 715 |
716 if (mem > 0) | |
1110 | 717 return mem >> shiftright; |
718 return (long_u)0x1fffff; | |
7 | 719 } |
720 #endif | |
721 | |
722 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
723 mch_delay(long msec, int ignoreinput) |
7 | 724 { |
725 int old_tmode; | |
14 | 726 #ifdef FEAT_MZSCHEME |
727 long total = msec; /* remember original value */ | |
728 #endif | |
7 | 729 |
730 if (ignoreinput) | |
731 { | |
732 /* Go to cooked mode without echo, to allow SIGINT interrupting us | |
1530 | 733 * here. But we don't want QUIT to kill us (CTRL-\ used in a |
734 * shell may produce SIGQUIT). */ | |
735 in_mch_delay = TRUE; | |
7 | 736 old_tmode = curr_tmode; |
737 if (curr_tmode == TMODE_RAW) | |
738 settmode(TMODE_SLEEP); | |
739 | |
740 /* | |
741 * Everybody sleeps in a different way... | |
742 * Prefer nanosleep(), some versions of usleep() can only sleep up to | |
743 * one second. | |
744 */ | |
14 | 745 #ifdef FEAT_MZSCHEME |
746 do | |
747 { | |
748 /* if total is large enough, wait by portions in p_mzq */ | |
749 if (total > p_mzq) | |
750 msec = p_mzq; | |
751 else | |
752 msec = total; | |
753 total -= msec; | |
754 #endif | |
7 | 755 #ifdef HAVE_NANOSLEEP |
756 { | |
757 struct timespec ts; | |
758 | |
759 ts.tv_sec = msec / 1000; | |
760 ts.tv_nsec = (msec % 1000) * 1000000; | |
761 (void)nanosleep(&ts, NULL); | |
762 } | |
763 #else | |
764 # ifdef HAVE_USLEEP | |
765 while (msec >= 1000) | |
766 { | |
767 usleep((unsigned int)(999 * 1000)); | |
768 msec -= 999; | |
769 } | |
770 usleep((unsigned int)(msec * 1000)); | |
771 # else | |
772 # ifndef HAVE_SELECT | |
773 poll(NULL, 0, (int)msec); | |
774 # else | |
775 { | |
776 struct timeval tv; | |
777 | |
778 tv.tv_sec = msec / 1000; | |
779 tv.tv_usec = (msec % 1000) * 1000; | |
780 /* | |
781 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get | |
782 * a patch from Sun to fix this. Reported by Gunnar Pedersen. | |
783 */ | |
784 select(0, NULL, NULL, NULL, &tv); | |
785 } | |
786 # endif /* HAVE_SELECT */ | |
787 # endif /* HAVE_NANOSLEEP */ | |
788 #endif /* HAVE_USLEEP */ | |
14 | 789 #ifdef FEAT_MZSCHEME |
790 } | |
791 while (total > 0); | |
792 #endif | |
7 | 793 |
794 settmode(old_tmode); | |
1530 | 795 in_mch_delay = FALSE; |
7 | 796 } |
797 else | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
798 WaitForChar(msec, NULL, FALSE); |
7 | 799 } |
800 | |
180 | 801 #if defined(HAVE_STACK_LIMIT) \ |
7 | 802 || (!defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGSTACK)) |
803 # define HAVE_CHECK_STACK_GROWTH | |
804 /* | |
805 * Support for checking for an almost-out-of-stack-space situation. | |
806 */ | |
807 | |
808 /* | |
809 * Return a pointer to an item on the stack. Used to find out if the stack | |
810 * grows up or down. | |
811 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
812 static void check_stack_growth(char *p); |
7 | 813 static int stack_grows_downwards; |
814 | |
815 /* | |
816 * Find out if the stack grows upwards or downwards. | |
817 * "p" points to a variable on the stack of the caller. | |
818 */ | |
819 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
820 check_stack_growth(char *p) |
7 | 821 { |
822 int i; | |
823 | |
824 stack_grows_downwards = (p > (char *)&i); | |
825 } | |
826 #endif | |
827 | |
180 | 828 #if defined(HAVE_STACK_LIMIT) || defined(PROTO) |
7 | 829 static char *stack_limit = NULL; |
830 | |
831 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
832 # include <pthread.h> | |
833 # include <pthread_np.h> | |
834 #endif | |
835 | |
836 /* | |
837 * Find out until how var the stack can grow without getting into trouble. | |
838 * Called when starting up and when switching to the signal stack in | |
839 * deathtrap(). | |
840 */ | |
841 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
842 get_stack_limit(void) |
7 | 843 { |
844 struct rlimit rlp; | |
845 int i; | |
846 long lim; | |
847 | |
848 /* Set the stack limit to 15/16 of the allowable size. Skip this when the | |
849 * limit doesn't fit in a long (rlim_cur might be "long long"). */ | |
850 if (getrlimit(RLIMIT_STACK, &rlp) == 0 | |
851 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
852 # ifdef RLIM_INFINITY | |
853 && rlp.rlim_cur != RLIM_INFINITY | |
854 # endif | |
855 ) | |
856 { | |
857 lim = (long)rlp.rlim_cur; | |
858 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
859 { | |
860 pthread_attr_t attr; | |
861 size_t size; | |
862 | |
863 /* On FreeBSD the initial thread always has a fixed stack size, no | |
864 * matter what the limits are set to. Normally it's 1 Mbyte. */ | |
865 pthread_attr_init(&attr); | |
866 if (pthread_attr_get_np(pthread_self(), &attr) == 0) | |
867 { | |
868 pthread_attr_getstacksize(&attr, &size); | |
869 if (lim > (long)size) | |
870 lim = (long)size; | |
871 } | |
872 pthread_attr_destroy(&attr); | |
873 } | |
874 #endif | |
875 if (stack_grows_downwards) | |
876 { | |
877 stack_limit = (char *)((long)&i - (lim / 16L * 15L)); | |
878 if (stack_limit >= (char *)&i) | |
879 /* overflow, set to 1/16 of current stack position */ | |
880 stack_limit = (char *)((long)&i / 16L); | |
881 } | |
882 else | |
883 { | |
884 stack_limit = (char *)((long)&i + (lim / 16L * 15L)); | |
885 if (stack_limit <= (char *)&i) | |
886 stack_limit = NULL; /* overflow */ | |
887 } | |
888 } | |
889 } | |
890 | |
891 /* | |
892 * Return FAIL when running out of stack space. | |
893 * "p" must point to any variable local to the caller that's on the stack. | |
894 */ | |
895 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
896 mch_stackcheck(char *p) |
7 | 897 { |
898 if (stack_limit != NULL) | |
899 { | |
900 if (stack_grows_downwards) | |
901 { | |
902 if (p < stack_limit) | |
903 return FAIL; | |
904 } | |
905 else if (p > stack_limit) | |
906 return FAIL; | |
907 } | |
908 return OK; | |
909 } | |
910 #endif | |
911 | |
912 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
913 /* | |
914 * Support for using the signal stack. | |
915 * This helps when we run out of stack space, which causes a SIGSEGV. The | |
916 * signal handler then must run on another stack, since the normal stack is | |
917 * completely full. | |
918 */ | |
919 | |
920 #ifndef SIGSTKSZ | |
921 # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ | |
922 #endif | |
923 | |
924 # ifdef HAVE_SIGALTSTACK | |
925 static stack_t sigstk; /* for sigaltstack() */ | |
926 # else | |
927 static struct sigstack sigstk; /* for sigstack() */ | |
928 # endif | |
929 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
930 static void init_signal_stack(void); |
7 | 931 static char *signal_stack; |
932 | |
933 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
934 init_signal_stack(void) |
7 | 935 { |
936 if (signal_stack != NULL) | |
937 { | |
938 # ifdef HAVE_SIGALTSTACK | |
939 # ifdef HAVE_SS_BASE | |
940 sigstk.ss_base = signal_stack; | |
941 # else | |
942 sigstk.ss_sp = signal_stack; | |
943 # endif | |
944 sigstk.ss_size = SIGSTKSZ; | |
945 sigstk.ss_flags = 0; | |
946 (void)sigaltstack(&sigstk, NULL); | |
947 # else | |
948 sigstk.ss_sp = signal_stack; | |
949 if (stack_grows_downwards) | |
950 sigstk.ss_sp += SIGSTKSZ - 1; | |
951 sigstk.ss_onstack = 0; | |
952 (void)sigstack(&sigstk, NULL); | |
953 # endif | |
954 } | |
955 } | |
956 #endif | |
957 | |
958 /* | |
1832 | 959 * We need correct prototypes for a signal function, otherwise mean compilers |
7 | 960 * will barf when the second argument to signal() is ``wrong''. |
961 * Let me try it with a few tricky defines from my own osdef.h (jw). | |
962 */ | |
963 #if defined(SIGWINCH) | |
964 static RETSIGTYPE | |
965 sig_winch SIGDEFARG(sigarg) | |
966 { | |
967 /* this is not required on all systems, but it doesn't hurt anybody */ | |
968 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
969 do_resize = TRUE; | |
970 SIGRETURN; | |
971 } | |
972 #endif | |
973 | |
974 #if defined(SIGINT) | |
975 static RETSIGTYPE | |
976 catch_sigint SIGDEFARG(sigarg) | |
977 { | |
978 /* this is not required on all systems, but it doesn't hurt anybody */ | |
979 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
980 got_int = TRUE; | |
981 SIGRETURN; | |
982 } | |
983 #endif | |
984 | |
985 #if defined(SIGPWR) | |
986 static RETSIGTYPE | |
987 catch_sigpwr SIGDEFARG(sigarg) | |
988 { | |
37 | 989 /* this is not required on all systems, but it doesn't hurt anybody */ |
990 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
7 | 991 /* |
992 * I'm not sure we get the SIGPWR signal when the system is really going | |
993 * down or when the batteries are almost empty. Just preserve the swap | |
994 * files and don't exit, that can't do any harm. | |
995 */ | |
996 ml_sync_all(FALSE, FALSE); | |
997 SIGRETURN; | |
998 } | |
999 #endif | |
1000 | |
1001 #ifdef SET_SIG_ALARM | |
1002 /* | |
1003 * signal function for alarm(). | |
1004 */ | |
1005 static RETSIGTYPE | |
1006 sig_alarm SIGDEFARG(sigarg) | |
1007 { | |
1008 /* doesn't do anything, just to break a system call */ | |
1009 sig_alarm_called = TRUE; | |
1010 SIGRETURN; | |
1011 } | |
1012 #endif | |
1013 | |
188 | 1014 #if (defined(HAVE_SETJMP_H) \ |
1015 && ((defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) \ | |
1016 || defined(FEAT_LIBCALL))) \ | |
1017 || defined(PROTO) | |
7 | 1018 /* |
1019 * A simplistic version of setjmp() that only allows one level of using. | |
1020 * Don't call twice before calling mch_endjmp()!. | |
1021 * Usage: | |
1022 * mch_startjmp(); | |
1023 * if (SETJMP(lc_jump_env) != 0) | |
1024 * { | |
1025 * mch_didjmp(); | |
1026 * EMSG("crash!"); | |
1027 * } | |
1028 * else | |
1029 * { | |
1030 * do_the_work; | |
1031 * mch_endjmp(); | |
1032 * } | |
1033 * Note: Can't move SETJMP() here, because a function calling setjmp() must | |
1034 * not return before the saved environment is used. | |
1035 * Returns OK for normal return, FAIL when the protected code caused a | |
1036 * problem and LONGJMP() was used. | |
1037 */ | |
1038 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1039 mch_startjmp(void) |
7 | 1040 { |
1041 #ifdef SIGHASARG | |
1042 lc_signal = 0; | |
1043 #endif | |
1044 lc_active = TRUE; | |
1045 } | |
1046 | |
1047 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1048 mch_endjmp(void) |
7 | 1049 { |
1050 lc_active = FALSE; | |
1051 } | |
1052 | |
1053 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1054 mch_didjmp(void) |
7 | 1055 { |
1056 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1057 /* On FreeBSD the signal stack has to be reset after using siglongjmp(), | |
1058 * otherwise catching the signal only works once. */ | |
1059 init_signal_stack(); | |
1060 # endif | |
1061 } | |
1062 #endif | |
1063 | |
1064 /* | |
1065 * This function handles deadly signals. | |
5338 | 1066 * It tries to preserve any swap files and exit properly. |
7 | 1067 * (partly from Elvis). |
5338 | 1068 * NOTE: Avoid unsafe functions, such as allocating memory, they can result in |
1069 * a deadlock. | |
7 | 1070 */ |
1071 static RETSIGTYPE | |
1072 deathtrap SIGDEFARG(sigarg) | |
1073 { | |
1074 static int entered = 0; /* count the number of times we got here. | |
1075 Note: when memory has been corrupted | |
1076 this may get an arbitrary value! */ | |
1077 #ifdef SIGHASARG | |
1078 int i; | |
1079 #endif | |
1080 | |
1081 #if defined(HAVE_SETJMP_H) | |
1082 /* | |
1083 * Catch a crash in protected code. | |
1084 * Restores the environment saved in lc_jump_env, which looks like | |
1085 * SETJMP() returns 1. | |
1086 */ | |
1087 if (lc_active) | |
1088 { | |
1089 # if defined(SIGHASARG) | |
1090 lc_signal = sigarg; | |
1091 # endif | |
1092 lc_active = FALSE; /* don't jump again */ | |
1093 LONGJMP(lc_jump_env, 1); | |
1094 /* NOTREACHED */ | |
1095 } | |
1096 #endif | |
1097 | |
36 | 1098 #ifdef SIGHASARG |
1530 | 1099 # ifdef SIGQUIT |
1100 /* While in mch_delay() we go to cooked mode to allow a CTRL-C to | |
1101 * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when | |
1102 * pressing CTRL-\, but we don't want Vim to exit then. */ | |
1103 if (in_mch_delay && sigarg == SIGQUIT) | |
1104 SIGRETURN; | |
1105 # endif | |
1106 | |
37 | 1107 /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return |
1108 * here. This avoids that a non-reentrant function is interrupted, e.g., | |
1109 * free(). Calling free() again may then cause a crash. */ | |
1110 if (entered == 0 | |
1111 && (0 | |
1112 # ifdef SIGHUP | |
1113 || sigarg == SIGHUP | |
1114 # endif | |
1115 # ifdef SIGQUIT | |
1116 || sigarg == SIGQUIT | |
1117 # endif | |
1118 # ifdef SIGTERM | |
1119 || sigarg == SIGTERM | |
1120 # endif | |
1121 # ifdef SIGPWR | |
1122 || sigarg == SIGPWR | |
1123 # endif | |
1124 # ifdef SIGUSR1 | |
1125 || sigarg == SIGUSR1 | |
1126 # endif | |
1127 # ifdef SIGUSR2 | |
1128 || sigarg == SIGUSR2 | |
1129 # endif | |
1130 ) | |
413 | 1131 && !vim_handle_signal(sigarg)) |
36 | 1132 SIGRETURN; |
1133 #endif | |
1134 | |
7 | 1135 /* Remember how often we have been called. */ |
1136 ++entered; | |
1137 | |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1138 /* 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
|
1139 * available in the signal stack. */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1140 block_autocmds(); |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1141 |
7 | 1142 #ifdef FEAT_EVAL |
1143 /* Set the v:dying variable. */ | |
1144 set_vim_var_nr(VV_DYING, (long)entered); | |
1145 #endif | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13357
diff
changeset
|
1146 v_dying = entered; |
7 | 1147 |
180 | 1148 #ifdef HAVE_STACK_LIMIT |
7 | 1149 /* Since we are now using the signal stack, need to reset the stack |
1150 * limit. Otherwise using a regexp will fail. */ | |
1151 get_stack_limit(); | |
1152 #endif | |
1153 | |
758 | 1154 #if 0 |
1155 /* This is for opening gdb the moment Vim crashes. | |
1156 * You need to manually adjust the file name and Vim executable name. | |
1157 * Suggested by SungHyun Nam. */ | |
1158 { | |
1159 # define VI_GDB_FILE "/tmp/vimgdb" | |
1160 # define VIM_NAME "/usr/bin/vim" | |
1161 FILE *fp = fopen(VI_GDB_FILE, "w"); | |
1162 if (fp) | |
1163 { | |
1164 fprintf(fp, | |
1165 "file %s\n" | |
1166 "attach %d\n" | |
1167 "set height 1000\n" | |
1168 "bt full\n" | |
1169 , VIM_NAME, getpid()); | |
1170 fclose(fp); | |
1171 system("xterm -e gdb -x "VI_GDB_FILE); | |
1172 unlink(VI_GDB_FILE); | |
1173 } | |
1174 } | |
1175 #endif | |
1176 | |
7 | 1177 #ifdef SIGHASARG |
1178 /* try to find the name of this signal */ | |
1179 for (i = 0; signal_info[i].sig != -1; i++) | |
1180 if (sigarg == signal_info[i].sig) | |
1181 break; | |
1182 deadly_signal = sigarg; | |
1183 #endif | |
1184 | |
1185 full_screen = FALSE; /* don't write message to the GUI, it might be | |
1186 * part of the problem... */ | |
1187 /* | |
1188 * If something goes wrong after entering here, we may get here again. | |
1189 * When this happens, give a message and try to exit nicely (resetting the | |
1190 * terminal mode, etc.) | |
1191 * When this happens twice, just exit, don't even try to give a message, | |
1192 * stack may be corrupt or something weird. | |
1193 * When this still happens again (or memory was corrupted in such a way | |
1194 * that "entered" was clobbered) use _exit(), don't try freeing resources. | |
1195 */ | |
1196 if (entered >= 3) | |
1197 { | |
1198 reset_signals(); /* don't catch any signals anymore */ | |
1199 may_core_dump(); | |
1200 if (entered >= 4) | |
1201 _exit(8); | |
1202 exit(7); | |
1203 } | |
1204 if (entered == 2) | |
1205 { | |
5338 | 1206 /* No translation, it may call malloc(). */ |
1207 OUT_STR("Vim: Double signal, exiting\n"); | |
7 | 1208 out_flush(); |
1209 getout(1); | |
1210 } | |
1211 | |
5338 | 1212 /* No translation, it may call malloc(). */ |
7 | 1213 #ifdef SIGHASARG |
5338 | 1214 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", |
7 | 1215 signal_info[i].name); |
1216 #else | |
5338 | 1217 sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); |
1218 #endif | |
1219 | |
1220 /* Preserve files and exit. This sets the really_exiting flag to prevent | |
1221 * calling free(). */ | |
1222 preserve_exit(); | |
7 | 1223 |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1224 /* NOTREACHED */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1225 |
33 | 1226 #ifdef NBDEBUG |
1227 reset_signals(); | |
1228 may_core_dump(); | |
1229 abort(); | |
1230 #endif | |
1231 | |
7 | 1232 SIGRETURN; |
1233 } | |
1234 | |
1235 /* | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1236 * Invoked after receiving SIGCONT. We don't know what happened while |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1237 * sleeping, deal with part of that. |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1238 */ |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1239 static void |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1240 after_sigcont(void) |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1241 { |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1242 # ifdef FEAT_TITLE |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1243 // Don't change "oldtitle" in a signal handler, set a flag to obtain it |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1244 // again later. |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1245 oldtitle_outdated = TRUE; |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1246 # endif |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1247 settmode(TMODE_RAW); |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1248 need_check_timestamps = TRUE; |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1249 did_check_timestamps = FALSE; |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1250 } |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1251 |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1252 #if defined(SIGCONT) |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1253 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
1254 static volatile sig_atomic_t in_mch_suspend = FALSE; |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1255 |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1256 /* |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1257 * With multi-threading, suspending might not work immediately. Catch the |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1258 * SIGCONT signal, which will be used as an indication whether the suspending |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1259 * has been done or not. |
1832 | 1260 * |
1261 * On Linux, signal is not always handled immediately either. | |
1262 * See https://bugs.launchpad.net/bugs/291373 | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1263 * Probably because the signal is handled in another thread. |
1832 | 1264 * |
2701 | 1265 * volatile because it is used in signal handler sigcont_handler(). |
7 | 1266 */ |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
1267 static volatile sig_atomic_t sigcont_received; |
14577
33d751f40e4c
patch 8.1.0302: crash when using :suspend and "fg"
Christian Brabandt <cb@256bit.org>
parents:
14573
diff
changeset
|
1268 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
7 | 1269 |
1270 /* | |
1271 * signal handler for SIGCONT | |
1272 */ | |
1273 static RETSIGTYPE | |
1274 sigcont_handler SIGDEFARG(sigarg) | |
1275 { | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1276 if (in_mch_suspend) |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1277 { |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1278 sigcont_received = TRUE; |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1279 } |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1280 else |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1281 { |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1282 // We didn't suspend ourselves, assume we were stopped by a SIGSTOP |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1283 // signal (which can't be intercepted) and get a SIGCONT. Need to get |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1284 // back to a sane mode. We should redraw, but we can't really do that |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1285 // in a signal handler, do a redraw later. |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1286 after_sigcont(); |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1287 redraw_later(CLEAR); |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1288 cursor_on_force(); |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1289 out_flush(); |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1290 } |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1291 |
7 | 1292 SIGRETURN; |
1293 } | |
1294 #endif | |
1295 | |
2586 | 1296 # 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
|
1297 static void loose_clipboard(void); |
4230 | 1298 # ifdef USE_SYSTEM |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1299 static void save_clipboard(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1300 static void restore_clipboard(void); |
4209 | 1301 |
1302 static void *clip_star_save = NULL; | |
1303 static void *clip_plus_save = NULL; | |
4230 | 1304 # endif |
2586 | 1305 |
1306 /* | |
1307 * Called when Vim is going to sleep or execute a shell command. | |
1308 * We can't respond to requests for the X selections. Lose them, otherwise | |
1309 * other applications will hang. But first copy the text to cut buffer 0. | |
1310 */ | |
1311 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1312 loose_clipboard(void) |
2586 | 1313 { |
1314 if (clip_star.owned || clip_plus.owned) | |
1315 { | |
1316 x11_export_final_selection(); | |
1317 if (clip_star.owned) | |
1318 clip_lose_selection(&clip_star); | |
1319 if (clip_plus.owned) | |
1320 clip_lose_selection(&clip_plus); | |
1321 if (x11_display != NULL) | |
1322 XFlush(x11_display); | |
1323 } | |
1324 } | |
4209 | 1325 |
4230 | 1326 # ifdef USE_SYSTEM |
4209 | 1327 /* |
1328 * Save clipboard text to restore later. | |
1329 */ | |
1330 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1331 save_clipboard(void) |
4209 | 1332 { |
1333 if (clip_star.owned) | |
1334 clip_star_save = get_register('*', TRUE); | |
1335 if (clip_plus.owned) | |
1336 clip_plus_save = get_register('+', TRUE); | |
1337 } | |
1338 | |
1339 /* | |
1340 * Restore clipboard text if no one own the X selection. | |
1341 */ | |
1342 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1343 restore_clipboard(void) |
4209 | 1344 { |
1345 if (clip_star_save != NULL) | |
1346 { | |
1347 if (!clip_gen_owner_exists(&clip_star)) | |
1348 put_register('*', clip_star_save); | |
1349 else | |
1350 free_register(clip_star_save); | |
1351 clip_star_save = NULL; | |
1352 } | |
1353 if (clip_plus_save != NULL) | |
1354 { | |
1355 if (!clip_gen_owner_exists(&clip_plus)) | |
1356 put_register('+', clip_plus_save); | |
1357 else | |
1358 free_register(clip_plus_save); | |
1359 clip_plus_save = NULL; | |
1360 } | |
1361 } | |
4230 | 1362 # endif |
2586 | 1363 #endif |
1364 | |
7 | 1365 /* |
1366 * If the machine has job control, use it to suspend the program, | |
1367 * otherwise fake it by starting a new shell. | |
1368 */ | |
1369 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1370 mch_suspend(void) |
7 | 1371 { |
1372 /* BeOS does have SIGTSTP, but it doesn't work. */ | |
1373 #if defined(SIGTSTP) && !defined(__BEOS__) | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1374 in_mch_suspend = TRUE; |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1375 |
7 | 1376 out_flush(); /* needed to make cursor visible on some systems */ |
1377 settmode(TMODE_COOK); | |
1378 out_flush(); /* needed to disable mouse on some systems */ | |
1379 | |
1380 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2586 | 1381 loose_clipboard(); |
7 | 1382 # endif |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1383 # if defined(SIGCONT) |
7 | 1384 sigcont_received = FALSE; |
1385 # endif | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1386 |
7 | 1387 kill(0, SIGTSTP); /* send ourselves a STOP signal */ |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1388 |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1389 # if defined(SIGCONT) |
1832 | 1390 /* |
1391 * Wait for the SIGCONT signal to be handled. It generally happens | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1392 * immediately, but somehow not all the time, probably because it's handled |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1393 * in another thread. Do not call pause() because there would be race |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1394 * condition which would hang Vim if signal happened in between the test of |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1395 * sigcont_received and the call to pause(). If signal is not yet received, |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1396 * sleep 0, 1, 2, 3 ms. Don't bother waiting further if signal is not |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1397 * received after 1+2+3 ms (not expected to happen). |
1832 | 1398 */ |
1399 { | |
1932 | 1400 long wait_time; |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1401 |
1932 | 1402 for (wait_time = 0; !sigcont_received && wait_time <= 3L; wait_time++) |
1403 mch_delay(wait_time, FALSE); | |
1832 | 1404 } |
7 | 1405 # endif |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1406 in_mch_suspend = FALSE; |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1407 |
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1408 after_sigcont(); |
7 | 1409 #else |
1410 suspend_shell(); | |
1411 #endif | |
1412 } | |
1413 | |
1414 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1415 mch_init(void) |
7 | 1416 { |
1417 Columns = 80; | |
1418 Rows = 24; | |
1419 | |
1420 out_flush(); | |
1421 set_signals(); | |
167 | 1422 |
765 | 1423 #ifdef MACOS_CONVERT |
167 | 1424 mac_conv_init(); |
1425 #endif | |
4168 | 1426 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
1427 win_clip_init(); | |
1428 #endif | |
7 | 1429 } |
1430 | |
1431 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1432 set_signals(void) |
7 | 1433 { |
1434 #if defined(SIGWINCH) | |
1435 /* | |
1436 * WINDOW CHANGE signal is handled with sig_winch(). | |
1437 */ | |
1438 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
1439 #endif | |
1440 | |
1441 /* | |
1442 * We want the STOP signal to work, to make mch_suspend() work. | |
1443 * For "rvim" the STOP signal is ignored. | |
1444 */ | |
1445 #ifdef SIGTSTP | |
1446 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); | |
1447 #endif | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1448 #if defined(SIGCONT) |
7 | 1449 signal(SIGCONT, sigcont_handler); |
1450 #endif | |
1451 | |
1452 /* | |
1453 * We want to ignore breaking of PIPEs. | |
1454 */ | |
1455 #ifdef SIGPIPE | |
1456 signal(SIGPIPE, SIG_IGN); | |
1457 #endif | |
1458 | |
1459 #ifdef SIGINT | |
167 | 1460 catch_int_signal(); |
7 | 1461 #endif |
1462 | |
1463 /* | |
1464 * Ignore alarm signals (Perl's alarm() generates it). | |
1465 */ | |
1466 #ifdef SIGALRM | |
1467 signal(SIGALRM, SIG_IGN); | |
1468 #endif | |
1469 | |
1470 /* | |
1471 * Catch SIGPWR (power failure?) to preserve the swap files, so that no | |
1472 * work will be lost. | |
1473 */ | |
1474 #ifdef SIGPWR | |
1475 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
1476 #endif | |
1477 | |
1478 /* | |
1479 * Arrange for other signals to gracefully shutdown Vim. | |
1480 */ | |
1481 catch_signals(deathtrap, SIG_ERR); | |
1482 | |
1483 #if defined(FEAT_GUI) && defined(SIGHUP) | |
1484 /* | |
1485 * When the GUI is running, ignore the hangup signal. | |
1486 */ | |
1487 if (gui.in_use) | |
1488 signal(SIGHUP, SIG_IGN); | |
1489 #endif | |
1490 } | |
1491 | |
167 | 1492 #if defined(SIGINT) || defined(PROTO) |
1493 /* | |
1494 * Catch CTRL-C (only works while in Cooked mode). | |
1495 */ | |
1496 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1497 catch_int_signal(void) |
167 | 1498 { |
1499 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
1500 } | |
1501 #endif | |
1502 | |
7 | 1503 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1504 reset_signals(void) |
7 | 1505 { |
1506 catch_signals(SIG_DFL, SIG_DFL); | |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1507 #if defined(SIGCONT) |
7 | 1508 /* SIGCONT isn't in the list, because its default action is ignore */ |
1509 signal(SIGCONT, SIG_DFL); | |
1510 #endif | |
1511 } | |
1512 | |
1513 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1514 catch_signals( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1515 RETSIGTYPE (*func_deadly)(), |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1516 RETSIGTYPE (*func_other)()) |
7 | 1517 { |
1518 int i; | |
1519 | |
1520 for (i = 0; signal_info[i].sig != -1; i++) | |
1521 if (signal_info[i].deadly) | |
1522 { | |
1523 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) | |
1524 struct sigaction sa; | |
1525 | |
1526 /* Setup to use the alternate stack for the signal function. */ | |
1527 sa.sa_handler = func_deadly; | |
1528 sigemptyset(&sa.sa_mask); | |
1529 # if defined(__linux__) && defined(_REENTRANT) | |
1530 /* On Linux, with glibc compiled for kernel 2.2, there is a bug in | |
1531 * thread handling in combination with using the alternate stack: | |
1532 * pthread library functions try to use the stack pointer to | |
1533 * identify the current thread, causing a SEGV signal, which | |
1534 * recursively calls deathtrap() and hangs. */ | |
1535 sa.sa_flags = 0; | |
1536 # else | |
1537 sa.sa_flags = SA_ONSTACK; | |
1538 # endif | |
1539 sigaction(signal_info[i].sig, &sa, NULL); | |
1540 #else | |
1541 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) | |
1542 struct sigvec sv; | |
1543 | |
1544 /* Setup to use the alternate stack for the signal function. */ | |
1545 sv.sv_handler = func_deadly; | |
1546 sv.sv_mask = 0; | |
1547 sv.sv_flags = SV_ONSTACK; | |
1548 sigvec(signal_info[i].sig, &sv, NULL); | |
1549 # else | |
1550 signal(signal_info[i].sig, func_deadly); | |
1551 # endif | |
1552 #endif | |
1553 } | |
1554 else if (func_other != SIG_ERR) | |
1555 signal(signal_info[i].sig, func_other); | |
1556 } | |
1557 | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1558 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1559 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1560 block_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1561 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1562 sigset_t newset; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1563 int i; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1564 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1565 sigemptyset(&newset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1566 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1567 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
|
1568 sigaddset(&newset, signal_info[i].sig); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1569 |
14581
bb02e9e33026
patch 8.1.0304: no redraw when using a STOP signal on Vim and then CONT
Christian Brabandt <cb@256bit.org>
parents:
14577
diff
changeset
|
1570 # if defined(SIGCONT) |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1571 /* 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
|
1572 sigaddset(&newset, SIGCONT); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1573 # endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1574 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1575 sigprocmask(SIG_BLOCK, &newset, set); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1576 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1577 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1578 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1579 unblock_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1580 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1581 sigprocmask(SIG_SETMASK, set, NULL); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1582 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1583 #endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1584 |
7 | 1585 /* |
37 | 1586 * Handling of SIGHUP, SIGQUIT and SIGTERM: |
1146 | 1587 * "when" == a signal: when busy, postpone and return FALSE, otherwise |
1588 * return TRUE | |
1589 * "when" == SIGNAL_BLOCK: Going to be busy, block signals | |
1590 * "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
|
1591 * signal |
36 | 1592 * Returns TRUE when Vim should exit. |
1593 */ | |
1594 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1595 vim_handle_signal(int sig) |
36 | 1596 { |
37 | 1597 static int got_signal = 0; |
1598 static int blocked = TRUE; | |
1599 | |
1600 switch (sig) | |
36 | 1601 { |
37 | 1602 case SIGNAL_BLOCK: blocked = TRUE; |
1603 break; | |
1604 | |
1605 case SIGNAL_UNBLOCK: blocked = FALSE; | |
1606 if (got_signal != 0) | |
1607 { | |
1608 kill(getpid(), got_signal); | |
1609 got_signal = 0; | |
1610 } | |
1611 break; | |
1612 | |
1613 default: if (!blocked) | |
36 | 1614 return TRUE; /* exit! */ |
37 | 1615 got_signal = sig; |
1616 #ifdef SIGPWR | |
1617 if (sig != SIGPWR) | |
1618 #endif | |
1619 got_int = TRUE; /* break any loops */ | |
36 | 1620 break; |
1621 } | |
1622 return FALSE; | |
1623 } | |
1624 | |
1625 /* | |
7 | 1626 * Check_win checks whether we have an interactive stdout. |
1627 */ | |
1628 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1629 mch_check_win(int argc UNUSED, char **argv UNUSED) |
7 | 1630 { |
1631 if (isatty(1)) | |
1632 return OK; | |
1633 return FAIL; | |
1634 } | |
1635 | |
1636 /* | |
1637 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
1638 */ | |
1639 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1640 mch_input_isatty(void) |
7 | 1641 { |
1642 if (isatty(read_cmd_fd)) | |
1643 return TRUE; | |
1644 return FALSE; | |
1645 } | |
1646 | |
1647 #ifdef FEAT_X11 | |
1648 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1649 # if defined(ELAPSED_TIMEVAL) \ |
7 | 1650 && (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE)) |
1651 | |
1652 /* | |
1653 * Give a message about the elapsed time for opening the X window. | |
1654 */ | |
1655 static void | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1656 xopen_message(long elapsed_msec) |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1657 { |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1658 smsg((char_u *)_("Opening the X display took %ld msec"), elapsed_msec); |
7 | 1659 } |
1660 # endif | |
1661 #endif | |
1662 | |
1663 #if defined(FEAT_X11) && (defined(FEAT_TITLE) || defined(FEAT_XCLIPBOARD)) | |
1664 /* | |
1665 * A few functions shared by X11 title and clipboard code. | |
1666 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1667 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
|
1668 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
|
1669 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
|
1670 static int test_x11_window(Display *dpy); |
7 | 1671 |
1672 static int got_x_error = FALSE; | |
1673 | |
1674 /* | |
1675 * X Error handler, otherwise X just exits! (very rude) -- webb | |
1676 */ | |
1677 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1678 x_error_handler(Display *dpy, XErrorEvent *error_event) |
7 | 1679 { |
42 | 1680 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); |
7 | 1681 STRCAT(IObuff, _("\nVim: Got X error\n")); |
1682 | |
1683 /* We cannot print a message and continue, because no X calls are allowed | |
1684 * here (causes my system to hang). Silently continuing might be an | |
1685 * alternative... */ | |
1686 preserve_exit(); /* preserve files and exit */ | |
1687 | |
1688 return 0; /* NOTREACHED */ | |
1689 } | |
1690 | |
1691 /* | |
1692 * Another X Error handler, just used to check for errors. | |
1693 */ | |
1694 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1695 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
7 | 1696 { |
1697 got_x_error = TRUE; | |
1698 return 0; | |
1699 } | |
1700 | |
1701 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) | |
1702 # if defined(HAVE_SETJMP_H) | |
1703 /* | |
1704 * An X IO Error handler, used to catch error while opening the display. | |
1705 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1706 static int x_IOerror_check(Display *dpy); |
7 | 1707 |
1708 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1709 x_IOerror_check(Display *dpy UNUSED) |
7 | 1710 { |
1711 /* This function should not return, it causes exit(). Longjump instead. */ | |
1712 LONGJMP(lc_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1713 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1714 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
|
1715 # endif |
7 | 1716 } |
1717 # endif | |
1718 | |
1719 /* | |
1720 * An X IO Error handler, used to catch terminal errors. | |
1721 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1722 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
|
1723 static void may_restore_clipboard(void); |
6383 | 1724 static int xterm_dpy_was_reset = FALSE; |
7 | 1725 |
1726 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1727 x_IOerror_handler(Display *dpy UNUSED) |
7 | 1728 { |
1729 xterm_dpy = NULL; | |
6383 | 1730 xterm_dpy_was_reset = TRUE; |
7 | 1731 x11_window = 0; |
1732 x11_display = NULL; | |
1733 xterm_Shell = (Widget)0; | |
1734 | |
1735 /* This function should not return, it causes exit(). Longjump instead. */ | |
1736 LONGJMP(x_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1737 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1738 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
|
1739 # endif |
7 | 1740 } |
6383 | 1741 |
1742 /* | |
1743 * If the X11 connection was lost try to restore it. | |
1744 * Helps when the X11 server was stopped and restarted while Vim was inactive | |
6448 | 1745 * (e.g. through tmux). |
6383 | 1746 */ |
1747 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1748 may_restore_clipboard(void) |
6383 | 1749 { |
1750 if (xterm_dpy_was_reset) | |
1751 { | |
1752 xterm_dpy_was_reset = FALSE; | |
6458 | 1753 |
1754 # ifndef LESSTIF_VERSION | |
1755 /* This has been reported to avoid Vim getting stuck. */ | |
1756 if (app_context != (XtAppContext)NULL) | |
1757 { | |
1758 XtDestroyApplicationContext(app_context); | |
1759 app_context = (XtAppContext)NULL; | |
1760 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
1761 } | |
1762 # endif | |
1763 | |
6383 | 1764 setup_term_clip(); |
1765 get_x11_title(FALSE); | |
1766 } | |
1767 } | |
7 | 1768 #endif |
1769 | |
1770 /* | |
1771 * Return TRUE when connection to the X server is desired. | |
1772 */ | |
1773 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1774 x_connect_to_server(void) |
7 | 1775 { |
1776 #if defined(FEAT_CLIENTSERVER) | |
1777 if (x_force_connect) | |
1778 return TRUE; | |
1779 #endif | |
1780 if (x_no_connect) | |
1781 return FALSE; | |
1782 | |
1783 /* Check for a match with "exclude:" from 'clipboard'. */ | |
1784 if (clip_exclude_prog != NULL) | |
1785 { | |
6375 | 1786 if (vim_regexec_prog(&clip_exclude_prog, FALSE, T_NAME, (colnr_T)0)) |
7 | 1787 return FALSE; |
1788 } | |
1789 return TRUE; | |
1790 } | |
1791 | |
1792 /* | |
1793 * Test if "dpy" and x11_window are valid by getting the window title. | |
1794 * I don't actually want it yet, so there may be a simpler call to use, but | |
1795 * this will cause the error handler x_error_check() to be called if anything | |
1796 * is wrong, such as the window pointer being invalid (as can happen when the | |
1797 * user changes his DISPLAY, but not his WINDOWID) -- webb | |
1798 */ | |
1799 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1800 test_x11_window(Display *dpy) |
7 | 1801 { |
1802 int (*old_handler)(); | |
1803 XTextProperty text_prop; | |
1804 | |
1805 old_handler = XSetErrorHandler(x_error_check); | |
1806 got_x_error = FALSE; | |
1807 if (XGetWMName(dpy, x11_window, &text_prop)) | |
1808 XFree((void *)text_prop.value); | |
1809 XSync(dpy, False); | |
1810 (void)XSetErrorHandler(old_handler); | |
1811 | |
1812 if (p_verbose > 0 && got_x_error) | |
292 | 1813 verb_msg((char_u *)_("Testing the X display failed")); |
7 | 1814 |
1815 return (got_x_error ? FAIL : OK); | |
1816 } | |
1817 #endif | |
1818 | |
1819 #ifdef FEAT_TITLE | |
1820 | |
1821 #ifdef FEAT_X11 | |
1822 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1823 static int get_x11_thing(int get_title, int test_only); |
7 | 1824 |
1825 /* | |
1826 * try to get x11 window and display | |
1827 * | |
1828 * return FAIL for failure, OK otherwise | |
1829 */ | |
1830 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1831 get_x11_windis(void) |
7 | 1832 { |
1833 char *winid; | |
1834 static int result = -1; | |
1835 #define XD_NONE 0 /* x11_display not set here */ | |
1836 #define XD_HERE 1 /* x11_display opened here */ | |
1837 #define XD_GUI 2 /* x11_display used from gui.dpy */ | |
1838 #define XD_XTERM 3 /* x11_display used from xterm_dpy */ | |
1839 static int x11_display_from = XD_NONE; | |
1840 static int did_set_error_handler = FALSE; | |
1841 | |
1842 if (!did_set_error_handler) | |
1843 { | |
1844 /* X just exits if it finds an error otherwise! */ | |
1845 (void)XSetErrorHandler(x_error_handler); | |
1846 did_set_error_handler = TRUE; | |
1847 } | |
1848 | |
574 | 1849 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
7 | 1850 if (gui.in_use) |
1851 { | |
1852 /* | |
1853 * If the X11 display was opened here before, for the window where Vim | |
1854 * was started, close that one now to avoid a memory leak. | |
1855 */ | |
1856 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1857 { | |
1858 XCloseDisplay(x11_display); | |
1859 x11_display_from = XD_NONE; | |
1860 } | |
1861 if (gui_get_x11_windis(&x11_window, &x11_display) == OK) | |
1862 { | |
1863 x11_display_from = XD_GUI; | |
1864 return OK; | |
1865 } | |
1866 x11_display = NULL; | |
1867 return FAIL; | |
1868 } | |
1869 else if (x11_display_from == XD_GUI) | |
1870 { | |
1871 /* GUI must have stopped somehow, clear x11_display */ | |
1872 x11_window = 0; | |
1873 x11_display = NULL; | |
1874 x11_display_from = XD_NONE; | |
1875 } | |
1876 #endif | |
1877 | |
1878 /* When started with the "-X" argument, don't try connecting. */ | |
1879 if (!x_connect_to_server()) | |
1880 return FAIL; | |
1881 | |
1882 /* | |
1883 * If WINDOWID not set, should try another method to find out | |
1884 * what the current window number is. The only code I know for | |
1885 * this is very complicated. | |
1886 * We assume that zero is invalid for WINDOWID. | |
1887 */ | |
1888 if (x11_window == 0 && (winid = getenv("WINDOWID")) != NULL) | |
1889 x11_window = (Window)atol(winid); | |
1890 | |
1891 #ifdef FEAT_XCLIPBOARD | |
1892 if (xterm_dpy != NULL && x11_window != 0) | |
1893 { | |
1450 | 1894 /* We may have checked it already, but Gnome terminal can move us to |
1895 * another window, so we need to check every time. */ | |
1896 if (x11_display_from != XD_XTERM) | |
1897 { | |
1898 /* | |
1899 * If the X11 display was opened here before, for the window where | |
1900 * Vim was started, close that one now to avoid a memory leak. | |
1901 */ | |
1902 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1903 XCloseDisplay(x11_display); | |
1904 x11_display = xterm_dpy; | |
1905 x11_display_from = XD_XTERM; | |
1906 } | |
7 | 1907 if (test_x11_window(x11_display) == FAIL) |
1908 { | |
1909 /* probably bad $WINDOWID */ | |
1910 x11_window = 0; | |
1911 x11_display = NULL; | |
1912 x11_display_from = XD_NONE; | |
1913 return FAIL; | |
1914 } | |
1915 return OK; | |
1916 } | |
1917 #endif | |
1918 | |
1919 if (x11_window == 0 || x11_display == NULL) | |
1920 result = -1; | |
1921 | |
1922 if (result != -1) /* Have already been here and set this */ | |
1923 return result; /* Don't do all these X calls again */ | |
1924 | |
1925 if (x11_window != 0 && x11_display == NULL) | |
1926 { | |
1927 #ifdef SET_SIG_ALARM | |
1928 RETSIGTYPE (*sig_save)(); | |
1929 #endif | |
1930 #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
1931 struct timeval start_tv; | |
1932 | |
1933 if (p_verbose > 0) | |
1934 gettimeofday(&start_tv, NULL); | |
1935 #endif | |
1936 | |
1937 #ifdef SET_SIG_ALARM | |
1938 /* | |
1939 * Opening the Display may hang if the DISPLAY setting is wrong, or | |
1940 * the network connection is bad. Set an alarm timer to get out. | |
1941 */ | |
1942 sig_alarm_called = FALSE; | |
1943 sig_save = (RETSIGTYPE (*)())signal(SIGALRM, | |
1944 (RETSIGTYPE (*)())sig_alarm); | |
1945 alarm(2); | |
1946 #endif | |
1947 x11_display = XOpenDisplay(NULL); | |
1948 | |
1949 #ifdef SET_SIG_ALARM | |
1950 alarm(0); | |
1951 signal(SIGALRM, (RETSIGTYPE (*)())sig_save); | |
1952 if (p_verbose > 0 && sig_alarm_called) | |
292 | 1953 verb_msg((char_u *)_("Opening the X display timed out")); |
7 | 1954 #endif |
1955 if (x11_display != NULL) | |
1956 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1957 # ifdef ELAPSED_FUNC |
7 | 1958 if (p_verbose > 0) |
292 | 1959 { |
1960 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1961 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 1962 verbose_leave(); |
1963 } | |
7 | 1964 # endif |
1965 if (test_x11_window(x11_display) == FAIL) | |
1966 { | |
1967 /* Maybe window id is bad */ | |
1968 x11_window = 0; | |
1969 XCloseDisplay(x11_display); | |
1970 x11_display = NULL; | |
1971 } | |
1972 else | |
1973 x11_display_from = XD_HERE; | |
1974 } | |
1975 } | |
1976 if (x11_window == 0 || x11_display == NULL) | |
1977 return (result = FAIL); | |
2609 | 1978 |
1979 # ifdef FEAT_EVAL | |
1980 set_vim_var_nr(VV_WINDOWID, (long)x11_window); | |
1981 # endif | |
1982 | |
7 | 1983 return (result = OK); |
1984 } | |
1985 | |
1986 /* | |
1987 * Determine original x11 Window Title | |
1988 */ | |
1989 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1990 get_x11_title(int test_only) |
7 | 1991 { |
32 | 1992 return get_x11_thing(TRUE, test_only); |
7 | 1993 } |
1994 | |
1995 /* | |
1996 * Determine original x11 Window icon | |
1997 */ | |
1998 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1999 get_x11_icon(int test_only) |
7 | 2000 { |
2001 int retval = FALSE; | |
2002 | |
2003 retval = get_x11_thing(FALSE, test_only); | |
2004 | |
2005 /* could not get old icon, use terminal name */ | |
2006 if (oldicon == NULL && !test_only) | |
2007 { | |
2008 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 2009 oldicon = vim_strsave(T_NAME + 8); |
7 | 2010 else |
1940 | 2011 oldicon = vim_strsave(T_NAME); |
7 | 2012 } |
2013 | |
2014 return retval; | |
2015 } | |
2016 | |
2017 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2018 get_x11_thing( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2019 int get_title, /* get title string */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2020 int test_only) |
7 | 2021 { |
2022 XTextProperty text_prop; | |
2023 int retval = FALSE; | |
2024 Status status; | |
2025 | |
2026 if (get_x11_windis() == OK) | |
2027 { | |
2028 /* Get window/icon name if any */ | |
2029 if (get_title) | |
2030 status = XGetWMName(x11_display, x11_window, &text_prop); | |
2031 else | |
2032 status = XGetWMIconName(x11_display, x11_window, &text_prop); | |
2033 | |
2034 /* | |
2035 * If terminal is xterm, then x11_window may be a child window of the | |
2036 * outer xterm window that actually contains the window/icon name, so | |
2037 * keep traversing up the tree until a window with a title/icon is | |
2038 * found. | |
2039 */ | |
2040 /* Previously this was only done for xterm and alikes. I don't see a | |
2041 * reason why it would fail for other terminal emulators. | |
2042 * if (term_is_xterm) */ | |
2043 { | |
2044 Window root; | |
2045 Window parent; | |
2046 Window win = x11_window; | |
2047 Window *children; | |
2048 unsigned int num_children; | |
2049 | |
2050 while (!status || text_prop.value == NULL) | |
2051 { | |
2052 if (!XQueryTree(x11_display, win, &root, &parent, &children, | |
2053 &num_children)) | |
2054 break; | |
2055 if (children) | |
2056 XFree((void *)children); | |
2057 if (parent == root || parent == 0) | |
2058 break; | |
2059 | |
2060 win = parent; | |
2061 if (get_title) | |
2062 status = XGetWMName(x11_display, win, &text_prop); | |
2063 else | |
2064 status = XGetWMIconName(x11_display, win, &text_prop); | |
2065 } | |
2066 } | |
2067 if (status && text_prop.value != NULL) | |
2068 { | |
2069 retval = TRUE; | |
2070 if (!test_only) | |
2071 { | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2072 #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
|
2073 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
|
2074 # ifdef FEAT_MBYTE |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2075 && !has_mbyte |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2076 # endif |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2077 ) |
7 | 2078 { |
2079 #endif | |
2080 if (get_title) | |
2081 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2082 else | |
2083 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
|
2084 #if defined(FEAT_XFONTSET) || defined(FEAT_MBYTE) |
7 | 2085 } |
2086 else | |
2087 { | |
2088 char **cl; | |
2089 Status transform_status; | |
2090 int n = 0; | |
2091 | |
2092 transform_status = XmbTextPropertyToTextList(x11_display, | |
2093 &text_prop, | |
2094 &cl, &n); | |
2095 if (transform_status >= Success && n > 0 && cl[0]) | |
2096 { | |
2097 if (get_title) | |
2098 oldtitle = vim_strsave((char_u *) cl[0]); | |
2099 else | |
2100 oldicon = vim_strsave((char_u *) cl[0]); | |
2101 XFreeStringList(cl); | |
2102 } | |
2103 else | |
2104 { | |
2105 if (get_title) | |
2106 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2107 else | |
2108 oldicon = vim_strsave((char_u *)text_prop.value); | |
2109 } | |
2110 } | |
2111 #endif | |
2112 } | |
2113 XFree((void *)text_prop.value); | |
2114 } | |
2115 } | |
2116 return retval; | |
2117 } | |
2118 | |
6282 | 2119 /* Xutf8 functions are not avaialble on older systems. Note that on some |
2120 * systems X_HAVE_UTF8_STRING may be defined in a header file but | |
2121 * Xutf8SetWMProperties() is not in the X11 library. Configure checks for | |
2122 * that and defines HAVE_XUTF8SETWMPROPERTIES. */ | |
7 | 2123 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) |
6282 | 2124 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES |
7 | 2125 # define USE_UTF8_STRING |
2126 # endif | |
2127 #endif | |
2128 | |
2129 /* | |
2130 * Set x11 Window Title | |
2131 * | |
2132 * get_x11_windis() must be called before this and have returned OK | |
2133 */ | |
2134 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2135 set_x11_title(char_u *title) |
7 | 2136 { |
2137 /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING | |
2138 * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't | |
2139 * supported everywhere and STRING doesn't work for multi-byte titles. | |
2140 */ | |
2141 #ifdef USE_UTF8_STRING | |
2142 if (enc_utf8) | |
2143 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, | |
2144 NULL, NULL, 0, NULL, NULL, NULL); | |
2145 else | |
2146 #endif | |
2147 { | |
2148 #if XtSpecificationRelease >= 4 | |
2149 # ifdef FEAT_XFONTSET | |
2150 XmbSetWMProperties(x11_display, x11_window, (const char *)title, | |
2151 NULL, NULL, 0, NULL, NULL, NULL); | |
2152 # else | |
2153 XTextProperty text_prop; | |
129 | 2154 char *c_title = (char *)title; |
7 | 2155 |
2156 /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ | |
129 | 2157 (void)XStringListToTextProperty(&c_title, 1, &text_prop); |
7 | 2158 XSetWMProperties(x11_display, x11_window, &text_prop, |
2159 NULL, NULL, 0, NULL, NULL, NULL); | |
2160 # endif | |
2161 #else | |
2162 XStoreName(x11_display, x11_window, (char *)title); | |
2163 #endif | |
2164 } | |
2165 XFlush(x11_display); | |
2166 } | |
2167 | |
2168 /* | |
2169 * Set x11 Window icon | |
2170 * | |
2171 * get_x11_windis() must be called before this and have returned OK | |
2172 */ | |
2173 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2174 set_x11_icon(char_u *icon) |
7 | 2175 { |
2176 /* See above for comments about using X*SetWMProperties(). */ | |
2177 #ifdef USE_UTF8_STRING | |
2178 if (enc_utf8) | |
2179 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2180 NULL, 0, NULL, NULL, NULL); | |
2181 else | |
2182 #endif | |
2183 { | |
2184 #if XtSpecificationRelease >= 4 | |
2185 # ifdef FEAT_XFONTSET | |
2186 XmbSetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2187 NULL, 0, NULL, NULL, NULL); | |
2188 # else | |
2189 XTextProperty text_prop; | |
129 | 2190 char *c_icon = (char *)icon; |
2191 | |
2192 (void)XStringListToTextProperty(&c_icon, 1, &text_prop); | |
7 | 2193 XSetWMProperties(x11_display, x11_window, NULL, &text_prop, |
2194 NULL, 0, NULL, NULL, NULL); | |
2195 # endif | |
2196 #else | |
2197 XSetIconName(x11_display, x11_window, (char *)icon); | |
2198 #endif | |
2199 } | |
2200 XFlush(x11_display); | |
2201 } | |
2202 | |
2203 #else /* FEAT_X11 */ | |
2204 | |
2205 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2206 get_x11_title(int test_only UNUSED) |
7 | 2207 { |
2208 return FALSE; | |
2209 } | |
2210 | |
2211 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2212 get_x11_icon(int test_only) |
7 | 2213 { |
2214 if (!test_only) | |
2215 { | |
2216 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 2217 oldicon = vim_strsave(T_NAME + 8); |
7 | 2218 else |
1940 | 2219 oldicon = vim_strsave(T_NAME); |
7 | 2220 } |
2221 return FALSE; | |
2222 } | |
2223 | |
2224 #endif /* FEAT_X11 */ | |
2225 | |
2226 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2227 mch_can_restore_title(void) |
7 | 2228 { |
2229 return get_x11_title(TRUE); | |
2230 } | |
2231 | |
2232 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2233 mch_can_restore_icon(void) |
7 | 2234 { |
2235 return get_x11_icon(TRUE); | |
2236 } | |
2237 | |
2238 /* | |
2239 * Set the window title and icon. | |
2240 */ | |
2241 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2242 mch_settitle(char_u *title, char_u *icon) |
7 | 2243 { |
2244 int type = 0; | |
2245 static int recursive = 0; | |
2246 | |
2247 if (T_NAME == NULL) /* no terminal name (yet) */ | |
2248 return; | |
2249 if (title == NULL && icon == NULL) /* nothing to do */ | |
2250 return; | |
2251 | |
2252 /* When one of the X11 functions causes a deadly signal, we get here again | |
2253 * recursively. Avoid hanging then (something is probably locked). */ | |
2254 if (recursive) | |
2255 return; | |
2256 ++recursive; | |
2257 | |
2258 /* | |
2259 * if the window ID and the display is known, we may use X11 calls | |
2260 */ | |
2261 #ifdef FEAT_X11 | |
2262 if (get_x11_windis() == OK) | |
2263 type = 1; | |
2264 #else | |
2265 # if defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_GTK) | |
2266 if (gui.in_use) | |
2267 type = 1; | |
2268 # endif | |
2269 #endif | |
2270 | |
2271 /* | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2272 * Note: if "t_ts" is set, title is set with escape sequence rather |
7 | 2273 * than x11 calls, because the x11 calls don't always work |
2274 */ | |
2275 if ((type || *T_TS != NUL) && title != NULL) | |
2276 { | |
14573
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2277 if (oldtitle_outdated) |
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2278 { |
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2279 oldtitle_outdated = FALSE; |
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2280 VIM_CLEAR(oldtitle); |
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2281 } |
7 | 2282 if (oldtitle == NULL |
2283 #ifdef FEAT_GUI | |
2284 && !gui.in_use | |
2285 #endif | |
2286 ) /* first call but not in GUI, save title */ | |
2287 (void)get_x11_title(FALSE); | |
2288 | |
2289 if (*T_TS != NUL) /* it's OK if t_fs is empty */ | |
2290 term_settitle(title); | |
2291 #ifdef FEAT_X11 | |
2292 else | |
2293 # ifdef FEAT_GUI_GTK | |
2294 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2295 # endif | |
2296 set_x11_title(title); /* x11 */ | |
2297 #endif | |
64 | 2298 #if defined(FEAT_GUI_GTK) \ |
7 | 2299 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
2300 else | |
2301 gui_mch_settitle(title, icon); | |
2302 #endif | |
2303 did_set_title = TRUE; | |
2304 } | |
2305 | |
2306 if ((type || *T_CIS != NUL) && icon != NULL) | |
2307 { | |
2308 if (oldicon == NULL | |
2309 #ifdef FEAT_GUI | |
2310 && !gui.in_use | |
2311 #endif | |
2312 ) /* first call, save icon */ | |
2313 get_x11_icon(FALSE); | |
2314 | |
2315 if (*T_CIS != NUL) | |
2316 { | |
2317 out_str(T_CIS); /* set icon start */ | |
2318 out_str_nf(icon); | |
2319 out_str(T_CIE); /* set icon end */ | |
2320 out_flush(); | |
2321 } | |
2322 #ifdef FEAT_X11 | |
2323 else | |
2324 # ifdef FEAT_GUI_GTK | |
2325 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2326 # endif | |
2327 set_x11_icon(icon); /* x11 */ | |
2328 #endif | |
2329 did_set_icon = TRUE; | |
2330 } | |
2331 --recursive; | |
2332 } | |
2333 | |
2334 /* | |
2335 * Restore the window/icon title. | |
2336 * "which" is one of: | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2337 * SAVE_RESTORE_TITLE only restore title |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2338 * SAVE_RESTORE_ICON only restore icon |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2339 * SAVE_RESTORE_BOTH restore title and icon |
7 | 2340 */ |
2341 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2342 mch_restore_title(int which) |
7 | 2343 { |
2344 /* only restore the title or icon when it has been set */ | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2345 mch_settitle(((which & SAVE_RESTORE_TITLE) && did_set_title) ? |
7 | 2346 (oldtitle ? oldtitle : p_titleold) : NULL, |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2347 ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL); |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2348 |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2349 // pop and push from/to the stack |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2350 term_pop_title(which); |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2351 term_push_title(which); |
7 | 2352 } |
2353 | |
2354 #endif /* FEAT_TITLE */ | |
2355 | |
2356 /* | |
2357 * Return TRUE if "name" looks like some xterm name. | |
158 | 2358 * Seiichi Sato mentioned that "mlterm" works like xterm. |
7 | 2359 */ |
2360 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2361 vim_is_xterm(char_u *name) |
7 | 2362 { |
2363 if (name == NULL) | |
2364 return FALSE; | |
2365 return (STRNICMP(name, "xterm", 5) == 0 | |
2366 || STRNICMP(name, "nxterm", 6) == 0 | |
2367 || STRNICMP(name, "kterm", 5) == 0 | |
158 | 2368 || STRNICMP(name, "mlterm", 6) == 0 |
7 | 2369 || 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
|
2370 || STRNICMP(name, "screen.xterm", 12) == 0 |
7 | 2371 || STRCMP(name, "builtin_xterm") == 0); |
2372 } | |
2373 | |
1620 | 2374 #if defined(FEAT_MOUSE_XTERM) || defined(PROTO) |
2375 /* | |
2376 * Return TRUE if "name" appears to be that of a terminal | |
2377 * known to support the xterm-style mouse protocol. | |
2378 * Relies on term_is_xterm having been set to its correct value. | |
2379 */ | |
2380 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2381 use_xterm_like_mouse(char_u *name) |
1620 | 2382 { |
2383 return (name != NULL | |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2384 && (term_is_xterm |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2385 || STRNICMP(name, "screen", 6) == 0 |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2386 || STRNICMP(name, "tmux", 4) == 0 |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2387 || STRICMP(name, "st") == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2388 || STRNICMP(name, "st-", 3) == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2389 || STRNICMP(name, "stterm", 6) == 0)); |
1620 | 2390 } |
2391 #endif | |
2392 | |
7 | 2393 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) |
2394 /* | |
2395 * Return non-zero when using an xterm mouse, according to 'ttymouse'. | |
2396 * Return 1 for "xterm". | |
2397 * Return 2 for "xterm2". | |
3145 | 2398 * Return 3 for "urxvt". |
3746 | 2399 * Return 4 for "sgr". |
7 | 2400 */ |
2401 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2402 use_xterm_mouse(void) |
7 | 2403 { |
3746 | 2404 if (ttym_flags == TTYM_SGR) |
2405 return 4; | |
3145 | 2406 if (ttym_flags == TTYM_URXVT) |
2407 return 3; | |
7 | 2408 if (ttym_flags == TTYM_XTERM2) |
2409 return 2; | |
2410 if (ttym_flags == TTYM_XTERM) | |
2411 return 1; | |
2412 return 0; | |
2413 } | |
2414 #endif | |
2415 | |
2416 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2417 vim_is_iris(char_u *name) |
7 | 2418 { |
2419 if (name == NULL) | |
2420 return FALSE; | |
2421 return (STRNICMP(name, "iris-ansi", 9) == 0 | |
2422 || STRCMP(name, "builtin_iris-ansi") == 0); | |
2423 } | |
2424 | |
2425 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2426 vim_is_vt300(char_u *name) |
7 | 2427 { |
2428 if (name == NULL) | |
2429 return FALSE; /* actually all ANSI comp. terminals should be here */ | |
22 | 2430 /* catch VT100 - VT5xx */ |
2431 return ((STRNICMP(name, "vt", 2) == 0 | |
2432 && vim_strchr((char_u *)"12345", name[2]) != NULL) | |
7 | 2433 || STRCMP(name, "builtin_vt320") == 0); |
2434 } | |
2435 | |
2436 /* | |
2437 * Return TRUE if "name" is a terminal for which 'ttyfast' should be set. | |
2438 * This should include all windowed terminal emulators. | |
2439 */ | |
2440 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2441 vim_is_fastterm(char_u *name) |
7 | 2442 { |
2443 if (name == NULL) | |
2444 return FALSE; | |
2445 if (vim_is_xterm(name) || vim_is_vt300(name) || vim_is_iris(name)) | |
2446 return TRUE; | |
2447 return ( STRNICMP(name, "hpterm", 6) == 0 | |
2448 || STRNICMP(name, "sun-cmd", 7) == 0 | |
2449 || STRNICMP(name, "screen", 6) == 0 | |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2450 || STRNICMP(name, "tmux", 4) == 0 |
7 | 2451 || STRNICMP(name, "dtterm", 6) == 0); |
2452 } | |
2453 | |
2454 /* | |
2455 * Insert user name in s[len]. | |
2456 * Return OK if a name found. | |
2457 */ | |
2458 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2459 mch_get_user_name(char_u *s, int len) |
7 | 2460 { |
2461 #ifdef VMS | |
509 | 2462 vim_strncpy(s, (char_u *)cuserid(NULL), len - 1); |
7 | 2463 return OK; |
2464 #else | |
2465 return mch_get_uname(getuid(), s, len); | |
2466 #endif | |
2467 } | |
2468 | |
2469 /* | |
2470 * Insert user name for "uid" in s[len]. | |
2471 * Return OK if a name found. | |
2472 */ | |
2473 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2474 mch_get_uname(uid_t uid, char_u *s, int len) |
7 | 2475 { |
2476 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) | |
2477 struct passwd *pw; | |
2478 | |
2479 if ((pw = getpwuid(uid)) != NULL | |
2480 && pw->pw_name != NULL && *(pw->pw_name) != NUL) | |
2481 { | |
418 | 2482 vim_strncpy(s, (char_u *)pw->pw_name, len - 1); |
7 | 2483 return OK; |
2484 } | |
2485 #endif | |
2486 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ | |
2487 return FAIL; /* a number is not a name */ | |
2488 } | |
2489 | |
2490 /* | |
2491 * Insert host name is s[len]. | |
2492 */ | |
2493 | |
2494 #ifdef HAVE_SYS_UTSNAME_H | |
2495 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2496 mch_get_host_name(char_u *s, int len) |
7 | 2497 { |
2498 struct utsname vutsname; | |
2499 | |
2500 if (uname(&vutsname) < 0) | |
2501 *s = NUL; | |
2502 else | |
418 | 2503 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); |
7 | 2504 } |
2505 #else /* HAVE_SYS_UTSNAME_H */ | |
2506 | |
2507 # ifdef HAVE_SYS_SYSTEMINFO_H | |
2508 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) | |
2509 # endif | |
2510 | |
2511 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2512 mch_get_host_name(char_u *s, int len) |
7 | 2513 { |
2514 # ifdef VAXC | |
2515 vaxc$gethostname((char *)s, len); | |
2516 # else | |
2517 gethostname((char *)s, len); | |
2518 # endif | |
2519 s[len - 1] = NUL; /* make sure it's terminated */ | |
2520 } | |
2521 #endif /* HAVE_SYS_UTSNAME_H */ | |
2522 | |
2523 /* | |
2524 * return process ID | |
2525 */ | |
2526 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2527 mch_get_pid(void) |
7 | 2528 { |
2529 return (long)getpid(); | |
2530 } | |
2531 | |
2532 #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
|
2533 static char *strerror(int); |
7 | 2534 |
2535 static char * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2536 strerror(int err) |
7 | 2537 { |
2538 extern int sys_nerr; | |
2539 extern char *sys_errlist[]; | |
2540 static char er[20]; | |
2541 | |
2542 if (err > 0 && err < sys_nerr) | |
2543 return (sys_errlist[err]); | |
2544 sprintf(er, "Error %d", err); | |
2545 return er; | |
2546 } | |
2547 #endif | |
2548 | |
2549 /* | |
2550 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2551 * Return OK for success, FAIL for failure. | |
2552 */ | |
2553 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2554 mch_dirname(char_u *buf, int len) |
7 | 2555 { |
2556 #if defined(USE_GETCWD) | |
2557 if (getcwd((char *)buf, len) == NULL) | |
2558 { | |
2559 STRCPY(buf, strerror(errno)); | |
2560 return FAIL; | |
2561 } | |
2562 return OK; | |
2563 #else | |
2564 return (getwd((char *)buf) != NULL ? OK : FAIL); | |
2565 #endif | |
2566 } | |
2567 | |
2568 /* | |
1045 | 2569 * Get absolute file name into "buf[len]". |
7 | 2570 * |
2571 * return FAIL for failure, OK for success | |
2572 */ | |
2573 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2574 mch_FullName( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2575 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2576 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2577 int len, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2578 int force) /* also expand when already absolute path */ |
7 | 2579 { |
2580 int l; | |
1082 | 2581 #ifdef HAVE_FCHDIR |
7 | 2582 int fd = -1; |
2583 static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ | |
1082 | 2584 #endif |
7 | 2585 char_u olddir[MAXPATHL]; |
2586 char_u *p; | |
2587 int retval = OK; | |
1615 | 2588 #ifdef __CYGWIN__ |
1620 | 2589 char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but |
2590 it's not always defined */ | |
2591 #endif | |
7 | 2592 |
1082 | 2593 #ifdef VMS |
2594 fname = vms_fixfilename(fname); | |
2595 #endif | |
2596 | |
1102 | 2597 #ifdef __CYGWIN__ |
2598 /* | |
2599 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". | |
2600 */ | |
1657 | 2601 # 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
|
2602 /* 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
|
2603 * a forward slash. */ |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2604 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
|
2605 fname, posix_fname, MAXPATHL); |
1657 | 2606 # else |
1615 | 2607 cygwin_conv_to_posix_path(fname, posix_fname); |
1657 | 2608 # endif |
1615 | 2609 fname = posix_fname; |
1102 | 2610 #endif |
2611 | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2612 /* 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
|
2613 * 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
|
2614 if ((force || !mch_isFullName(fname)) |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2615 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) |
7 | 2616 { |
2617 /* | |
2618 * If the file name has a path, change to that directory for a moment, | |
2619 * and then do the getwd() (and get back to where we were). | |
2620 * This will get the correct path name with "../" things. | |
2621 */ | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2622 if (p != NULL) |
7 | 2623 { |
1082 | 2624 #ifdef HAVE_FCHDIR |
7 | 2625 /* |
2626 * Use fchdir() if possible, it's said to be faster and more | |
2627 * reliable. But on SunOS 4 it might not work. Check this by | |
2628 * doing a fchdir() right now. | |
2629 */ | |
2630 if (!dont_fchdir) | |
2631 { | |
2632 fd = open(".", O_RDONLY | O_EXTRA, 0); | |
2633 if (fd >= 0 && fchdir(fd) < 0) | |
2634 { | |
2635 close(fd); | |
2636 fd = -1; | |
2637 dont_fchdir = TRUE; /* don't try again */ | |
2638 } | |
2639 } | |
1082 | 2640 #endif |
7 | 2641 |
2642 /* Only change directory when we are sure we can return to where | |
2643 * we are now. After doing "su" chdir(".") might not work. */ | |
2644 if ( | |
1082 | 2645 #ifdef HAVE_FCHDIR |
7 | 2646 fd < 0 && |
1082 | 2647 #endif |
7 | 2648 (mch_dirname(olddir, MAXPATHL) == FAIL |
2649 || mch_chdir((char *)olddir) != 0)) | |
2650 { | |
2651 p = NULL; /* can't get current dir: don't chdir */ | |
2652 retval = FAIL; | |
2653 } | |
2654 else | |
2655 { | |
2656 /* The directory is copied into buf[], to be able to remove | |
2657 * the file name without changing it (could be a string in | |
2658 * read-only memory) */ | |
2659 if (p - fname >= len) | |
2660 retval = FAIL; | |
2661 else | |
2662 { | |
418 | 2663 vim_strncpy(buf, fname, p - fname); |
7 | 2664 if (mch_chdir((char *)buf)) |
2665 retval = FAIL; | |
2666 else | |
2667 fname = p + 1; | |
2668 *buf = NUL; | |
2669 } | |
2670 } | |
2671 } | |
2672 if (mch_dirname(buf, len) == FAIL) | |
2673 { | |
2674 retval = FAIL; | |
2675 *buf = NUL; | |
2676 } | |
2677 if (p != NULL) | |
2678 { | |
1082 | 2679 #ifdef HAVE_FCHDIR |
7 | 2680 if (fd >= 0) |
2681 { | |
1935 | 2682 if (p_verbose >= 5) |
2683 { | |
2684 verbose_enter(); | |
2685 MSG("fchdir() to previous dir"); | |
2686 verbose_leave(); | |
2687 } | |
7 | 2688 l = fchdir(fd); |
2689 close(fd); | |
2690 } | |
2691 else | |
1082 | 2692 #endif |
7 | 2693 l = mch_chdir((char *)olddir); |
2694 if (l != 0) | |
2695 EMSG(_(e_prev_dir)); | |
2696 } | |
2697 | |
2698 l = STRLEN(buf); | |
3867 | 2699 if (l >= len - 1) |
2700 retval = FAIL; /* no space for trailing "/" */ | |
1082 | 2701 #ifndef VMS |
3867 | 2702 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL |
7 | 2703 && STRCMP(fname, ".") != 0) |
3867 | 2704 STRCAT(buf, "/"); |
1082 | 2705 #endif |
7 | 2706 } |
1045 | 2707 |
7 | 2708 /* Catch file names which are too long. */ |
1877 | 2709 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) |
7 | 2710 return FAIL; |
2711 | |
2712 /* Do not append ".", "/dir/." is equal to "/dir". */ | |
2713 if (STRCMP(fname, ".") != 0) | |
2714 STRCAT(buf, fname); | |
2715 | |
2716 return OK; | |
2717 } | |
2718 | |
2719 /* | |
2720 * Return TRUE if "fname" does not depend on the current directory. | |
2721 */ | |
2722 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2723 mch_isFullName(char_u *fname) |
7 | 2724 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
2725 #ifdef VMS |
7 | 2726 return ( fname[0] == '/' || fname[0] == '.' || |
2727 strchr((char *)fname,':') || strchr((char *)fname,'"') || | |
2728 (strchr((char *)fname,'[') && strchr((char *)fname,']'))|| | |
2729 (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
|
2730 #else |
7 | 2731 return (*fname == '/' || *fname == '~'); |
2732 #endif | |
2733 } | |
2734 | |
585 | 2735 #if defined(USE_FNAME_CASE) || defined(PROTO) |
2736 /* | |
2737 * Set the case of the file name, if it already exists. This will cause the | |
2738 * file name to remain exactly the same. | |
1450 | 2739 * Only required for file systems where case is ignored and preserved. |
585 | 2740 */ |
2741 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2742 fname_case( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2743 char_u *name, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2744 int len UNUSED) /* buffer size, only used when name gets longer */ |
585 | 2745 { |
2746 struct stat st; | |
2747 char_u *slash, *tail; | |
2748 DIR *dirp; | |
2749 struct dirent *dp; | |
2750 | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2751 if (mch_lstat((char *)name, &st) >= 0) |
585 | 2752 { |
2753 /* Open the directory where the file is located. */ | |
2754 slash = vim_strrchr(name, '/'); | |
2755 if (slash == NULL) | |
2756 { | |
2757 dirp = opendir("."); | |
2758 tail = name; | |
2759 } | |
2760 else | |
2761 { | |
2762 *slash = NUL; | |
2763 dirp = opendir((char *)name); | |
2764 *slash = '/'; | |
2765 tail = slash + 1; | |
2766 } | |
2767 | |
2768 if (dirp != NULL) | |
2769 { | |
2770 while ((dp = readdir(dirp)) != NULL) | |
2771 { | |
2772 /* Only accept names that differ in case and are the same byte | |
2773 * length. TODO: accept different length name. */ | |
2774 if (STRICMP(tail, dp->d_name) == 0 | |
2775 && STRLEN(tail) == STRLEN(dp->d_name)) | |
2776 { | |
2777 char_u newname[MAXPATHL + 1]; | |
2778 struct stat st2; | |
2779 | |
2780 /* Verify the inode is equal. */ | |
2781 vim_strncpy(newname, name, MAXPATHL); | |
2782 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, | |
2783 MAXPATHL - (tail - name)); | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2784 if (mch_lstat((char *)newname, &st2) >= 0 |
585 | 2785 && st.st_ino == st2.st_ino |
2786 && st.st_dev == st2.st_dev) | |
2787 { | |
2788 STRCPY(tail, dp->d_name); | |
2789 break; | |
2790 } | |
2791 } | |
2792 } | |
2793 | |
2794 closedir(dirp); | |
2795 } | |
2796 } | |
2797 } | |
2798 #endif | |
2799 | |
7 | 2800 /* |
2801 * Get file permissions for 'name'. | |
2802 * Returns -1 when it doesn't exist. | |
2803 */ | |
2804 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2805 mch_getperm(char_u *name) |
7 | 2806 { |
2807 struct stat statb; | |
2808 | |
2809 /* Keep the #ifdef outside of stat(), it may be a macro. */ | |
2810 #ifdef VMS | |
2811 if (stat((char *)vms_fixfilename(name), &statb)) | |
2812 #else | |
2813 if (stat((char *)name, &statb)) | |
2814 #endif | |
2815 return -1; | |
1350 | 2816 #ifdef __INTERIX |
2817 /* The top bit makes the value negative, which means the file doesn't | |
2818 * exist. Remove the bit, we don't use it. */ | |
2819 return statb.st_mode & ~S_ADDACE; | |
2820 #else | |
7 | 2821 return statb.st_mode; |
1350 | 2822 #endif |
7 | 2823 } |
2824 | |
2825 /* | |
12847
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2826 * 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
|
2827 * Return FAIL for failure, OK otherwise. |
7 | 2828 */ |
2829 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2830 mch_setperm(char_u *name, long perm) |
7 | 2831 { |
2832 return (chmod((char *) | |
2833 #ifdef VMS | |
2834 vms_fixfilename(name), | |
2835 #else | |
2836 name, | |
2837 #endif | |
2838 (mode_t)perm) == 0 ? OK : FAIL); | |
2839 } | |
2840 | |
12847
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2841 #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
|
2842 /* |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2843 * 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
|
2844 * 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
|
2845 */ |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2846 int |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2847 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
|
2848 { |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2849 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
|
2850 } |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2851 #endif |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2852 |
7 | 2853 #if defined(HAVE_ACL) || defined(PROTO) |
2854 # ifdef HAVE_SYS_ACL_H | |
2855 # include <sys/acl.h> | |
2856 # endif | |
2857 # ifdef HAVE_SYS_ACCESS_H | |
2858 # include <sys/access.h> | |
2859 # endif | |
2860 | |
2861 # ifdef HAVE_SOLARIS_ACL | |
2862 typedef struct vim_acl_solaris_T { | |
2863 int acl_cnt; | |
2864 aclent_t *acl_entry; | |
2865 } vim_acl_solaris_T; | |
2866 # endif | |
2867 | |
1583 | 2868 #if defined(HAVE_SELINUX) || defined(PROTO) |
2869 /* | |
2870 * Copy security info from "from_file" to "to_file". | |
2871 */ | |
2872 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2873 mch_copy_sec(char_u *from_file, char_u *to_file) |
1583 | 2874 { |
2875 if (from_file == NULL) | |
2876 return; | |
2877 | |
2878 if (selinux_enabled == -1) | |
2879 selinux_enabled = is_selinux_enabled(); | |
2880 | |
2881 if (selinux_enabled > 0) | |
2882 { | |
2883 security_context_t from_context = NULL; | |
2884 security_context_t to_context = NULL; | |
2885 | |
2886 if (getfilecon((char *)from_file, &from_context) < 0) | |
2887 { | |
2888 /* If the filesystem doesn't support extended attributes, | |
2889 the original had no special security context and the | |
2890 target cannot have one either. */ | |
2891 if (errno == EOPNOTSUPP) | |
2892 return; | |
2893 | |
2894 MSG_PUTS(_("\nCould not get security context for ")); | |
2895 msg_outtrans(from_file); | |
2896 msg_putchar('\n'); | |
2897 return; | |
2898 } | |
2899 if (getfilecon((char *)to_file, &to_context) < 0) | |
2900 { | |
2901 MSG_PUTS(_("\nCould not get security context for ")); | |
2902 msg_outtrans(to_file); | |
2903 msg_putchar('\n'); | |
2904 freecon (from_context); | |
2905 return ; | |
2906 } | |
2907 if (strcmp(from_context, to_context) != 0) | |
2908 { | |
2909 if (setfilecon((char *)to_file, from_context) < 0) | |
2910 { | |
2911 MSG_PUTS(_("\nCould not set security context for ")); | |
2912 msg_outtrans(to_file); | |
2913 msg_putchar('\n'); | |
2914 } | |
2915 } | |
2916 freecon(to_context); | |
2917 freecon(from_context); | |
2918 } | |
2919 } | |
2920 #endif /* HAVE_SELINUX */ | |
2921 | |
5788 | 2922 #if defined(HAVE_SMACK) && !defined(PROTO) |
2923 /* | |
2924 * Copy security info from "from_file" to "to_file". | |
2925 */ | |
2926 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2927 mch_copy_sec(char_u *from_file, char_u *to_file) |
5788 | 2928 { |
5832 | 2929 static const char * const smack_copied_attributes[] = |
5788 | 2930 { |
2931 XATTR_NAME_SMACK, | |
2932 XATTR_NAME_SMACKEXEC, | |
2933 XATTR_NAME_SMACKMMAP | |
2934 }; | |
2935 | |
2936 char buffer[SMACK_LABEL_LEN]; | |
2937 const char *name; | |
2938 int index; | |
2939 int ret; | |
2940 ssize_t size; | |
2941 | |
2942 if (from_file == NULL) | |
2943 return; | |
2944 | |
2945 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) | |
2946 / sizeof(smack_copied_attributes)[0]) ; index++) | |
2947 { | |
2948 /* get the name of the attribute to copy */ | |
2949 name = smack_copied_attributes[index]; | |
2950 | |
2951 /* get the value of the attribute in buffer */ | |
2952 size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); | |
2953 if (size >= 0) | |
2954 { | |
2955 /* copy the attribute value of buffer */ | |
2956 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); | |
2957 if (ret < 0) | |
2958 { | |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2959 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2960 _("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
|
2961 name, to_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2962 msg_outtrans(IObuff); |
5788 | 2963 msg_putchar('\n'); |
2964 } | |
2965 } | |
2966 else | |
2967 { | |
2968 /* what reason of not having the attribute value? */ | |
2969 switch (errno) | |
2970 { | |
2971 case ENOTSUP: | |
2972 /* extended attributes aren't supported or enabled */ | |
2973 /* should a message be echoed? not sure... */ | |
2974 return; /* leave because it isn't usefull to continue */ | |
2975 | |
2976 case ERANGE: | |
2977 default: | |
2978 /* 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
|
2979 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2980 _("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
|
2981 name, from_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2982 msg_puts(IObuff); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2983 msg_putchar('\n'); |
5788 | 2984 /* FALLTHROUGH to remove the attribute */ |
2985 | |
2986 case ENODATA: | |
2987 /* no attribute of this name */ | |
2988 ret = removexattr((char*)to_file, name); | |
5800 | 2989 /* Silently ignore errors, apparently this happens when |
2990 * smack is not actually being used. */ | |
5788 | 2991 break; |
2992 } | |
2993 } | |
2994 } | |
2995 } | |
2996 #endif /* HAVE_SMACK */ | |
2997 | |
7 | 2998 /* |
2999 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3000 * Return NULL if the ACL is not available for whatever reason. | |
3001 */ | |
3002 vim_acl_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3003 mch_get_acl(char_u *fname UNUSED) |
7 | 3004 { |
3005 vim_acl_T ret = NULL; | |
3006 #ifdef HAVE_POSIX_ACL | |
3007 ret = (vim_acl_T)acl_get_file((char *)fname, ACL_TYPE_ACCESS); | |
3008 #else | |
3330 | 3009 #ifdef HAVE_SOLARIS_ZFS_ACL |
3010 acl_t *aclent; | |
3011 | |
3012 if (acl_get((char *)fname, 0, &aclent) < 0) | |
3013 return NULL; | |
3014 ret = (vim_acl_T)aclent; | |
3015 #else | |
7 | 3016 #ifdef HAVE_SOLARIS_ACL |
3017 vim_acl_solaris_T *aclent; | |
3018 | |
3019 aclent = malloc(sizeof(vim_acl_solaris_T)); | |
3020 if ((aclent->acl_cnt = acl((char *)fname, GETACLCNT, 0, NULL)) < 0) | |
3021 { | |
3022 free(aclent); | |
3023 return NULL; | |
3024 } | |
3025 aclent->acl_entry = malloc(aclent->acl_cnt * sizeof(aclent_t)); | |
3026 if (acl((char *)fname, GETACL, aclent->acl_cnt, aclent->acl_entry) < 0) | |
3027 { | |
3028 free(aclent->acl_entry); | |
3029 free(aclent); | |
3030 return NULL; | |
3031 } | |
3032 ret = (vim_acl_T)aclent; | |
3033 #else | |
3034 #if defined(HAVE_AIX_ACL) | |
3035 int aclsize; | |
3036 struct acl *aclent; | |
3037 | |
3038 aclsize = sizeof(struct acl); | |
3039 aclent = malloc(aclsize); | |
3040 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
3041 { | |
3042 if (errno == ENOSPC) | |
3043 { | |
3044 aclsize = aclent->acl_len; | |
3045 aclent = realloc(aclent, aclsize); | |
3046 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
3047 { | |
3048 free(aclent); | |
3049 return NULL; | |
3050 } | |
3051 } | |
3052 else | |
3053 { | |
3054 free(aclent); | |
3055 return NULL; | |
3056 } | |
3057 } | |
3058 ret = (vim_acl_T)aclent; | |
3059 #endif /* HAVE_AIX_ACL */ | |
3060 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3061 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3062 #endif /* HAVE_POSIX_ACL */ |
3063 return ret; | |
3064 } | |
3065 | |
3066 /* | |
3067 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3068 */ | |
3069 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3070 mch_set_acl(char_u *fname UNUSED, vim_acl_T aclent) |
7 | 3071 { |
3072 if (aclent == NULL) | |
3073 return; | |
3074 #ifdef HAVE_POSIX_ACL | |
3075 acl_set_file((char *)fname, ACL_TYPE_ACCESS, (acl_t)aclent); | |
3076 #else | |
3330 | 3077 #ifdef HAVE_SOLARIS_ZFS_ACL |
3078 acl_set((char *)fname, (acl_t *)aclent); | |
3079 #else | |
7 | 3080 #ifdef HAVE_SOLARIS_ACL |
3081 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt, | |
3082 ((vim_acl_solaris_T *)aclent)->acl_entry); | |
3083 #else | |
3084 #ifdef HAVE_AIX_ACL | |
3085 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); | |
3086 #endif /* HAVE_AIX_ACL */ | |
3087 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3088 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3089 #endif /* HAVE_POSIX_ACL */ |
3090 } | |
3091 | |
3092 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3093 mch_free_acl(vim_acl_T aclent) |
7 | 3094 { |
3095 if (aclent == NULL) | |
3096 return; | |
3097 #ifdef HAVE_POSIX_ACL | |
3098 acl_free((acl_t)aclent); | |
3099 #else | |
3330 | 3100 #ifdef HAVE_SOLARIS_ZFS_ACL |
3101 acl_free((acl_t *)aclent); | |
3102 #else | |
7 | 3103 #ifdef HAVE_SOLARIS_ACL |
3104 free(((vim_acl_solaris_T *)aclent)->acl_entry); | |
3105 free(aclent); | |
3106 #else | |
3107 #ifdef HAVE_AIX_ACL | |
3108 free(aclent); | |
3109 #endif /* HAVE_AIX_ACL */ | |
3110 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3111 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3112 #endif /* HAVE_POSIX_ACL */ |
3113 } | |
3114 #endif | |
3115 | |
3116 /* | |
3117 * Set hidden flag for "name". | |
3118 */ | |
3119 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3120 mch_hide(char_u *name UNUSED) |
7 | 3121 { |
3122 /* can't hide a file */ | |
3123 } | |
3124 | |
3125 /* | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3126 * return TRUE if "name" is a directory or a symlink to a directory |
7 | 3127 * return FALSE if "name" is not a directory |
3128 * return FALSE for error | |
3129 */ | |
3130 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3131 mch_isdir(char_u *name) |
7 | 3132 { |
3133 struct stat statb; | |
3134 | |
3135 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ | |
3136 return FALSE; | |
3137 if (stat((char *)name, &statb)) | |
3138 return FALSE; | |
3139 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); | |
3140 } | |
3141 | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3142 /* |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3143 * 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
|
3144 * 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
|
3145 * return FALSE for error |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3146 */ |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3147 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3148 mch_isrealdir(char_u *name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3149 { |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3150 struct stat statb; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3151 |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3152 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
|
3153 return FALSE; |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
3154 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
|
3155 return FALSE; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3156 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
|
3157 } |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3158 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3159 static int executable_file(char_u *name); |
7 | 3160 |
3161 /* | |
3162 * Return 1 if "name" is an executable file, 0 if not or it doesn't exist. | |
3163 */ | |
3164 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3165 executable_file(char_u *name) |
7 | 3166 { |
3167 struct stat st; | |
3168 | |
3169 if (stat((char *)name, &st)) | |
3170 return 0; | |
5704 | 3171 #ifdef VMS |
3172 /* Like on Unix system file can have executable rights but not necessarily | |
3173 * be an executable, but on Unix is not a default for an ordianry file to | |
3174 * have an executable flag - on VMS it is in most cases. | |
3175 * Therefore, this check does not have any sense - let keep us to the | |
3176 * conventions instead: | |
3177 * *.COM and *.EXE files are the executables - the rest are not. This is | |
3178 * not ideal but better then it was. | |
3179 */ | |
3180 int vms_executable = 0; | |
3181 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) | |
3182 { | |
3183 if (strstr(vms_tolower((char*)name),".exe") != NULL | |
3184 || strstr(vms_tolower((char*)name),".com")!= NULL) | |
3185 vms_executable = 1; | |
3186 } | |
3187 return vms_executable; | |
3188 #else | |
7 | 3189 return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0; |
5704 | 3190 #endif |
7 | 3191 } |
3192 | |
3193 /* | |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
3194 * Return TRUE if "name" can be found in $PATH and executed, FALSE if not. |
6695 | 3195 * If "use_path" is FALSE only check if "name" is executable. |
7 | 3196 * Return -1 if unknown. |
3197 */ | |
3198 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3199 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3200 { |
3201 char_u *buf; | |
3202 char_u *p, *e; | |
3203 int retval; | |
3204 | |
6695 | 3205 /* When "use_path" is false and if it's an absolute or relative path don't |
3206 * need to use $PATH. */ | |
3207 if (!use_path || mch_isFullName(name) || (name[0] == '.' | |
3208 && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) | |
5704 | 3209 { |
6695 | 3210 /* There must be a path separator, files in the current directory |
3211 * can't be executed. */ | |
3212 if (gettail(name) != name && executable_file(name)) | |
5782 | 3213 { |
3214 if (path != NULL) | |
3215 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3216 if (name[0] != '/') |
5782 | 3217 *path = FullName_save(name, TRUE); |
3218 else | |
3219 *path = vim_strsave(name); | |
3220 } | |
3221 return TRUE; | |
3222 } | |
3223 return FALSE; | |
5704 | 3224 } |
7 | 3225 |
3226 p = (char_u *)getenv("PATH"); | |
3227 if (p == NULL || *p == NUL) | |
3228 return -1; | |
3229 buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); | |
3230 if (buf == NULL) | |
3231 return -1; | |
3232 | |
3233 /* | |
3234 * Walk through all entries in $PATH to check if "name" exists there and | |
3235 * is an executable file. | |
3236 */ | |
3237 for (;;) | |
3238 { | |
3239 e = (char_u *)strchr((char *)p, ':'); | |
3240 if (e == NULL) | |
3241 e = p + STRLEN(p); | |
3242 if (e - p <= 1) /* empty entry means current dir */ | |
3243 STRCPY(buf, "./"); | |
3244 else | |
3245 { | |
418 | 3246 vim_strncpy(buf, p, e - p); |
7 | 3247 add_pathsep(buf); |
3248 } | |
3249 STRCAT(buf, name); | |
3250 retval = executable_file(buf); | |
3251 if (retval == 1) | |
5782 | 3252 { |
3253 if (path != NULL) | |
3254 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3255 if (buf[0] != '/') |
5782 | 3256 *path = FullName_save(buf, TRUE); |
3257 else | |
3258 *path = vim_strsave(buf); | |
3259 } | |
7 | 3260 break; |
5782 | 3261 } |
7 | 3262 |
3263 if (*e != ':') | |
3264 break; | |
3265 p = e + 1; | |
3266 } | |
3267 | |
3268 vim_free(buf); | |
3269 return retval; | |
3270 } | |
3271 | |
3272 /* | |
3273 * Check what "name" is: | |
3274 * NODE_NORMAL: file or directory (or doesn't exist) | |
3275 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3276 * NODE_OTHER: non-writable things | |
3277 */ | |
3278 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3279 mch_nodetype(char_u *name) |
7 | 3280 { |
3281 struct stat st; | |
3282 | |
3283 if (stat((char *)name, &st)) | |
3284 return NODE_NORMAL; | |
3285 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) | |
3286 return NODE_NORMAL; | |
3287 if (S_ISBLK(st.st_mode)) /* block device isn't writable */ | |
3288 return NODE_OTHER; | |
3289 /* Everything else is writable? */ | |
3290 return NODE_WRITABLE; | |
3291 } | |
3292 | |
3293 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3294 mch_early_init(void) |
7 | 3295 { |
3296 #ifdef HAVE_CHECK_STACK_GROWTH | |
3297 int i; | |
180 | 3298 |
7 | 3299 check_stack_growth((char *)&i); |
3300 | |
180 | 3301 # ifdef HAVE_STACK_LIMIT |
7 | 3302 get_stack_limit(); |
3303 # endif | |
3304 | |
3305 #endif | |
3306 | |
3307 /* | |
3308 * Setup an alternative stack for signals. Helps to catch signals when | |
3309 * running out of stack space. | |
3310 * Use of sigaltstack() is preferred, it's more portable. | |
3311 * Ignore any errors. | |
3312 */ | |
3313 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1737 | 3314 signal_stack = (char *)alloc(SIGSTKSZ); |
7 | 3315 init_signal_stack(); |
3316 #endif | |
3317 } | |
3318 | |
355 | 3319 #if defined(EXITFREE) || defined(PROTO) |
3320 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3321 mch_free_mem(void) |
355 | 3322 { |
359 | 3323 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
3324 if (clip_star.owned) | |
3325 clip_lose_selection(&clip_star); | |
3326 if (clip_plus.owned) | |
3327 clip_lose_selection(&clip_plus); | |
355 | 3328 # endif |
1605 | 3329 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
355 | 3330 if (xterm_Shell != (Widget)0) |
3331 XtDestroyWidget(xterm_Shell); | |
1605 | 3332 # ifndef LESSTIF_VERSION |
3333 /* Lesstif crashes here, lose some memory */ | |
355 | 3334 if (xterm_dpy != NULL) |
3335 XtCloseDisplay(xterm_dpy); | |
3336 if (app_context != (XtAppContext)NULL) | |
1605 | 3337 { |
355 | 3338 XtDestroyApplicationContext(app_context); |
1605 | 3339 # ifdef FEAT_X11 |
3340 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
3341 # endif | |
3342 } | |
3343 # endif | |
355 | 3344 # endif |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
3345 # if defined(FEAT_X11) |
1605 | 3346 if (x11_display != NULL |
3347 # ifdef FEAT_XCLIPBOARD | |
3348 && x11_display != xterm_dpy | |
3349 # endif | |
3350 ) | |
359 | 3351 XCloseDisplay(x11_display); |
3352 # endif | |
3353 # 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
|
3354 VIM_CLEAR(signal_stack); |
359 | 3355 # endif |
3356 # ifdef FEAT_TITLE | |
3357 vim_free(oldtitle); | |
3358 vim_free(oldicon); | |
3359 # endif | |
355 | 3360 } |
3361 #endif | |
3362 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3363 static void exit_scroll(void); |
7 | 3364 |
3365 /* | |
3366 * Output a newline when exiting. | |
3367 * Make sure the newline goes to the same stream as the text. | |
3368 */ | |
3369 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3370 exit_scroll(void) |
7 | 3371 { |
167 | 3372 if (silent_mode) |
3373 return; | |
7 | 3374 if (newline_on_exit || msg_didout) |
3375 { | |
3376 if (msg_use_printf()) | |
3377 { | |
3378 if (info_message) | |
3379 mch_msg("\n"); | |
3380 else | |
3381 mch_errmsg("\r\n"); | |
3382 } | |
3383 else | |
3384 out_char('\n'); | |
3385 } | |
3386 else | |
3387 { | |
3388 restore_cterm_colors(); /* get original colors back */ | |
3389 msg_clr_eos_force(); /* clear the rest of the display */ | |
3390 windgoto((int)Rows - 1, 0); /* may have moved the cursor */ | |
3391 } | |
3392 } | |
3393 | |
3394 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3395 mch_exit(int r) |
7 | 3396 { |
3397 exiting = TRUE; | |
3398 | |
3399 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
3400 x11_export_final_selection(); | |
3401 #endif | |
3402 | |
3403 #ifdef FEAT_GUI | |
3404 if (!gui.in_use) | |
3405 #endif | |
3406 { | |
3407 settmode(TMODE_COOK); | |
3408 #ifdef FEAT_TITLE | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
3409 // restore xterm title and icon name |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
3410 mch_restore_title(SAVE_RESTORE_BOTH); |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
3411 term_pop_title(SAVE_RESTORE_BOTH); |
7 | 3412 #endif |
3413 /* | |
3414 * When t_ti is not empty but it doesn't cause swapping terminal | |
3415 * pages, need to output a newline when msg_didout is set. But when | |
3416 * t_ti does swap pages it should not go to the shell page. Do this | |
3417 * before stoptermcap(). | |
3418 */ | |
3419 if (swapping_screen() && !newline_on_exit) | |
3420 exit_scroll(); | |
3421 | |
3422 /* Stop termcap: May need to check for T_CRV response, which | |
3423 * requires RAW mode. */ | |
3424 stoptermcap(); | |
3425 | |
3426 /* | |
3427 * A newline is only required after a message in the alternate screen. | |
3428 * This is set to TRUE by wait_return(). | |
3429 */ | |
3430 if (!swapping_screen() || newline_on_exit) | |
3431 exit_scroll(); | |
3432 | |
3433 /* Cursor may have been switched off without calling starttermcap() | |
3434 * when doing "vim -u vimrc" and vimrc contains ":q". */ | |
3435 if (full_screen) | |
3436 cursor_on(); | |
3437 } | |
3438 out_flush(); | |
3439 ml_close_all(TRUE); /* remove all memfiles */ | |
3440 may_core_dump(); | |
3441 #ifdef FEAT_GUI | |
3442 if (gui.in_use) | |
3443 gui_exit(r); | |
3444 #endif | |
167 | 3445 |
765 | 3446 #ifdef MACOS_CONVERT |
167 | 3447 mac_conv_cleanup(); |
3448 #endif | |
3449 | |
7 | 3450 #ifdef __QNX__ |
3451 /* A core dump won't be created if the signal handler | |
3452 * doesn't return, so we can't call exit() */ | |
3453 if (deadly_signal != 0) | |
3454 return; | |
3455 #endif | |
3456 | |
33 | 3457 #ifdef FEAT_NETBEANS_INTG |
2210 | 3458 netbeans_send_disconnect(); |
33 | 3459 #endif |
355 | 3460 |
3461 #ifdef EXITFREE | |
3462 free_all_mem(); | |
3463 #endif | |
3464 | |
7 | 3465 exit(r); |
3466 } | |
3467 | |
3468 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3469 may_core_dump(void) |
7 | 3470 { |
3471 if (deadly_signal != 0) | |
3472 { | |
3473 signal(deadly_signal, SIG_DFL); | |
3474 kill(getpid(), deadly_signal); /* Die using the signal we caught */ | |
3475 } | |
3476 } | |
3477 | |
3478 #ifndef VMS | |
3479 | |
3480 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3481 mch_settmode(int tmode) |
7 | 3482 { |
3483 static int first = TRUE; | |
3484 | |
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
|
3485 #ifdef NEW_TTY_SYSTEM |
7 | 3486 # ifdef HAVE_TERMIOS_H |
3487 static struct termios told; | |
3488 struct termios tnew; | |
3489 # else | |
3490 static struct termio told; | |
3491 struct termio tnew; | |
3492 # endif | |
3493 | |
3494 if (first) | |
3495 { | |
3496 first = FALSE; | |
3497 # if defined(HAVE_TERMIOS_H) | |
3498 tcgetattr(read_cmd_fd, &told); | |
3499 # else | |
3500 ioctl(read_cmd_fd, TCGETA, &told); | |
3501 # endif | |
3502 } | |
3503 | |
3504 tnew = told; | |
3505 if (tmode == TMODE_RAW) | |
3506 { | |
3507 /* | |
3508 * ~ICRNL enables typing ^V^M | |
3509 */ | |
3510 tnew.c_iflag &= ~ICRNL; | |
3511 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE | |
3512 # if defined(IEXTEN) && !defined(__MINT__) | |
3513 | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ | |
3514 /* but it breaks function keys on MINT */ | |
3515 # endif | |
3516 ); | |
3517 # ifdef ONLCR /* don't map NL -> CR NL, we do it ourselves */ | |
3518 tnew.c_oflag &= ~ONLCR; | |
3519 # endif | |
3520 tnew.c_cc[VMIN] = 1; /* return after 1 char */ | |
3521 tnew.c_cc[VTIME] = 0; /* don't wait */ | |
3522 } | |
3523 else if (tmode == TMODE_SLEEP) | |
9381
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3524 { |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3525 /* 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
|
3526 * typeahead characters. */ |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3527 tnew.c_lflag &= ~(ICANON | ECHO); |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3528 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
|
3529 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
|
3530 } |
7 | 3531 |
3532 # if defined(HAVE_TERMIOS_H) | |
3533 { | |
3534 int n = 10; | |
3535 | |
3536 /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a | |
3537 * few times. */ | |
3538 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 | |
3539 && errno == EINTR && n > 0) | |
3540 --n; | |
3541 } | |
3542 # else | |
3543 ioctl(read_cmd_fd, TCSETA, &tnew); | |
3544 # endif | |
3545 | |
3546 #else | |
3547 /* | |
3548 * for "old" tty systems | |
3549 */ | |
3550 # ifndef TIOCSETN | |
3551 # define TIOCSETN TIOCSETP /* for hpux 9.0 */ | |
3552 # endif | |
3553 static struct sgttyb ttybold; | |
3554 struct sgttyb ttybnew; | |
3555 | |
3556 if (first) | |
3557 { | |
3558 first = FALSE; | |
3559 ioctl(read_cmd_fd, TIOCGETP, &ttybold); | |
3560 } | |
3561 | |
3562 ttybnew = ttybold; | |
3563 if (tmode == TMODE_RAW) | |
3564 { | |
3565 ttybnew.sg_flags &= ~(CRMOD | ECHO); | |
3566 ttybnew.sg_flags |= RAW; | |
3567 } | |
3568 else if (tmode == TMODE_SLEEP) | |
3569 ttybnew.sg_flags &= ~(ECHO); | |
3570 ioctl(read_cmd_fd, TIOCSETN, &ttybnew); | |
3571 #endif | |
3572 curr_tmode = tmode; | |
3573 } | |
3574 | |
3575 /* | |
3576 * Try to get the code for "t_kb" from the stty setting | |
3577 * | |
3578 * Even if termcap claims a backspace key, the user's setting *should* | |
3579 * prevail. stty knows more about reality than termcap does, and if | |
3580 * somebody's usual erase key is DEL (which, for most BSD users, it will | |
3581 * be), they're going to get really annoyed if their erase key starts | |
3582 * doing forward deletes for no reason. (Eric Fischer) | |
3583 */ | |
3584 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3585 get_stty(void) |
7 | 3586 { |
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
|
3587 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
|
3588 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
|
3589 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
|
3590 |
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 (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
|
3592 { |
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 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
|
3594 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
|
3595 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
|
3596 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
|
3597 |
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 /* 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
|
3599 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
|
3600 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
|
3601 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
|
3602 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3603 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3604 |
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 /* |
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 * 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
|
3607 * 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
|
3608 */ |
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 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
|
3610 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
|
3611 { |
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 #ifdef NEW_TTY_SYSTEM |
7 | 3613 # ifdef HAVE_TERMIOS_H |
3614 struct termios keys; | |
3615 # else | |
3616 struct termio keys; | |
3617 # endif | |
3618 | |
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
|
3619 if ( |
7 | 3620 # 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
|
3621 tcgetattr(fd, &keys) != -1 |
7 | 3622 # 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
|
3623 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
|
3624 # 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
|
3625 ) |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3626 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3627 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
|
3628 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
|
3629 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
|
3630 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
|
3631 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
|
3632 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
|
3633 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
|
3634 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
|
3635 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
|
3636 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
|
3637 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
|
3638 } |
7 | 3639 #else |
3640 /* for "old" tty systems */ | |
3641 struct sgttyb keys; | |
3642 | |
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
|
3643 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
|
3644 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3645 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
|
3646 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
|
3647 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
|
3648 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
|
3649 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
|
3650 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3651 #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
|
3652 return FAIL; |
7 | 3653 } |
3654 | |
3655 #endif /* VMS */ | |
3656 | |
3657 #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
|
3658 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
|
3659 |
7 | 3660 /* |
3661 * Set mouse clicks on or off. | |
3662 */ | |
3663 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3664 mch_setmouse(int on) |
7 | 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 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
|
3668 # endif |
7 | 3669 int xterm_mouse_vers; |
3670 | |
14631
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3671 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3672 if (!on) |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3673 // Make sure not tracing mouse movements. Important when a button-down |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3674 // was received but no release yet. |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3675 stop_xterm_trace(); |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3676 # endif |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3677 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3678 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
|
3679 # 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
|
3680 && p_bevalterm == bevalterm_ison |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3681 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3682 ) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3683 /* return quickly if nothing to do */ |
7 | 3684 return; |
3685 | |
3686 xterm_mouse_vers = use_xterm_mouse(); | |
3145 | 3687 |
3688 # ifdef FEAT_MOUSE_URXVT | |
3746 | 3689 if (ttym_flags == TTYM_URXVT) |
3690 { | |
3145 | 3691 out_str_nf((char_u *) |
3692 (on | |
3693 ? IF_EB("\033[?1015h", ESC_STR "[?1015h") | |
3694 : 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
|
3695 mouse_ison = on; |
3145 | 3696 } |
3697 # endif | |
3698 | |
3746 | 3699 # ifdef FEAT_MOUSE_SGR |
3700 if (ttym_flags == TTYM_SGR) | |
3701 { | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3702 /* SGR mode supports columns above 223 */ |
3746 | 3703 out_str_nf((char_u *) |
3704 (on | |
3705 ? IF_EB("\033[?1006h", ESC_STR "[?1006h") | |
3706 : 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
|
3707 mouse_ison = on; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3708 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3709 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3710 |
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
|
3711 # 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
|
3712 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
|
3713 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3714 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
|
3715 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
|
3716 /* 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
|
3717 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
|
3718 (IF_EB("\033[?1003l", ESC_STR "[?1003l"))); |
3746 | 3719 } |
3720 # endif | |
3721 | |
7 | 3722 if (xterm_mouse_vers > 0) |
3723 { | |
3724 if (on) /* enable mouse events, use mouse tracking if available */ | |
3725 out_str_nf((char_u *) | |
3726 (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
|
3727 ? ( |
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
|
3728 # 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
|
3729 bevalterm_ison |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3730 ? 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
|
3731 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3732 IF_EB("\033[?1002h", ESC_STR "[?1002h")) |
7 | 3733 : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); |
3734 else /* disable mouse events, could probably always send the same */ | |
3735 out_str_nf((char_u *) | |
3736 (xterm_mouse_vers > 1 | |
3737 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") | |
3738 : 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
|
3739 mouse_ison = on; |
7 | 3740 } |
3741 | |
3742 # ifdef FEAT_MOUSE_DEC | |
3743 else if (ttym_flags == TTYM_DEC) | |
3744 { | |
3745 if (on) /* enable mouse events */ | |
3746 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); | |
3747 else /* disable mouse events */ | |
3748 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
|
3749 mouse_ison = on; |
7 | 3750 } |
3751 # endif | |
3752 | |
3753 # ifdef FEAT_MOUSE_GPM | |
3754 else | |
3755 { | |
3756 if (on) | |
3757 { | |
3758 if (gpm_open()) | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3759 mouse_ison = TRUE; |
7 | 3760 } |
3761 else | |
3762 { | |
3763 gpm_close(); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3764 mouse_ison = FALSE; |
7 | 3765 } |
3766 } | |
3767 # endif | |
3768 | |
1620 | 3769 # ifdef FEAT_SYSMOUSE |
3770 else | |
3771 { | |
3772 if (on) | |
3773 { | |
3774 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
|
3775 mouse_ison = TRUE; |
1620 | 3776 } |
3777 else | |
3778 { | |
3779 sysmouse_close(); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3780 mouse_ison = FALSE; |
1620 | 3781 } |
3782 } | |
3783 # endif | |
3784 | |
7 | 3785 # ifdef FEAT_MOUSE_JSB |
3786 else | |
3787 { | |
3788 if (on) | |
3789 { | |
3790 /* D - Enable Mouse up/down messages | |
3791 * L - Enable Left Button Reporting | |
3792 * M - Enable Middle Button Reporting | |
3793 * R - Enable Right Button Reporting | |
3794 * K - Enable SHIFT and CTRL key Reporting | |
3795 * + - Enable Advanced messaging of mouse moves and up/down messages | |
3796 * Q - Quiet No Ack | |
3797 * # - Numeric value of mouse pointer required | |
3798 * 0 = Multiview 2000 cursor, used as standard | |
3799 * 1 = Windows Arrow | |
3800 * 2 = Windows I Beam | |
3801 * 3 = Windows Hour Glass | |
3802 * 4 = Windows Cross Hair | |
3803 * 5 = Windows UP Arrow | |
3804 */ | |
4299 | 3805 # ifdef JSBTERM_MOUSE_NONADVANCED |
3806 /* Disables full feedback of pointer movements */ | |
7 | 3807 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", |
3808 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); | |
4299 | 3809 # else |
7 | 3810 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\", |
3811 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\")); | |
4299 | 3812 # endif |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3813 mouse_ison = TRUE; |
7 | 3814 } |
3815 else | |
3816 { | |
3817 out_str_nf((char_u *)IF_EB("\033[0~ZwQ\033\\", | |
3818 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
|
3819 mouse_ison = FALSE; |
7 | 3820 } |
3821 } | |
3822 # endif | |
3823 # ifdef FEAT_MOUSE_PTERM | |
3824 else | |
3825 { | |
3826 /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ | |
3827 if (on) | |
3828 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); | |
3829 else | |
3830 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
|
3831 mouse_ison = on; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3832 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3833 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3834 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3835 |
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
|
3836 #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
|
3837 /* |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3838 * Called when 'balloonevalterm' changed. |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3839 */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3840 void |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3841 mch_bevalterm_changed(void) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3842 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3843 mch_setmouse(mouse_ison); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3844 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3845 #endif |
7 | 3846 |
3847 /* | |
3848 * Set the mouse termcode, depending on the 'term' and 'ttymouse' options. | |
3849 */ | |
3850 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3851 check_mouse_termcode(void) |
7 | 3852 { |
3853 # ifdef FEAT_MOUSE_XTERM | |
3854 if (use_xterm_mouse() | |
3145 | 3855 # ifdef FEAT_MOUSE_URXVT |
3856 && use_xterm_mouse() != 3 | |
3857 # endif | |
7 | 3858 # ifdef FEAT_GUI |
3859 && !gui.in_use | |
3860 # endif | |
3861 ) | |
3862 { | |
3863 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
180 | 3864 ? IF_EB("\233M", CSI_STR "M") |
3865 : IF_EB("\033[M", ESC_STR "[M"))); | |
7 | 3866 if (*p_mouse != NUL) |
3867 { | |
3868 /* force mouse off and maybe on to send possibly new mouse | |
3869 * activation sequence to the xterm, with(out) drag tracing. */ | |
3870 mch_setmouse(FALSE); | |
3871 setmouse(); | |
3872 } | |
3873 } | |
3874 else | |
3875 del_mouse_termcode(KS_MOUSE); | |
3876 # endif | |
3877 | |
3878 # ifdef FEAT_MOUSE_GPM | |
3879 if (!use_xterm_mouse() | |
3880 # ifdef FEAT_GUI | |
3881 && !gui.in_use | |
3882 # endif | |
3883 ) | |
3884 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MG", ESC_STR "MG")); | |
3885 # endif | |
3886 | |
1620 | 3887 # ifdef FEAT_SYSMOUSE |
3888 if (!use_xterm_mouse() | |
3889 # ifdef FEAT_GUI | |
3890 && !gui.in_use | |
3891 # endif | |
3892 ) | |
3893 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS")); | |
3894 # endif | |
3895 | |
7 | 3896 # ifdef FEAT_MOUSE_JSB |
6102 | 3897 /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ |
7 | 3898 if (!use_xterm_mouse() |
3899 # ifdef FEAT_GUI | |
3900 && !gui.in_use | |
3901 # endif | |
3902 ) | |
3903 set_mouse_termcode(KS_JSBTERM_MOUSE, | |
3904 (char_u *)IF_EB("\033[0~zw", ESC_STR "[0~zw")); | |
3905 else | |
3906 del_mouse_termcode(KS_JSBTERM_MOUSE); | |
3907 # endif | |
3908 | |
3909 # ifdef FEAT_MOUSE_NET | |
180 | 3910 /* There is no conflict, but one may type "ESC }" from Insert mode. Don't |
7 | 3911 * define it in the GUI or when using an xterm. */ |
3912 if (!use_xterm_mouse() | |
3913 # ifdef FEAT_GUI | |
3914 && !gui.in_use | |
3915 # endif | |
3916 ) | |
3917 set_mouse_termcode(KS_NETTERM_MOUSE, | |
3918 (char_u *)IF_EB("\033}", ESC_STR "}")); | |
3919 else | |
3920 del_mouse_termcode(KS_NETTERM_MOUSE); | |
3921 # endif | |
3922 | |
3923 # ifdef FEAT_MOUSE_DEC | |
6102 | 3924 /* Conflicts with xterm mouse: "\033[" and "\033[M" */ |
5932 | 3925 if (!use_xterm_mouse() |
7 | 3926 # ifdef FEAT_GUI |
3927 && !gui.in_use | |
3928 # endif | |
3929 ) | |
180 | 3930 set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME) |
3931 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); | |
7 | 3932 else |
3933 del_mouse_termcode(KS_DEC_MOUSE); | |
3934 # endif | |
3935 # ifdef FEAT_MOUSE_PTERM | |
6102 | 3936 /* same conflict as the dec mouse */ |
5932 | 3937 if (!use_xterm_mouse() |
7 | 3938 # ifdef FEAT_GUI |
3939 && !gui.in_use | |
3940 # endif | |
3941 ) | |
3942 set_mouse_termcode(KS_PTERM_MOUSE, | |
3943 (char_u *) IF_EB("\033[", ESC_STR "[")); | |
3944 else | |
3945 del_mouse_termcode(KS_PTERM_MOUSE); | |
3946 # endif | |
3145 | 3947 # ifdef FEAT_MOUSE_URXVT |
5932 | 3948 if (use_xterm_mouse() == 3 |
3145 | 3949 # ifdef FEAT_GUI |
3950 && !gui.in_use | |
3951 # endif | |
3952 ) | |
3953 { | |
3954 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
|
3955 ? 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
|
3956 : IF_EB("\033[*M", ESC_STR "[*M"))); |
3145 | 3957 |
3958 if (*p_mouse != NUL) | |
3959 { | |
3960 mch_setmouse(FALSE); | |
3961 setmouse(); | |
3962 } | |
3963 } | |
3964 else | |
3965 del_mouse_termcode(KS_URXVT_MOUSE); | |
3966 # endif | |
3746 | 3967 # ifdef FEAT_MOUSE_SGR |
3968 if (use_xterm_mouse() == 4 | |
3969 # ifdef FEAT_GUI | |
3970 && !gui.in_use | |
3971 # endif | |
3972 ) | |
3973 { | |
3974 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
|
3975 ? 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
|
3976 : 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
|
3977 |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3978 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
|
3979 ? 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
|
3980 : IF_EB("\033[<*m", ESC_STR "[<*m"))); |
3746 | 3981 |
3982 if (*p_mouse != NUL) | |
3983 { | |
3984 mch_setmouse(FALSE); | |
3985 setmouse(); | |
3986 } | |
3987 } | |
3988 else | |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3989 { |
3746 | 3990 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
|
3991 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
|
3992 } |
3746 | 3993 # endif |
7 | 3994 } |
3995 #endif | |
3996 | |
3997 /* | |
3998 * set screen mode, always fails. | |
3999 */ | |
4000 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4001 mch_screenmode(char_u *arg UNUSED) |
7 | 4002 { |
4003 EMSG(_(e_screenmode)); | |
4004 return FAIL; | |
4005 } | |
4006 | |
4007 #ifndef VMS | |
4008 | |
4009 /* | |
4010 * Try to get the current window size: | |
4011 * 1. with an ioctl(), most accurate method | |
4012 * 2. from the environment variables LINES and COLUMNS | |
4013 * 3. from the termcap | |
4014 * 4. keep using the old values | |
4015 * Return OK when size could be determined, FAIL otherwise. | |
4016 */ | |
4017 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4018 mch_get_shellsize(void) |
7 | 4019 { |
4020 long rows = 0; | |
4021 long columns = 0; | |
4022 char_u *p; | |
4023 | |
4024 /* | |
4025 * 1. try using an ioctl. It is the most accurate method. | |
4026 * | |
4027 * Try using TIOCGWINSZ first, some systems that have it also define | |
4028 * TIOCGSIZE but don't have a struct ttysize. | |
4029 */ | |
4030 # ifdef TIOCGWINSZ | |
4031 { | |
4032 struct winsize ws; | |
4033 int fd = 1; | |
4034 | |
4035 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
4036 if (!isatty(fd) && isatty(read_cmd_fd)) | |
4037 fd = read_cmd_fd; | |
4038 if (ioctl(fd, TIOCGWINSZ, &ws) == 0) | |
4039 { | |
4040 columns = ws.ws_col; | |
4041 rows = ws.ws_row; | |
4042 } | |
4043 } | |
4044 # else /* TIOCGWINSZ */ | |
4045 # ifdef TIOCGSIZE | |
4046 { | |
4047 struct ttysize ts; | |
4048 int fd = 1; | |
4049 | |
4050 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
4051 if (!isatty(fd) && isatty(read_cmd_fd)) | |
4052 fd = read_cmd_fd; | |
4053 if (ioctl(fd, TIOCGSIZE, &ts) == 0) | |
4054 { | |
4055 columns = ts.ts_cols; | |
4056 rows = ts.ts_lines; | |
4057 } | |
4058 } | |
4059 # endif /* TIOCGSIZE */ | |
4060 # endif /* TIOCGWINSZ */ | |
4061 | |
4062 /* | |
4063 * 2. get size from environment | |
164 | 4064 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules |
4065 * the ioctl() values! | |
7 | 4066 */ |
164 | 4067 if (columns == 0 || rows == 0 || vim_strchr(p_cpo, CPO_TSIZE) != NULL) |
7 | 4068 { |
4069 if ((p = (char_u *)getenv("LINES"))) | |
4070 rows = atoi((char *)p); | |
4071 if ((p = (char_u *)getenv("COLUMNS"))) | |
4072 columns = atoi((char *)p); | |
4073 } | |
4074 | |
4075 #ifdef HAVE_TGETENT | |
4076 /* | |
4077 * 3. try reading "co" and "li" entries from termcap | |
4078 */ | |
4079 if (columns == 0 || rows == 0) | |
4080 getlinecol(&columns, &rows); | |
4081 #endif | |
4082 | |
4083 /* | |
4084 * 4. If everything fails, use the old values | |
4085 */ | |
4086 if (columns <= 0 || rows <= 0) | |
4087 return FAIL; | |
4088 | |
4089 Rows = rows; | |
4090 Columns = columns; | |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
4091 limit_screen_size(); |
7 | 4092 return OK; |
4093 } | |
4094 | |
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
|
4095 #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
|
4096 /* |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4097 * 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
|
4098 */ |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4099 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
|
4100 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
|
4101 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4102 # 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
|
4103 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
|
4104 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4105 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
|
4106 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
|
4107 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
|
4108 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
|
4109 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
|
4110 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4111 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
|
4112 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
|
4113 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4114 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
|
4115 # 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
|
4116 # 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
|
4117 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
|
4118 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4119 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
|
4120 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
|
4121 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
|
4122 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4123 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
|
4124 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
|
4125 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4126 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
|
4127 # 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
|
4128 # 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
|
4129 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
|
4130 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4131 #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
|
4132 |
7 | 4133 /* |
4134 * Try to set the window size to Rows and Columns. | |
4135 */ | |
4136 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4137 mch_set_shellsize(void) |
7 | 4138 { |
4139 if (*T_CWS) | |
4140 { | |
4141 /* | |
4142 * NOTE: if you get an error here that term_set_winsize() is | |
4143 * undefined, check the output of configure. It could probably not | |
4144 * find a ncurses, termcap or termlib library. | |
4145 */ | |
4146 term_set_winsize((int)Rows, (int)Columns); | |
4147 out_flush(); | |
4148 screen_start(); /* don't know where cursor is now */ | |
4149 } | |
4150 } | |
4151 | |
4152 #endif /* VMS */ | |
4153 | |
4154 /* | |
4155 * Rows and/or Columns has changed. | |
4156 */ | |
4157 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4158 mch_new_shellsize(void) |
7 | 4159 { |
4160 /* Nothing to do. */ | |
4161 } | |
4162 | |
3048 | 4163 /* |
4164 * Wait for process "child" to end. | |
4165 * Return "child" if it exited properly, <= 0 on error. | |
4166 */ | |
4167 static pid_t | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4168 wait4pid(pid_t child, waitstatus *status) |
3048 | 4169 { |
4170 pid_t wait_pid = 0; | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4171 long delay_msec = 1; |
3048 | 4172 |
4173 while (wait_pid != child) | |
4174 { | |
3470 | 4175 /* When compiled with Python threads are probably used, in which case |
4176 * wait() sometimes hangs for no obvious reason. Use waitpid() | |
4177 * instead and loop (like the GUI). Also needed for other interfaces, | |
4178 * they might call system(). */ | |
4179 # ifdef __NeXT__ | |
3048 | 4180 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); |
3470 | 4181 # else |
3048 | 4182 wait_pid = waitpid(child, status, WNOHANG); |
3470 | 4183 # endif |
3048 | 4184 if (wait_pid == 0) |
4185 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4186 /* 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
|
4187 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4188 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4189 delay_msec = 10; |
3048 | 4190 continue; |
4191 } | |
4192 if (wait_pid <= 0 | |
4193 # ifdef ECHILD | |
4194 && errno == ECHILD | |
4195 # endif | |
4196 ) | |
4197 break; | |
4198 } | |
4199 return wait_pid; | |
4200 } | |
4201 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4202 #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
|
4203 /* |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4204 * 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
|
4205 */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4206 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
|
4207 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
|
4208 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
|
4209 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
|
4210 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
|
4211 int is_terminal UNUSED) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4212 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4213 # ifdef HAVE_SETENV |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4214 char envbuf[50]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4215 # else |
11717
30247960c8a7
patch 8.0.0741: cannot build with HPUX
Christian Brabandt <cb@256bit.org>
parents:
11713
diff
changeset
|
4216 static char envbuf_Term[30]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4217 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
|
4218 static char envbuf_Lines[20]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4219 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
|
4220 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
|
4221 # 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
|
4222 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
|
4223 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4224 # 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
|
4225 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
|
4226 # 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
|
4227 # 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
|
4228 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
|
4229 # 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
|
4230 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
|
4231 # 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
|
4232 t_colors; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4233 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4234 # ifdef HAVE_SETENV |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4235 setenv("TERM", term, 1); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4236 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4237 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
|
4238 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4239 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
|
4240 sprintf((char *)envbuf, "%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4241 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
|
4242 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
|
4243 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
|
4244 # 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
|
4245 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
|
4246 { |
14073
a9b141cf99ff
patch 8.1.0054: compiler warning for using %ld for "long long"
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
4247 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
|
4248 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
|
4249 } |
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
|
4250 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4251 # 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
|
4252 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
|
4253 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4254 # else |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4255 /* |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4256 * 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
|
4257 * 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
|
4258 * 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
|
4259 */ |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4260 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
|
4261 putenv(envbuf_Term); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4262 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
|
4263 putenv(envbuf_Rows); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4264 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
|
4265 putenv(envbuf_Lines); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4266 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
|
4267 "COLUMNS=%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4268 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
|
4269 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
|
4270 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
|
4271 # 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
|
4272 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
|
4273 { |
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
|
4274 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
|
4275 "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
|
4276 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
|
4277 } |
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
|
4278 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4279 # 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
|
4280 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
|
4281 "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
|
4282 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
|
4283 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4284 # endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4285 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4286 |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4287 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
|
4288 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
|
4289 { |
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
|
4290 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
|
4291 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4292 #endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4293 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4294 #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
|
4295 /* |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4296 * 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
|
4297 * 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
|
4298 * 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
|
4299 */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4300 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
|
4301 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
|
4302 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4303 char *tty_name; |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4304 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4305 *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
|
4306 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
|
4307 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4308 /* 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
|
4309 * 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
|
4310 * 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
|
4311 #ifdef O_NOCTTY |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4312 *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
|
4313 #else |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4314 *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
|
4315 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4316 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
|
4317 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4318 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
|
4319 *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
|
4320 } |
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
|
4321 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
|
4322 *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
|
4323 } |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4324 } |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4325 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4326 |
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
|
4327 /* |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4328 * 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
|
4329 */ |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4330 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
|
4331 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
|
4332 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4333 # 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
|
4334 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
|
4335 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4336 # 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
|
4337 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
|
4338 # 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
|
4339 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
|
4340 # 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
|
4341 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
|
4342 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
|
4343 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4344 # 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
|
4345 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4346 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4347 #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
|
4348 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4349 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
|
4350 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
|
4351 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
|
4352 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
|
4353 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
|
4354 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
|
4355 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4356 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
|
4357 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
|
4358 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4359 *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
|
4360 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
|
4361 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
|
4362 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4363 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
|
4364 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
|
4365 *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
|
4366 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4367 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
|
4368 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4369 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
|
4370 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
|
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 (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
|
4373 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
|
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 /* 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
|
4376 * 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
|
4377 *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
|
4378 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
|
4379 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
|
4380 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
|
4381 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
|
4382 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
|
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 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
|
4385 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
|
4386 *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
|
4387 *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
|
4388 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
|
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 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4391 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
|
4392 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4393 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
|
4394 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
|
4395 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4396 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4397 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4398 #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
|
4399 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4400 * 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
|
4401 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4402 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
|
4403 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
|
4404 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
|
4405 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
|
4406 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4407 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
|
4408 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
|
4409 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
|
4410 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
|
4411 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
|
4412 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
|
4413 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
|
4414 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
|
4415 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
|
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 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
|
4418 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
|
4419 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4420 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
|
4421 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
|
4422 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
|
4423 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
|
4424 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
|
4425 |
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
|
4426 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
|
4427 ++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
|
4428 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4429 /* 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
|
4430 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
|
4431 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4432 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
|
4433 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
|
4434 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4435 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
|
4436 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4437 /* 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
|
4438 * 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
|
4439 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
|
4440 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
|
4441 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4442 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4443 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
|
4444 } |
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
|
4445 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
|
4446 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
|
4447 |
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
|
4448 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
|
4449 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4450 /* 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
|
4451 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
|
4452 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4453 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
|
4454 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
|
4455 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4456 theend: |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4457 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
|
4458 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
|
4459 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
|
4460 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
|
4461 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4462 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4463 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4464 #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
|
4465 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4466 * 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
|
4467 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4468 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
|
4469 mch_call_shell_system( |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4470 char_u *cmd, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4471 int options) /* SHELL_*, see vim.h */ |
7 | 4472 { |
4473 #ifdef VMS | |
4474 char *ifn = NULL; | |
4475 char *ofn = NULL; | |
4476 #endif | |
4477 int tmode = cur_tmode; | |
9552
49512aba8e32
commit https://github.com/vim/vim/commit/b2b050ab16565c117f0e7e411ffef3700d99203b
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
4478 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
|
4479 int x; |
7 | 4480 |
4481 out_flush(); | |
4482 | |
4483 if (options & SHELL_COOKED) | |
4484 settmode(TMODE_COOK); /* set to normal mode */ | |
4485 | |
2586 | 4486 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4209 | 4487 save_clipboard(); |
2586 | 4488 loose_clipboard(); |
4489 # endif | |
4490 | |
7 | 4491 if (cmd == NULL) |
4492 x = system((char *)p_sh); | |
4493 else | |
4494 { | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4495 # ifdef VMS |
7 | 4496 if (ofn = strchr((char *)cmd, '>')) |
4497 *ofn++ = '\0'; | |
4498 if (ifn = strchr((char *)cmd, '<')) | |
4499 { | |
4500 char *p; | |
4501 | |
4502 *ifn++ = '\0'; | |
4503 p = strchr(ifn,' '); /* chop off any trailing spaces */ | |
4504 if (p) | |
4505 *p = '\0'; | |
4506 } | |
4507 if (ofn) | |
4508 x = vms_sys((char *)cmd, ofn, ifn); | |
4509 else | |
4510 x = system((char *)cmd); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4511 # else |
7 | 4512 newcmd = lalloc(STRLEN(p_sh) |
4513 + (extra_shell_arg == NULL ? 0 : STRLEN(extra_shell_arg)) | |
4514 + STRLEN(p_shcf) + STRLEN(cmd) + 4, TRUE); | |
4515 if (newcmd == NULL) | |
4516 x = 0; | |
4517 else | |
4518 { | |
4519 sprintf((char *)newcmd, "%s %s %s %s", p_sh, | |
4520 extra_shell_arg == NULL ? "" : (char *)extra_shell_arg, | |
4521 (char *)p_shcf, | |
4522 (char *)cmd); | |
4523 x = system((char *)newcmd); | |
4524 vim_free(newcmd); | |
4525 } | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4526 # endif |
7 | 4527 } |
4528 # ifdef VMS | |
4529 x = vms_sys_status(x); | |
4530 # endif | |
4531 if (emsg_silent) | |
4532 ; | |
4533 else if (x == 127) | |
4534 MSG_PUTS(_("\nCannot execute shell sh\n")); | |
4535 else if (x && !(options & SHELL_SILENT)) | |
4536 { | |
4537 MSG_PUTS(_("\nshell returned ")); | |
4538 msg_outnum((long)x); | |
4539 msg_putchar('\n'); | |
4540 } | |
4541 | |
4542 if (tmode == TMODE_RAW) | |
4543 settmode(TMODE_RAW); /* set to raw mode */ | |
4544 # ifdef FEAT_TITLE | |
4545 resettitle(); | |
4546 # endif | |
4209 | 4547 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4548 restore_clipboard(); | |
4549 # endif | |
7 | 4550 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
|
4551 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4552 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4553 #else /* USE_SYSTEM */ |
7 | 4554 |
167 | 4555 # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use |
4556 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
|
4557 # define OPEN_NULL_FAILED 123 /* Exit code if /dev/null can't be opened */ |
7 | 4558 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4559 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4560 * 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
|
4561 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4562 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
|
4563 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
|
4564 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
|
4565 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
|
4566 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4567 int tmode = cur_tmode; |
7 | 4568 pid_t pid; |
167 | 4569 pid_t wpid = 0; |
7 | 4570 pid_t wait_pid = 0; |
4571 # ifdef HAVE_UNION_WAIT | |
4572 union wait status; | |
4573 # else | |
4574 int status = -1; | |
4575 # endif | |
4576 int retval = -1; | |
4577 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
|
4578 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
|
4579 char_u *tofree2 = NULL; |
7 | 4580 int i; |
167 | 4581 int pty_master_fd = -1; /* for pty's */ |
7 | 4582 # ifdef FEAT_GUI |
4583 int pty_slave_fd = -1; | |
167 | 4584 # endif |
602 | 4585 int fd_toshell[2]; /* for pipes */ |
7 | 4586 int fd_fromshell[2]; |
4587 int pipe_error = FALSE; | |
602 | 4588 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ |
7 | 4589 |
4590 out_flush(); | |
4591 if (options & SHELL_COOKED) | |
4592 settmode(TMODE_COOK); /* set to normal mode */ | |
4593 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4594 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
|
4595 goto error; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4596 |
167 | 4597 /* |
4598 * For the GUI, when writing the output into the buffer and when reading | |
4599 * input from the buffer: Try using a pseudo-tty to get the stdin/stdout | |
4600 * of the executed command into the Vim window. Or use a pipe. | |
4601 */ | |
4602 if ((options & (SHELL_READ|SHELL_WRITE)) | |
7 | 4603 # ifdef FEAT_GUI |
167 | 4604 || (gui.in_use && show_shell_mess) |
4605 # endif | |
4606 ) | |
7 | 4607 { |
167 | 4608 # ifdef FEAT_GUI |
7 | 4609 /* |
4610 * Try to open a master pty. | |
4611 * If this works, open the slave pty. | |
4612 * If the slave can't be opened, close the master pty. | |
4613 */ | |
167 | 4614 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
|
4615 open_pty(&pty_master_fd, &pty_slave_fd, NULL); |
7 | 4616 /* |
4617 * If not opening a pty or it didn't work, try using pipes. | |
4618 */ | |
4619 if (pty_master_fd < 0) | |
167 | 4620 # endif |
7 | 4621 { |
4622 pipe_error = (pipe(fd_toshell) < 0); | |
4623 if (!pipe_error) /* pipe create OK */ | |
4624 { | |
4625 pipe_error = (pipe(fd_fromshell) < 0); | |
4626 if (pipe_error) /* pipe create failed */ | |
4627 { | |
4628 close(fd_toshell[0]); | |
4629 close(fd_toshell[1]); | |
4630 } | |
4631 } | |
4632 if (pipe_error) | |
4633 { | |
4634 MSG_PUTS(_("\nCannot create pipes\n")); | |
4635 out_flush(); | |
4636 } | |
4637 } | |
4638 } | |
4639 | |
4640 if (!pipe_error) /* pty or pipe opened or not used */ | |
4641 { | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4642 SIGSET_DECL(curset) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4643 |
7 | 4644 # ifdef __BEOS__ |
4645 beos_cleanup_read_thread(); | |
4646 # endif | |
602 | 4647 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4648 BLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4649 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
|
4650 if (pid == -1) |
7 | 4651 { |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4652 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4653 |
7 | 4654 MSG_PUTS(_("\nCannot fork\n")); |
167 | 4655 if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4656 # ifdef FEAT_GUI |
167 | 4657 || (gui.in_use && show_shell_mess) |
4658 # endif | |
4659 ) | |
7 | 4660 { |
167 | 4661 # ifdef FEAT_GUI |
7 | 4662 if (pty_master_fd >= 0) /* close the pseudo tty */ |
4663 { | |
4664 close(pty_master_fd); | |
4665 close(pty_slave_fd); | |
4666 } | |
4667 else /* close the pipes */ | |
167 | 4668 # endif |
7 | 4669 { |
4670 close(fd_toshell[0]); | |
4671 close(fd_toshell[1]); | |
4672 close(fd_fromshell[0]); | |
4673 close(fd_fromshell[1]); | |
4674 } | |
4675 } | |
4676 } | |
4677 else if (pid == 0) /* child */ | |
4678 { | |
4679 reset_signals(); /* handle signals normally */ | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4680 UNBLOCK_SIGNALS(&curset); |
7 | 4681 |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4682 # 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
|
4683 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
|
4684 /* 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
|
4685 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
|
4686 # endif |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4687 |
7 | 4688 if (!show_shell_mess || (options & SHELL_EXPAND)) |
4689 { | |
4690 int fd; | |
4691 | |
4692 /* | |
4693 * Don't want to show any message from the shell. Can't just | |
4694 * close stdout and stderr though, because some systems will | |
4695 * break if you try to write to them after that, so we must | |
4696 * use dup() to replace them with something else -- webb | |
4697 * Connect stdin to /dev/null too, so ":n `cat`" doesn't hang, | |
4698 * waiting for input. | |
4699 */ | |
4700 fd = open("/dev/null", O_RDWR | O_EXTRA, 0); | |
4701 fclose(stdin); | |
4702 fclose(stdout); | |
4703 fclose(stderr); | |
4704 | |
4705 /* | |
4706 * If any of these open()'s and dup()'s fail, we just continue | |
4707 * anyway. It's not fatal, and on most systems it will make | |
4708 * no difference at all. On a few it will cause the execvp() | |
4709 * to exit with a non-zero status even when the completion | |
4710 * could be done, which is nothing too serious. If the open() | |
4711 * or dup() failed we'd just do the same thing ourselves | |
4712 * anyway -- webb | |
4713 */ | |
4714 if (fd >= 0) | |
4715 { | |
1757 | 4716 ignored = dup(fd); /* To replace stdin (fd 0) */ |
4717 ignored = dup(fd); /* To replace stdout (fd 1) */ | |
4718 ignored = dup(fd); /* To replace stderr (fd 2) */ | |
7 | 4719 |
4720 /* Don't need this now that we've duplicated it */ | |
4721 close(fd); | |
4722 } | |
4723 } | |
167 | 4724 else if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4725 # ifdef FEAT_GUI |
167 | 4726 || gui.in_use |
4727 # endif | |
4728 ) | |
7 | 4729 { |
4730 | |
167 | 4731 # ifdef HAVE_SETSID |
602 | 4732 /* Create our own process group, so that the child and all its |
4733 * children can be kill()ed. Don't do this when using pipes, | |
1698 | 4734 * because stdin is not a tty, we would lose /dev/tty. */ |
602 | 4735 if (p_stmp) |
1799 | 4736 { |
602 | 4737 (void)setsid(); |
1799 | 4738 # if defined(SIGHUP) |
4739 /* When doing "!xterm&" and 'shell' is bash: the shell | |
4740 * will exit and send SIGHUP to all processes in its | |
4741 * group, killing the just started process. Ignore SIGHUP | |
4742 * to avoid that. (suggested by Simon Schubert) | |
4743 */ | |
4744 signal(SIGHUP, SIG_IGN); | |
4745 # endif | |
4746 } | |
167 | 4747 # endif |
4748 # ifdef FEAT_GUI | |
602 | 4749 if (pty_slave_fd >= 0) |
4750 { | |
4751 /* push stream discipline modules */ | |
4752 if (options & SHELL_COOKED) | |
4753 SetupSlavePTY(pty_slave_fd); | |
7 | 4754 # ifdef TIOCSCTTY |
602 | 4755 /* Try to become controlling tty (probably doesn't work, |
4756 * unless run by root) */ | |
4757 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); | |
7 | 4758 # endif |
602 | 4759 } |
167 | 4760 # 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
|
4761 set_default_child_environment(FALSE); |
167 | 4762 |
557 | 4763 /* |
4764 * stderr is only redirected when using the GUI, so that a | |
4765 * program like gpg can still access the terminal to get a | |
4766 * passphrase using stderr. | |
4767 */ | |
167 | 4768 # ifdef FEAT_GUI |
7 | 4769 if (pty_master_fd >= 0) |
4770 { | |
4771 close(pty_master_fd); /* close master side of pty */ | |
4772 | |
4773 /* set up stdin/stdout/stderr for the child */ | |
4774 close(0); | |
1757 | 4775 ignored = dup(pty_slave_fd); |
7 | 4776 close(1); |
1757 | 4777 ignored = dup(pty_slave_fd); |
557 | 4778 if (gui.in_use) |
4779 { | |
4780 close(2); | |
1757 | 4781 ignored = dup(pty_slave_fd); |
557 | 4782 } |
7 | 4783 |
4784 close(pty_slave_fd); /* has been dupped, close it now */ | |
4785 } | |
4786 else | |
167 | 4787 # endif |
7 | 4788 { |
4789 /* set up stdin for the child */ | |
4790 close(fd_toshell[1]); | |
4791 close(0); | |
1757 | 4792 ignored = dup(fd_toshell[0]); |
7 | 4793 close(fd_toshell[0]); |
4794 | |
4795 /* set up stdout for the child */ | |
4796 close(fd_fromshell[0]); | |
4797 close(1); | |
1757 | 4798 ignored = dup(fd_fromshell[1]); |
7 | 4799 close(fd_fromshell[1]); |
4800 | |
557 | 4801 # ifdef FEAT_GUI |
4802 if (gui.in_use) | |
4803 { | |
4804 /* set up stderr for the child */ | |
4805 close(2); | |
1757 | 4806 ignored = dup(1); |
557 | 4807 } |
4808 # endif | |
7 | 4809 } |
4810 } | |
167 | 4811 |
7 | 4812 /* |
4813 * There is no type cast for the argv, because the type may be | |
4814 * different on different machines. This may cause a warning | |
4815 * message with strict compilers, don't worry about it. | |
4816 * Call _exit() instead of exit() to avoid closing the connection | |
4817 * to the X server (esp. with GTK, which uses atexit()). | |
4818 */ | |
4819 execvp(argv[0], argv); | |
4820 _exit(EXEC_FAILED); /* exec failed, return failure code */ | |
4821 } | |
4822 else /* parent */ | |
4823 { | |
4824 /* | |
4825 * While child is running, ignore terminating signals. | |
167 | 4826 * Do catch CTRL-C, so that "got_int" is set. |
7 | 4827 */ |
4828 catch_signals(SIG_IGN, SIG_ERR); | |
167 | 4829 catch_int_signal(); |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4830 UNBLOCK_SIGNALS(&curset); |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4831 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4832 ++dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4833 # endif |
7 | 4834 /* |
4835 * For the GUI we redirect stdin, stdout and stderr to our window. | |
167 | 4836 * This is also used to pipe stdin/stdout to/from the external |
4837 * command. | |
7 | 4838 */ |
167 | 4839 if ((options & (SHELL_READ|SHELL_WRITE)) |
4840 # ifdef FEAT_GUI | |
4841 || (gui.in_use && show_shell_mess) | |
4842 # endif | |
4843 ) | |
7 | 4844 { |
167 | 4845 # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ |
7 | 4846 char_u buffer[BUFLEN + 1]; |
167 | 4847 # ifdef FEAT_MBYTE |
7 | 4848 int buffer_off = 0; /* valid bytes in buffer[] */ |
167 | 4849 # endif |
7 | 4850 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ |
4851 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4852 int len; | |
4853 int p_more_save; | |
4854 int old_State; | |
4855 int c; | |
4856 int toshell_fd; | |
4857 int fromshell_fd; | |
167 | 4858 garray_T ga; |
4859 int noread_cnt; | |
1823 | 4860 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) |
4861 struct timeval start_tv; | |
4862 # endif | |
167 | 4863 |
4864 # ifdef FEAT_GUI | |
7 | 4865 if (pty_master_fd >= 0) |
4866 { | |
4867 fromshell_fd = pty_master_fd; | |
4868 toshell_fd = dup(pty_master_fd); | |
4869 } | |
4870 else | |
167 | 4871 # endif |
7 | 4872 { |
4873 close(fd_toshell[0]); | |
4874 close(fd_fromshell[1]); | |
4875 toshell_fd = fd_toshell[1]; | |
4876 fromshell_fd = fd_fromshell[0]; | |
4877 } | |
4878 | |
4879 /* | |
4880 * Write to the child if there are typed characters. | |
4881 * Read from the child if there are characters available. | |
4882 * Repeat the reading a few times if more characters are | |
4883 * available. Need to check for typed keys now and then, but | |
4884 * not too often (delays when no chars are available). | |
4885 * This loop is quit if no characters can be read from the pty | |
4886 * (WaitForChar detected special condition), or there are no | |
4887 * characters available and the child has exited. | |
4888 * Only check if the child has exited when there is no more | |
4889 * output. The child may exit before all the output has | |
4890 * been printed. | |
4891 * | |
4892 * Currently this busy loops! | |
4893 * This can probably dead-lock when the write blocks! | |
4894 */ | |
4895 p_more_save = p_more; | |
4896 p_more = FALSE; | |
4897 old_State = State; | |
4898 State = EXTERNCMD; /* don't redraw at window resize */ | |
4899 | |
602 | 4900 if ((options & SHELL_WRITE) && toshell_fd >= 0) |
167 | 4901 { |
4902 /* Fork a process that will write the lines to the | |
4903 * external program. */ | |
4904 if ((wpid = fork()) == -1) | |
4905 { | |
4906 MSG_PUTS(_("\nCannot fork\n")); | |
4907 } | |
3048 | 4908 else if (wpid == 0) /* child */ |
167 | 4909 { |
4910 linenr_T lnum = curbuf->b_op_start.lnum; | |
4911 int written = 0; | |
944 | 4912 char_u *lp = ml_get(lnum); |
167 | 4913 size_t l; |
4914 | |
177 | 4915 close(fromshell_fd); |
167 | 4916 for (;;) |
4917 { | |
944 | 4918 l = STRLEN(lp + written); |
167 | 4919 if (l == 0) |
4920 len = 0; | |
944 | 4921 else if (lp[written] == NL) |
167 | 4922 /* NL -> NUL translation */ |
4923 len = write(toshell_fd, "", (size_t)1); | |
4924 else | |
4925 { | |
3263 | 4926 char_u *s = vim_strchr(lp + written, NL); |
4927 | |
944 | 4928 len = write(toshell_fd, (char *)lp + written, |
1877 | 4929 s == NULL ? l |
4930 : (size_t)(s - (lp + written))); | |
167 | 4931 } |
1877 | 4932 if (len == (int)l) |
167 | 4933 { |
4934 /* Finished a line, add a NL, unless this line | |
4935 * should not have one. */ | |
4936 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4937 || (!curbuf->b_p_bin |
4938 && curbuf->b_p_fixeol) | |
2707 | 4939 || (lnum != curbuf->b_no_eol_lnum |
167 | 4940 && (lnum != |
4941 curbuf->b_ml.ml_line_count | |
4942 || curbuf->b_p_eol))) | |
1757 | 4943 ignored = write(toshell_fd, "\n", |
4944 (size_t)1); | |
167 | 4945 ++lnum; |
4946 if (lnum > curbuf->b_op_end.lnum) | |
4947 { | |
4948 /* finished all the lines, close pipe */ | |
4949 close(toshell_fd); | |
4950 toshell_fd = -1; | |
4951 break; | |
4952 } | |
944 | 4953 lp = ml_get(lnum); |
167 | 4954 written = 0; |
4955 } | |
4956 else if (len > 0) | |
4957 written += len; | |
4958 } | |
4959 _exit(0); | |
4960 } | |
3048 | 4961 else /* parent */ |
167 | 4962 { |
4963 close(toshell_fd); | |
4964 toshell_fd = -1; | |
4965 } | |
4966 } | |
4967 | |
4968 if (options & SHELL_READ) | |
4969 ga_init2(&ga, 1, BUFLEN); | |
4970 | |
4971 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4972 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4973 ELAPSED_INIT(start_tv); |
1823 | 4974 # endif |
7 | 4975 for (;;) |
4976 { | |
4977 /* | |
4978 * Check if keys have been typed, write them to the child | |
592 | 4979 * if there are any. |
4980 * Don't do this if we are expanding wild cards (would eat | |
4981 * typeahead). | |
4982 * Don't do this when filtering and terminal is in cooked | |
4983 * mode, the shell command will handle the I/O. Avoids | |
4984 * that a typed password is echoed for ssh or gpg command. | |
602 | 4985 * Don't get characters when the child has already |
4986 * finished (wait_pid == 0). | |
167 | 4987 * Don't read characters unless we didn't get output for a |
1823 | 4988 * while (noread_cnt > 4), avoids that ":r !ls" eats |
4989 * typeahead. | |
7 | 4990 */ |
4991 len = 0; | |
4992 if (!(options & SHELL_EXPAND) | |
592 | 4993 && ((options & |
4994 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4995 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
1823 | 4996 # ifdef FEAT_GUI |
592 | 4997 || gui.in_use |
1823 | 4998 # endif |
592 | 4999 ) |
602 | 5000 && wait_pid == 0 |
1823 | 5001 && (ta_len > 0 || noread_cnt > 4)) |
7 | 5002 { |
1823 | 5003 if (ta_len == 0) |
5004 { | |
5005 /* Get extra characters when we don't have any. | |
5006 * Reset the counter and timer. */ | |
5007 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5008 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5009 ELAPSED_INIT(start_tv); |
1823 | 5010 # endif |
5011 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
5012 } | |
5013 if (ta_len > 0 || len > 0) | |
5014 { | |
7 | 5015 /* |
5016 * For pipes: | |
5017 * Check for CTRL-C: send interrupt signal to child. | |
5018 * Check for CTRL-D: EOF, close pipe to child. | |
5019 */ | |
5020 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) | |
5021 { | |
5022 /* | |
5023 * Send SIGINT to the child's group or all | |
5024 * processes in our group. | |
5025 */ | |
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
|
5026 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
|
5027 |
7 | 5028 if (pty_master_fd < 0 && toshell_fd >= 0 |
5029 && ta_buf[ta_len] == Ctrl_D) | |
5030 { | |
5031 close(toshell_fd); | |
5032 toshell_fd = -1; | |
5033 } | |
5034 } | |
5035 | |
5036 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
5037 for (i = ta_len; i < ta_len + len; ++i) | |
5038 { | |
5039 if (ta_buf[i] == CSI && len - i > 2) | |
5040 { | |
5041 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
5042 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
5043 { | |
5044 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
5045 (size_t)(len - i - 2)); | |
5046 if (c == K_DEL || c == K_KDEL) | |
5047 ta_buf[i] = DEL; | |
5048 else | |
5049 ta_buf[i] = Ctrl_H; | |
5050 len -= 2; | |
5051 } | |
5052 } | |
5053 else if (ta_buf[i] == '\r') | |
5054 ta_buf[i] = '\n'; | |
167 | 5055 # ifdef FEAT_MBYTE |
7 | 5056 if (has_mbyte) |
1903 | 5057 i += (*mb_ptr2len_len)(ta_buf + i, |
5058 ta_len + len - i) - 1; | |
167 | 5059 # endif |
7 | 5060 } |
5061 | |
5062 /* | |
5063 * For pipes: echo the typed characters. | |
5064 * For a pty this does not seem to work. | |
5065 */ | |
5066 if (pty_master_fd < 0) | |
5067 { | |
5068 for (i = ta_len; i < ta_len + len; ++i) | |
5069 { | |
5070 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
5071 msg_putchar(ta_buf[i]); | |
167 | 5072 # ifdef FEAT_MBYTE |
7 | 5073 else if (has_mbyte) |
5074 { | |
474 | 5075 int l = (*mb_ptr2len)(ta_buf + i); |
7 | 5076 |
5077 msg_outtrans_len(ta_buf + i, l); | |
5078 i += l - 1; | |
5079 } | |
167 | 5080 # endif |
7 | 5081 else |
5082 msg_outtrans_len(ta_buf + i, 1); | |
5083 } | |
5084 windgoto(msg_row, msg_col); | |
5085 out_flush(); | |
5086 } | |
5087 | |
5088 ta_len += len; | |
5089 | |
5090 /* | |
5091 * Write the characters to the child, unless EOF has | |
5092 * been typed for pipes. Write one character at a | |
1698 | 5093 * time, to avoid losing too much typeahead. |
167 | 5094 * When writing buffer lines, drop the typed |
5095 * characters (only check for CTRL-C). | |
7 | 5096 */ |
167 | 5097 if (options & SHELL_WRITE) |
5098 ta_len = 0; | |
5099 else if (toshell_fd >= 0) | |
7 | 5100 { |
5101 len = write(toshell_fd, (char *)ta_buf, (size_t)1); | |
5102 if (len > 0) | |
5103 { | |
5104 ta_len -= len; | |
5105 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
5106 } | |
5107 } | |
1823 | 5108 } |
7 | 5109 } |
5110 | |
167 | 5111 if (got_int) |
5112 { | |
5113 /* CTRL-C sends a signal to the child, we ignore it | |
5114 * ourselves */ | |
5115 # ifdef HAVE_SETSID | |
5116 kill(-pid, SIGINT); | |
5117 # else | |
5118 kill(0, SIGINT); | |
5119 # endif | |
5120 if (wpid > 0) | |
5121 kill(wpid, SIGINT); | |
5122 got_int = FALSE; | |
5123 } | |
5124 | |
7 | 5125 /* |
5126 * Check if the child has any characters to be printed. | |
5127 * Read them and write them to our window. Repeat this as | |
5128 * long as there is something to do, avoid the 10ms wait | |
5129 * for mch_inchar(), or sending typeahead characters to | |
5130 * the external process. | |
5131 * TODO: This should handle escape sequences, compatible | |
5132 * to some terminal (vt52?). | |
5133 */ | |
167 | 5134 ++noread_cnt; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5135 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL)) |
7 | 5136 { |
2664 | 5137 len = read_eintr(fromshell_fd, buffer |
167 | 5138 # ifdef FEAT_MBYTE |
7 | 5139 + buffer_off, (size_t)(BUFLEN - buffer_off) |
167 | 5140 # else |
7 | 5141 , (size_t)BUFLEN |
167 | 5142 # endif |
7 | 5143 ); |
5144 if (len <= 0) /* end of file or error */ | |
5145 goto finished; | |
167 | 5146 |
5147 noread_cnt = 0; | |
5148 if (options & SHELL_READ) | |
5149 { | |
5150 /* Do NUL -> NL translation, append NL separated | |
5151 * lines to the current buffer. */ | |
5152 for (i = 0; i < len; ++i) | |
5153 { | |
5154 if (buffer[i] == NL) | |
5155 append_ga_line(&ga); | |
5156 else if (buffer[i] == NUL) | |
5157 ga_append(&ga, NL); | |
5158 else | |
5159 ga_append(&ga, buffer[i]); | |
5160 } | |
5161 } | |
5162 # ifdef FEAT_MBYTE | |
5163 else if (has_mbyte) | |
7 | 5164 { |
5165 int l; | |
13478
601d797cca88
patch 8.0.1613: warning for unused variable in tiny build
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
5166 char_u *p; |
7 | 5167 |
167 | 5168 len += buffer_off; |
5169 buffer[len] = NUL; | |
5170 | |
7 | 5171 /* Check if the last character in buffer[] is |
5172 * incomplete, keep these bytes for the next | |
5173 * round. */ | |
5174 for (p = buffer; p < buffer + len; p += l) | |
5175 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9873
diff
changeset
|
5176 l = MB_CPTR2LEN(p); |
7 | 5177 if (l == 0) |
5178 l = 1; /* NUL byte? */ | |
5179 else if (MB_BYTE2LEN(*p) != l) | |
5180 break; | |
5181 } | |
5182 if (p == buffer) /* no complete character */ | |
5183 { | |
5184 /* avoid getting stuck at an illegal byte */ | |
5185 if (len >= 12) | |
5186 ++p; | |
5187 else | |
5188 { | |
5189 buffer_off = len; | |
5190 continue; | |
5191 } | |
5192 } | |
5193 c = *p; | |
5194 *p = NUL; | |
5195 msg_puts(buffer); | |
5196 if (p < buffer + len) | |
5197 { | |
5198 *p = c; | |
5199 buffer_off = (buffer + len) - p; | |
5200 mch_memmove(buffer, p, buffer_off); | |
5201 continue; | |
5202 } | |
5203 buffer_off = 0; | |
5204 } | |
167 | 5205 # endif /* FEAT_MBYTE */ |
7 | 5206 else |
5207 { | |
5208 buffer[len] = NUL; | |
5209 msg_puts(buffer); | |
5210 } | |
5211 | |
5212 windgoto(msg_row, msg_col); | |
5213 cursor_on(); | |
5214 out_flush(); | |
5215 if (got_int) | |
5216 break; | |
1823 | 5217 |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5218 # ifdef ELAPSED_FUNC |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5219 if (wait_pid == 0) |
1823 | 5220 { |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5221 long msec = ELAPSED_FUNC(start_tv); |
1823 | 5222 |
5223 /* Avoid that we keep looping here without | |
5224 * checking for a CTRL-C for a long time. Don't | |
5225 * break out too often to avoid losing typeahead. */ | |
5226 if (msec > 2000) | |
5227 { | |
5228 noread_cnt = 5; | |
5229 break; | |
5230 } | |
5231 } | |
5232 # endif | |
7 | 5233 } |
5234 | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5235 /* 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
|
5236 * 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
|
5237 * buffered. */ |
602 | 5238 if (wait_pid == pid) |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5239 { |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5240 if (noread_cnt < 5) |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5241 continue; |
602 | 5242 break; |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5243 } |
602 | 5244 |
7 | 5245 /* |
5246 * Check if the child still exists, before checking for | |
1698 | 5247 * typed characters (otherwise we would lose typeahead). |
7 | 5248 */ |
167 | 5249 # ifdef __NeXT__ |
3048 | 5250 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); |
167 | 5251 # else |
7 | 5252 wait_pid = waitpid(pid, &status, WNOHANG); |
167 | 5253 # endif |
7 | 5254 if ((wait_pid == (pid_t)-1 && errno == ECHILD) |
5255 || (wait_pid == pid && WIFEXITED(status))) | |
5256 { | |
602 | 5257 /* Don't break the loop yet, try reading more |
5258 * characters from "fromshell_fd" first. When using | |
5259 * pipes there might still be something to read and | |
5260 * then we'll break the loop at the "break" above. */ | |
7 | 5261 wait_pid = pid; |
5262 } | |
602 | 5263 else |
5264 wait_pid = 0; | |
4230 | 5265 |
4248 | 5266 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5267 /* Handle any X events, e.g. serving the clipboard. */ |
5268 clip_update(); | |
5269 # endif | |
7 | 5270 } |
5271 finished: | |
5272 p_more = p_more_save; | |
167 | 5273 if (options & SHELL_READ) |
5274 { | |
5275 if (ga.ga_len > 0) | |
5276 { | |
5277 append_ga_line(&ga); | |
5278 /* remember that the NL was missing */ | |
2707 | 5279 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
167 | 5280 } |
5281 else | |
2707 | 5282 curbuf->b_no_eol_lnum = 0; |
167 | 5283 ga_clear(&ga); |
5284 } | |
5285 | |
7 | 5286 /* |
5287 * Give all typeahead that wasn't used back to ui_inchar(). | |
5288 */ | |
5289 if (ta_len) | |
5290 ui_inchar_undo(ta_buf, ta_len); | |
5291 State = old_State; | |
5292 if (toshell_fd >= 0) | |
5293 close(toshell_fd); | |
5294 close(fromshell_fd); | |
5295 } | |
4248 | 5296 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5297 else |
5298 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5299 long delay_msec = 1; |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5300 |
4230 | 5301 /* |
5302 * Similar to the loop above, but only handle X events, no | |
5303 * I/O. | |
5304 */ | |
5305 for (;;) | |
5306 { | |
5307 if (got_int) | |
5308 { | |
5309 /* CTRL-C sends a signal to the child, we ignore it | |
5310 * ourselves */ | |
5311 # ifdef HAVE_SETSID | |
5312 kill(-pid, SIGINT); | |
5313 # else | |
5314 kill(0, SIGINT); | |
5315 # endif | |
5316 got_int = FALSE; | |
5317 } | |
5318 # ifdef __NeXT__ | |
5319 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); | |
5320 # else | |
5321 wait_pid = waitpid(pid, &status, WNOHANG); | |
5322 # endif | |
5323 if ((wait_pid == (pid_t)-1 && errno == ECHILD) | |
5324 || (wait_pid == pid && WIFEXITED(status))) | |
5325 { | |
5326 wait_pid = pid; | |
5327 break; | |
5328 } | |
5329 | |
5330 /* Handle any X events, e.g. serving the clipboard. */ | |
5331 clip_update(); | |
5332 | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5333 /* 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
|
5334 * less time. */ |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5335 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5336 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5337 delay_msec = 10; |
4230 | 5338 } |
5339 } | |
5340 # endif | |
7 | 5341 |
5342 /* | |
5343 * Wait until our child has exited. | |
5344 * Ignore wait() returning pids of other children and returning | |
5345 * because of some signal like SIGWINCH. | |
5346 * Don't wait if wait_pid was already set above, indicating the | |
5347 * child already exited. | |
5348 */ | |
3048 | 5349 if (wait_pid != pid) |
5350 wait_pid = wait4pid(pid, &status); | |
7 | 5351 |
2600 | 5352 # ifdef FEAT_GUI |
5353 /* Close slave side of pty. Only do this after the child has | |
5354 * exited, otherwise the child may hang when it tries to write on | |
5355 * the pty. */ | |
5356 if (pty_master_fd >= 0) | |
5357 close(pty_slave_fd); | |
5358 # endif | |
5359 | |
167 | 5360 /* Make sure the child that writes to the external program is |
5361 * dead. */ | |
5362 if (wpid > 0) | |
3048 | 5363 { |
167 | 5364 kill(wpid, SIGKILL); |
3048 | 5365 wait4pid(wpid, NULL); |
5366 } | |
167 | 5367 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5368 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5369 --dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5370 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5371 |
7 | 5372 /* |
5373 * Set to raw mode right now, otherwise a CTRL-C after | |
5374 * catch_signals() will kill Vim. | |
5375 */ | |
5376 if (tmode == TMODE_RAW) | |
5377 settmode(TMODE_RAW); | |
5378 did_settmode = TRUE; | |
5379 set_signals(); | |
5380 | |
5381 if (WIFEXITED(status)) | |
5382 { | |
129 | 5383 /* LINTED avoid "bitwise operation on signed value" */ |
7 | 5384 retval = WEXITSTATUS(status); |
4074 | 5385 if (retval != 0 && !emsg_silent) |
7 | 5386 { |
5387 if (retval == EXEC_FAILED) | |
5388 { | |
5389 MSG_PUTS(_("\nCannot execute shell ")); | |
5390 msg_outtrans(p_sh); | |
5391 msg_putchar('\n'); | |
5392 } | |
5393 else if (!(options & SHELL_SILENT)) | |
5394 { | |
5395 MSG_PUTS(_("\nshell returned ")); | |
5396 msg_outnum((long)retval); | |
5397 msg_putchar('\n'); | |
5398 } | |
5399 } | |
5400 } | |
5401 else | |
5402 MSG_PUTS(_("\nCommand terminated\n")); | |
5403 } | |
5404 } | |
5405 | |
5406 error: | |
5407 if (!did_settmode) | |
5408 if (tmode == TMODE_RAW) | |
5409 settmode(TMODE_RAW); /* set to raw mode */ | |
5410 # ifdef FEAT_TITLE | |
5411 resettitle(); | |
5412 # 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
|
5413 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
|
5414 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
|
5415 vim_free(tofree2); |
7 | 5416 |
5417 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
|
5418 } |
7 | 5419 #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
|
5420 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5421 int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5422 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
|
5423 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
|
5424 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
|
5425 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5426 #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
|
5427 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
|
5428 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
|
5429 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5430 #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
|
5431 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
|
5432 #else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5433 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
|
5434 #endif |
7 | 5435 } |
5436 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5437 #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
|
5438 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
|
5439 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
|
5440 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5441 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
|
5442 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
|
5443 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
|
5444 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
|
5445 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
|
5446 int pty_slave_fd = -1; |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
5447 channel_T *channel = NULL; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5448 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
|
5449 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
|
5450 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
|
5451 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
|
5452 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
|
5453 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
|
5454 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
|
5455 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
|
5456 SIGSET_DECL(curset) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5457 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5458 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
|
5459 use_null_for_err = TRUE; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5460 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5461 /* default is to fail */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5462 job->jv_status = JOB_FAILED; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5463 |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5464 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
|
5465 && (!(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
|
5466 || !(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
|
5467 || !(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
|
5468 { |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5469 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
|
5470 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
|
5471 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
|
5472 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5473 |
8068
9c6740f2204f
commit https://github.com/vim/vim/commit/12dcf024e90ab511f04a08b20fe7eedbe92096d2
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5474 /* 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
|
5475 /* 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
|
5476 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5477 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5478 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
|
5479 |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5480 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
|
5481 if (fd_in[0] < 0) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5482 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5483 EMSG2(_(e_notopen), fname); |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5484 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5485 } |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5486 } |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5487 else |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5488 /* 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
|
5489 * 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
|
5490 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
|
5491 && 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
|
5492 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5493 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5494 if (use_file_for_out) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5495 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5496 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
|
5497 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5498 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
|
5499 if (fd_out[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5500 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5501 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5502 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5503 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5504 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5505 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
|
5506 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5507 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5508 if (use_file_for_err) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5509 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5510 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
|
5511 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5512 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
|
5513 if (fd_err[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5514 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5515 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5516 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5517 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5518 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5519 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
|
5520 && 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
|
5521 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5522 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5523 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
|
5524 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5525 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5526 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5527 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5528 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5529 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5530 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5531 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5532 channel = add_channel(); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5533 if (channel == NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5534 goto failed; |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5535 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
|
5536 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
|
5537 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
|
5538 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5539 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5540 BLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5541 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
|
5542 if (pid == -1) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5543 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5544 /* failed to fork */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5545 UNBLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5546 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5547 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5548 if (pid == 0) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5549 { |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5550 int null_fd = -1; |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5551 int stderr_works = TRUE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5552 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5553 /* child */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5554 reset_signals(); /* handle signals normally */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5555 UNBLOCK_SIGNALS(&curset); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5556 |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5557 # 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
|
5558 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
|
5559 /* 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
|
5560 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
|
5561 # endif |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5562 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5563 # ifdef HAVE_SETSID |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5564 /* 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
|
5565 * 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
|
5566 * 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
|
5567 (void)setsid(); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5568 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5569 |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5570 # ifdef FEAT_TERMINAL |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5571 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
|
5572 { |
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
|
5573 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
|
5574 |
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
|
5575 #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
|
5576 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
|
5577 /* 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
|
5578 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
|
5579 #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
|
5580 /* 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
|
5581 * 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
|
5582 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
|
5583 term = "xterm"; |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5584 set_child_environment( |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5585 (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
|
5586 (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
|
5587 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
|
5588 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
|
5589 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5590 else |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5591 # 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
|
5592 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
|
5593 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5594 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
|
5595 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5596 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
|
5597 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
|
5598 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
|
5599 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5600 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
|
5601 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
|
5602 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5603 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
|
5604 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5605 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
|
5606 --todo; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5607 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5608 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5609 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5610 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
|
5611 { |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5612 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
|
5613 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
|
5614 { |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5615 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
|
5616 _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
|
5617 } |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5618 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5619 |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5620 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
|
5621 { |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5622 /* push stream discipline modules */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5623 SetupSlavePTY(pty_slave_fd); |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5624 # ifdef TIOCSCTTY |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5625 /* 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
|
5626 * unless run by root) */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5627 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
|
5628 # endif |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5629 } |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5630 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5631 /* 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
|
5632 close(0); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5633 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
|
5634 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
|
5635 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
|
5636 ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5637 else |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5638 ignored = dup(fd_in[0]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5639 |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5640 /* 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
|
5641 close(2); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5642 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
|
5643 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5644 ignored = dup(null_fd); |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5645 stderr_works = FALSE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5646 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5647 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
|
5648 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
|
5649 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
|
5650 ignored = dup(pty_slave_fd); |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5651 else |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5652 ignored = dup(fd_err[1]); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5653 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5654 /* 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
|
5655 close(1); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5656 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
|
5657 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
|
5658 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
|
5659 ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5660 else |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5661 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
|
5662 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5663 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
|
5664 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
|
5665 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
|
5666 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
|
5667 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
|
5668 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
|
5669 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
|
5670 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
|
5671 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
|
5672 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
|
5673 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
|
5674 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
|
5675 if (pty_master_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5676 { |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5677 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
|
5678 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
|
5679 } |
9074
3aab62b76363
commit https://github.com/vim/vim/commit/ea83bf06b92baeb6d68a10d8e8ffad289d31dae2
Christian Brabandt <cb@256bit.org>
parents:
9009
diff
changeset
|
5680 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5681 if (null_fd >= 0) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5682 close(null_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5683 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5684 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
|
5685 _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
|
5686 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5687 /* See above for type of argv. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5688 execvp(argv[0], argv); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5689 |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5690 if (stderr_works) |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5691 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
|
5692 # ifdef EXITFREE |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5693 /* 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
|
5694 * 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
|
5695 # endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5696 _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
|
5697 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5698 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5699 /* parent */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5700 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5701 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5702 job->jv_pid = pid; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5703 job->jv_status = JOB_STARTED; |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5704 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
|
5705 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5706 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
|
5707 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
|
5708 /* 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
|
5709 if (fd_in[0] >= 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5710 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
|
5711 if (fd_out[1] >= 0) |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5712 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
|
5713 if (fd_err[1] >= 0) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5714 close(fd_err[1]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5715 if (channel != NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5716 { |
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
|
5717 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
|
5718 ? 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
|
5719 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
|
5720 ? 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
|
5721 /* 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
|
5722 * 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
|
5723 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
|
5724 ? INVALID_FD |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5725 : 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
|
5726 ? 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
|
5727 : (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
|
5728 ? INVALID_FD |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5729 : 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
|
5730 |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5731 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
|
5732 channel_set_job(channel, job, options); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5733 } |
11894
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5734 else |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5735 { |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5736 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
|
5737 close(fd_in[1]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5738 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
|
5739 close(fd_out[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5740 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
|
5741 close(fd_err[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5742 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
|
5743 close(pty_master_fd); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5744 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5745 |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5746 /* success! */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5747 return; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5748 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5749 failed: |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5750 channel_unref(channel); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5751 if (fd_in[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5752 close(fd_in[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5753 if (fd_in[1] >= 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5754 close(fd_in[1]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5755 if (fd_out[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5756 close(fd_out[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5757 if (fd_out[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5758 close(fd_out[1]); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5759 if (fd_err[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5760 close(fd_err[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5761 if (fd_err[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5762 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
|
5763 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
|
5764 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
|
5765 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
|
5766 close(pty_slave_fd); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5767 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5768 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5769 char * |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5770 mch_job_status(job_T *job) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5771 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5772 # ifdef HAVE_UNION_WAIT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5773 union wait status; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5774 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5775 int status = -1; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5776 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5777 pid_t wait_pid = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5778 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5779 # ifdef __NeXT__ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5780 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
|
5781 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5782 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
|
5783 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5784 if (wait_pid == -1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5785 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5786 /* 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
|
5787 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
|
5788 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
|
5789 strerror(errno)); |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5790 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5791 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5792 if (wait_pid == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5793 return "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5794 if (WIFEXITED(status)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5795 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5796 /* 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
|
5797 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
|
5798 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
|
5799 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
|
5800 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5801 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5802 if (WIFSIGNALED(status)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5803 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5804 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
|
5805 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
|
5806 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
|
5807 goto return_dead; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5808 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5809 return "run"; |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5810 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5811 return_dead: |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5812 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
|
5813 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5814 return "dead"; |
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 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5817 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5818 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
|
5819 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5820 # ifdef HAVE_UNION_WAIT |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5821 union wait status; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5822 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5823 int status = -1; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5824 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5825 pid_t wait_pid = 0; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5826 job_T *job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5827 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5828 # ifndef USE_SYSTEM |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5829 /* 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
|
5830 * 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
|
5831 * would then be wrong. */ |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5832 if (dont_check_job_ended > 0) |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5833 return NULL; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5834 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5835 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5836 # ifdef __NeXT__ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5837 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
|
5838 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5839 wait_pid = waitpid(-1, &status, WNOHANG); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5840 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5841 if (wait_pid <= 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5842 /* no process ended */ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5843 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5844 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
|
5845 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5846 if (job->jv_pid == wait_pid) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5847 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5848 if (WIFEXITED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5849 /* 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
|
5850 job->jv_exitval = WEXITSTATUS(status); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5851 else if (WIFSIGNALED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5852 job->jv_exitval = -1; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5853 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
|
5854 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5855 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
|
5856 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5857 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5858 return job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5859 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5860 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5861 return NULL; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5862 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5863 |
10320
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5864 /* |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5865 * Send a (deadly) signal to "job". |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5866 * 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
|
5867 */ |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5868 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
5869 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
|
5870 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5871 int sig = -1; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5872 pid_t job_pid; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5873 |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5874 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
|
5875 sig = SIGTERM; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5876 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
|
5877 sig = SIGHUP; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5878 else if (STRCMP(how, "quit") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5879 sig = SIGQUIT; |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5880 else if (STRCMP(how, "int") == 0) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5881 sig = SIGINT; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5882 else if (STRCMP(how, "kill") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5883 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
|
5884 #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
|
5885 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
|
5886 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
|
5887 #endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5888 else if (isdigit(*how)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5889 sig = atoi((char *)how); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5890 else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5891 return FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5892 |
7999
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
5893 /* 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
|
5894 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
|
5895 #ifdef HAVE_GETPGID |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5896 if (job_pid == getpgid(job_pid)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5897 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
|
5898 #endif |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5899 |
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
|
5900 /* 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
|
5901 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
|
5902 kill(job_pid, sig); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5903 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5904 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5905 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5906 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5907 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5908 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5909 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5910 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5911 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5912 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5913 /* 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
|
5914 # ifdef __NeXT__ |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5915 (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
|
5916 # else |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5917 (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
|
5918 # endif |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5919 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5920 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5921 |
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
|
5922 #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
|
5923 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
|
5924 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
|
5925 { |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5926 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
|
5927 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
|
5928 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
|
5929 |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5930 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
|
5931 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
|
5932 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
|
5933 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
|
5934 |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5935 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
|
5936 if (channel == NULL) |
12369
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5937 { |
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5938 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
|
5939 return FAIL; |
12369
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5940 } |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5941 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
|
5942 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
|
5943 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
|
5944 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
|
5945 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
|
5946 |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5947 /* 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
|
5948 * 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
|
5949 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
|
5950 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
|
5951 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
|
5952 } |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5953 #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
|
5954 |
7 | 5955 /* |
5956 * Check for CTRL-C typed by reading all available characters. | |
5957 * In cooked mode we should get SIGINT, no need to check. | |
5958 */ | |
5959 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5960 mch_breakcheck(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5961 { |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5962 if ((curr_tmode == TMODE_RAW || force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5963 && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL)) |
7 | 5964 fill_input_buf(FALSE); |
5965 } | |
5966 | |
5967 /* | |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5968 * 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
|
5969 * from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5970 * "msec" == -1 will block forever. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5971 * 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
|
5972 * 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
|
5973 * already available. |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5974 * "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
|
5975 * 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
|
5976 * Returns TRUE when a character is available. |
7 | 5977 * When a GUI is being used, this will never get called -- webb |
5978 */ | |
5979 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5980 WaitForChar(long msec, int *interrupted, int ignore_input) |
7 | 5981 { |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5982 #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
|
5983 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
|
5984 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
|
5985 #else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5986 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
|
5987 #endif |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5988 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5989 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5990 /* |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5991 * 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
|
5992 * or from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5993 * "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
|
5994 * for "ignore_input" see WaitForCharOr(). |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5995 * "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
|
5996 * 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
|
5997 * 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
|
5998 */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5999 static int |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
6000 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
|
6001 { |
7 | 6002 #ifdef FEAT_MOUSE_GPM |
6003 int gpm_process_wanted; | |
6004 #endif | |
6005 #ifdef FEAT_XCLIPBOARD | |
6006 int rest; | |
6007 #endif | |
6008 int avail; | |
6009 | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
6010 if (!ignore_input && input_available()) /* something in inbuf[] */ |
7 | 6011 return 1; |
6012 | |
6013 #if defined(FEAT_MOUSE_DEC) | |
6014 /* May need to query the mouse position. */ | |
6015 if (WantQueryMouse) | |
6016 { | |
227 | 6017 WantQueryMouse = FALSE; |
7 | 6018 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5); |
6019 } | |
6020 #endif | |
6021 | |
6022 /* | |
6023 * For FEAT_MOUSE_GPM and FEAT_XCLIPBOARD we loop here to process mouse | |
6024 * events. This is a bit complicated, because they might both be defined. | |
6025 */ | |
6026 #if defined(FEAT_MOUSE_GPM) || defined(FEAT_XCLIPBOARD) | |
6027 # ifdef FEAT_XCLIPBOARD | |
6028 rest = 0; | |
6029 if (do_xterm_trace()) | |
6030 rest = msec; | |
6031 # endif | |
6032 do | |
6033 { | |
6034 # ifdef FEAT_XCLIPBOARD | |
6035 if (rest != 0) | |
6036 { | |
6037 msec = XT_TRACE_DELAY; | |
6038 if (rest >= 0 && rest < XT_TRACE_DELAY) | |
6039 msec = rest; | |
6040 if (rest >= 0) | |
6041 rest -= msec; | |
6042 } | |
6043 # endif | |
6044 # ifdef FEAT_MOUSE_GPM | |
6045 gpm_process_wanted = 0; | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6046 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
|
6047 &gpm_process_wanted, interrupted); |
7 | 6048 # else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6049 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 6050 # endif |
6051 if (!avail) | |
6052 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
6053 if (!ignore_input && input_available()) |
7 | 6054 return 1; |
6055 # ifdef FEAT_XCLIPBOARD | |
6056 if (rest == 0 || !do_xterm_trace()) | |
6057 # endif | |
6058 break; | |
6059 } | |
6060 } | |
6061 while (FALSE | |
6062 # ifdef FEAT_MOUSE_GPM | |
6063 || (gpm_process_wanted && mch_gpm_process() == 0) | |
6064 # endif | |
6065 # ifdef FEAT_XCLIPBOARD | |
6066 || (!avail && rest != 0) | |
6067 # endif | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6068 ) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6069 ; |
7 | 6070 |
6071 #else | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6072 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 6073 #endif |
6074 return avail; | |
6075 } | |
6076 | |
5541 | 6077 #ifndef VMS |
7 | 6078 /* |
6079 * Wait "msec" msec until a character is available from file descriptor "fd". | |
3046 | 6080 * "msec" == 0 will check for characters once. |
6081 * "msec" == -1 will block until a character is available. | |
7 | 6082 * When a GUI is being used, this will not be used for input -- webb |
6083 * 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
|
6084 * 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
|
6085 * "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
|
6086 * but something else needs to be done. |
7 | 6087 */ |
6088 #if defined(__BEOS__) | |
6089 int | |
6090 #else | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6091 static int |
7 | 6092 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6093 RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted) |
7 | 6094 { |
6095 int ret; | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6096 int result; |
14 | 6097 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) |
7 | 6098 static int busy = FALSE; |
6099 | |
6100 /* May retry getting characters after an event was handled. */ | |
6101 # define MAY_LOOP | |
6102 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6103 # ifdef ELAPSED_FUNC |
7 | 6104 /* Remember at what time we started, so that we know how much longer we |
6105 * should wait after being interrupted. */ | |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
6106 long start_msec = msec; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6107 ELAPSED_TYPE start_tv; |
7 | 6108 |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
6109 if (msec > 0) |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6110 ELAPSED_INIT(start_tv); |
7 | 6111 # endif |
6112 | |
6113 /* Handle being called recursively. This may happen for the session | |
6114 * manager stuff, it may save the file, which does a breakcheck. */ | |
6115 if (busy) | |
6116 return 0; | |
6117 #endif | |
6118 | |
6119 #ifdef MAY_LOOP | |
407 | 6120 for (;;) |
7 | 6121 #endif |
6122 { | |
6123 #ifdef MAY_LOOP | |
6124 int finished = TRUE; /* default is to 'loop' just once */ | |
14 | 6125 # ifdef FEAT_MZSCHEME |
6126 int mzquantum_used = FALSE; | |
6127 # endif | |
7 | 6128 #endif |
6129 #ifndef HAVE_SELECT | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6130 /* 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
|
6131 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; |
7 | 6132 int nfd; |
6133 # ifdef FEAT_XCLIPBOARD | |
6134 int xterm_idx = -1; | |
6135 # endif | |
6136 # ifdef FEAT_MOUSE_GPM | |
6137 int gpm_idx = -1; | |
6138 # endif | |
6139 # ifdef USE_XSMP | |
6140 int xsmp_idx = -1; | |
6141 # endif | |
14 | 6142 int towait = (int)msec; |
6143 | |
6144 # ifdef FEAT_MZSCHEME | |
6145 mzvim_check_threads(); | |
6146 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
6147 { | |
6148 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ | |
6149 mzquantum_used = TRUE; | |
6150 } | |
6151 # endif | |
7 | 6152 fds[0].fd = fd; |
6153 fds[0].events = POLLIN; | |
6154 nfd = 1; | |
6155 | |
6156 # ifdef FEAT_XCLIPBOARD | |
6383 | 6157 may_restore_clipboard(); |
7 | 6158 if (xterm_Shell != (Widget)0) |
6159 { | |
6160 xterm_idx = nfd; | |
6161 fds[nfd].fd = ConnectionNumber(xterm_dpy); | |
6162 fds[nfd].events = POLLIN; | |
6163 nfd++; | |
6164 } | |
6165 # endif | |
6166 # ifdef FEAT_MOUSE_GPM | |
6167 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
6168 { | |
6169 gpm_idx = nfd; | |
6170 fds[nfd].fd = gpm_fd; | |
6171 fds[nfd].events = POLLIN; | |
6172 nfd++; | |
6173 } | |
6174 # endif | |
6175 # ifdef USE_XSMP | |
6176 if (xsmp_icefd != -1) | |
6177 { | |
6178 xsmp_idx = nfd; | |
6179 fds[nfd].fd = xsmp_icefd; | |
6180 fds[nfd].events = POLLIN; | |
6181 nfd++; | |
6182 } | |
6183 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6184 #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
|
6185 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
|
6186 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6187 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6188 *interrupted = FALSE; |
7 | 6189 |
14 | 6190 ret = poll(fds, nfd, towait); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6191 |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6192 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
|
6193 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
|
6194 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6195 |
14 | 6196 # ifdef FEAT_MZSCHEME |
6197 if (ret == 0 && mzquantum_used) | |
1450 | 6198 /* MzThreads scheduling is required and timeout occurred */ |
14 | 6199 finished = FALSE; |
6200 # endif | |
7 | 6201 |
6202 # ifdef FEAT_XCLIPBOARD | |
6203 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) | |
6204 { | |
6205 xterm_update(); /* Maybe we should hand out clipboard */ | |
6206 if (--ret == 0 && !input_available()) | |
6207 /* Try again */ | |
6208 finished = FALSE; | |
6209 } | |
6210 # endif | |
6211 # ifdef FEAT_MOUSE_GPM | |
6212 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN)) | |
6213 { | |
6214 *check_for_gpm = 1; | |
6215 } | |
6216 # endif | |
6217 # ifdef USE_XSMP | |
6218 if (xsmp_idx >= 0 && (fds[xsmp_idx].revents & (POLLIN | POLLHUP))) | |
6219 { | |
6220 if (fds[xsmp_idx].revents & POLLIN) | |
6221 { | |
6222 busy = TRUE; | |
6223 xsmp_handle_requests(); | |
6224 busy = FALSE; | |
6225 } | |
6226 else if (fds[xsmp_idx].revents & POLLHUP) | |
6227 { | |
6228 if (p_verbose > 0) | |
292 | 6229 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 6230 xsmp_close(); |
6231 } | |
6232 if (--ret == 0) | |
14 | 6233 finished = FALSE; /* Try again */ |
7 | 6234 } |
6235 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6236 #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
|
6237 /* 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
|
6238 if (ret >= 0) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
6239 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
|
6240 #endif |
7 | 6241 |
6242 #else /* HAVE_SELECT */ | |
6243 | |
6244 struct timeval tv; | |
14 | 6245 struct timeval *tvp; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6246 fd_set rfds, wfds, efds; |
7 | 6247 int maxfd; |
14 | 6248 long towait = msec; |
6249 | |
6250 # ifdef FEAT_MZSCHEME | |
6251 mzvim_check_threads(); | |
6252 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
6253 { | |
6254 towait = p_mzq; /* don't wait longer than 'mzquantum' */ | |
6255 mzquantum_used = TRUE; | |
6256 } | |
6257 # endif | |
7 | 6258 |
14 | 6259 if (towait >= 0) |
7 | 6260 { |
14 | 6261 tv.tv_sec = towait / 1000; |
6262 tv.tv_usec = (towait % 1000) * (1000000/1000); | |
6263 tvp = &tv; | |
7 | 6264 } |
14 | 6265 else |
6266 tvp = NULL; | |
7 | 6267 |
6268 /* | |
6269 * Select on ready for reading and exceptional condition (end of file). | |
6270 */ | |
3046 | 6271 select_eintr: |
6272 FD_ZERO(&rfds); | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6273 FD_ZERO(&wfds); |
7 | 6274 FD_ZERO(&efds); |
6275 FD_SET(fd, &rfds); | |
6276 # if !defined(__QNX__) && !defined(__CYGWIN32__) | |
6277 /* For QNX select() always returns 1 if this is set. Why? */ | |
6278 FD_SET(fd, &efds); | |
6279 # endif | |
6280 maxfd = fd; | |
6281 | |
6282 # ifdef FEAT_XCLIPBOARD | |
6383 | 6283 may_restore_clipboard(); |
7 | 6284 if (xterm_Shell != (Widget)0) |
6285 { | |
6286 FD_SET(ConnectionNumber(xterm_dpy), &rfds); | |
6287 if (maxfd < ConnectionNumber(xterm_dpy)) | |
6288 maxfd = ConnectionNumber(xterm_dpy); | |
3748 | 6289 |
6290 /* An event may have already been read but not handled. In | |
6291 * particulary, XFlush may cause this. */ | |
6292 xterm_update(); | |
7 | 6293 } |
6294 # endif | |
6295 # ifdef FEAT_MOUSE_GPM | |
6296 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
6297 { | |
6298 FD_SET(gpm_fd, &rfds); | |
6299 FD_SET(gpm_fd, &efds); | |
6300 if (maxfd < gpm_fd) | |
6301 maxfd = gpm_fd; | |
6302 } | |
6303 # endif | |
6304 # ifdef USE_XSMP | |
6305 if (xsmp_icefd != -1) | |
6306 { | |
6307 FD_SET(xsmp_icefd, &rfds); | |
6308 FD_SET(xsmp_icefd, &efds); | |
6309 if (maxfd < xsmp_icefd) | |
6310 maxfd = xsmp_icefd; | |
6311 } | |
6312 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6313 # 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
|
6314 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
|
6315 # endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6316 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6317 *interrupted = FALSE; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6318 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6319 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
|
6320 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
|
6321 if (result) |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6322 --ret; |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6323 else if (interrupted != NULL && ret > 0) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6324 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6325 |
3046 | 6326 # ifdef EINTR |
6327 if (ret == -1 && errno == EINTR) | |
3133 | 6328 { |
6329 /* Check whether window has been resized, EINTR may be caused by | |
6330 * SIGWINCH. */ | |
6331 if (do_resize) | |
6332 handle_resize(); | |
6333 | |
3046 | 6334 /* Interrupted by a signal, need to try again. We ignore msec |
6335 * here, because we do want to check even after a timeout if | |
6336 * characters are available. Needed for reading output of an | |
6337 * external command after the process has finished. */ | |
6338 goto select_eintr; | |
3133 | 6339 } |
3046 | 6340 # endif |
1076 | 6341 # ifdef __TANDEM |
6342 if (ret == -1 && errno == ENOTSUP) | |
6343 { | |
6344 FD_ZERO(&rfds); | |
6345 FD_ZERO(&efds); | |
6346 ret = 0; | |
6347 } | |
3046 | 6348 # endif |
14 | 6349 # ifdef FEAT_MZSCHEME |
6350 if (ret == 0 && mzquantum_used) | |
1450 | 6351 /* loop if MzThreads must be scheduled and timeout occurred */ |
14 | 6352 finished = FALSE; |
7 | 6353 # endif |
6354 | |
6355 # ifdef FEAT_XCLIPBOARD | |
6356 if (ret > 0 && xterm_Shell != (Widget)0 | |
6357 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) | |
6358 { | |
6359 xterm_update(); /* Maybe we should hand out clipboard */ | |
6360 /* continue looping when we only got the X event and the input | |
6361 * buffer is empty */ | |
6362 if (--ret == 0 && !input_available()) | |
6363 { | |
6364 /* Try again */ | |
6365 finished = FALSE; | |
6366 } | |
6367 } | |
6368 # endif | |
6369 # ifdef FEAT_MOUSE_GPM | |
6370 if (ret > 0 && gpm_flag && check_for_gpm != NULL && gpm_fd >= 0) | |
6371 { | |
6372 if (FD_ISSET(gpm_fd, &efds)) | |
6373 gpm_close(); | |
6374 else if (FD_ISSET(gpm_fd, &rfds)) | |
6375 *check_for_gpm = 1; | |
6376 } | |
6377 # endif | |
6378 # ifdef USE_XSMP | |
6379 if (ret > 0 && xsmp_icefd != -1) | |
6380 { | |
6381 if (FD_ISSET(xsmp_icefd, &efds)) | |
6382 { | |
6383 if (p_verbose > 0) | |
292 | 6384 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 6385 xsmp_close(); |
6386 if (--ret == 0) | |
6387 finished = FALSE; /* keep going if event was only one */ | |
6388 } | |
6389 else if (FD_ISSET(xsmp_icefd, &rfds)) | |
6390 { | |
6391 busy = TRUE; | |
6392 xsmp_handle_requests(); | |
6393 busy = FALSE; | |
6394 if (--ret == 0) | |
6395 finished = FALSE; /* keep going if event was only one */ | |
6396 } | |
6397 } | |
6398 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6399 #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
|
6400 /* 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
|
6401 if (ret >= 0) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6402 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
|
6403 #endif |
7 | 6404 |
6405 #endif /* HAVE_SELECT */ | |
6406 | |
6407 #ifdef MAY_LOOP | |
6408 if (finished || msec == 0) | |
6409 break; | |
6410 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6411 # ifdef FEAT_CLIENTSERVER |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6412 if (server_waiting()) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6413 break; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6414 # endif |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6415 |
7 | 6416 /* We're going to loop around again, find out for how long */ |
6417 if (msec > 0) | |
6418 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6419 # ifdef ELAPSED_FUNC |
7 | 6420 /* Compute remaining wait time. */ |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6421 msec = start_msec - ELAPSED_FUNC(start_tv); |
7 | 6422 # else |
6423 /* Guess we got interrupted halfway. */ | |
6424 msec = msec / 2; | |
6425 # endif | |
6426 if (msec <= 0) | |
6427 break; /* waited long enough */ | |
6428 } | |
6429 #endif | |
6430 } | |
6431 | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6432 return result; |
7 | 6433 } |
6434 | |
6435 #ifndef NO_EXPANDPATH | |
6436 /* | |
444 | 6437 * Expand a path into all matching files and/or directories. Handles "*", |
6438 * "?", "[a-z]", "**", etc. | |
6439 * "path" has backslashes before chars that are not to be expanded. | |
6440 * Returns the number of matches found. | |
7 | 6441 */ |
6442 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6443 mch_expandpath( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6444 garray_T *gap, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6445 char_u *path, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6446 int flags) /* EW_* flags */ |
7 | 6447 { |
444 | 6448 return unix_expandpath(gap, path, 0, flags, FALSE); |
7 | 6449 } |
6450 #endif | |
6451 | |
6452 /* | |
6453 * mch_expand_wildcards() - this code does wild-card pattern matching using | |
6454 * the shell | |
6455 * | |
6456 * return OK for success, FAIL for error (you may lose some memory) and put | |
6457 * an error message in *file. | |
6458 * | |
6459 * num_pat is number of input patterns | |
6460 * pat is array of pointers to input patterns | |
6461 * num_file is pointer to number of matched file names | |
6462 * file is pointer to array of pointers to matched file names | |
6463 */ | |
6464 | |
6465 #ifndef SEEK_SET | |
6466 # define SEEK_SET 0 | |
6467 #endif | |
6468 #ifndef SEEK_END | |
6469 # define SEEK_END 2 | |
6470 #endif | |
6471 | |
822 | 6472 #define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
628 | 6473 |
7 | 6474 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6475 mch_expand_wildcards( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6476 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6477 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6478 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6479 char_u ***file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6480 int flags) /* EW_* flags */ |
7 | 6481 { |
6482 int i; | |
6483 size_t len; | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6484 long llen; |
7 | 6485 char_u *p; |
6486 int dir; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
6487 |
1508 | 6488 /* |
6489 * This is the non-OS/2 implementation (really Unix). | |
6490 */ | |
7 | 6491 int j; |
6492 char_u *tempname; | |
6493 char_u *command; | |
6494 FILE *fd; | |
6495 char_u *buffer; | |
1508 | 6496 #define STYLE_ECHO 0 /* use "echo", the default */ |
6497 #define STYLE_GLOB 1 /* use "glob", for csh */ | |
6498 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
6499 #define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
6500 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
6501 * directly */ | |
7 | 6502 int shell_style = STYLE_ECHO; |
6503 int check_spaces; | |
6504 static int did_find_nul = FALSE; | |
6505 int ampersent = FALSE; | |
1508 | 6506 /* vimglob() function to define for Posix shell */ |
1620 | 6507 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; |
7 | 6508 |
6509 *num_file = 0; /* default: no files found */ | |
6510 *file = NULL; | |
6511 | |
6512 /* | |
6513 * If there are no wildcards, just copy the names to allocated memory. | |
6514 * Saves a lot of time, because we don't have to start a new shell. | |
6515 */ | |
6516 if (!have_wildcard(num_pat, pat)) | |
6517 return save_patterns(num_pat, pat, num_file, file); | |
6518 | |
428 | 6519 # ifdef HAVE_SANDBOX |
6520 /* Don't allow any shell command in the sandbox. */ | |
6521 if (sandbox != 0 && check_secure()) | |
6522 return FAIL; | |
6523 # endif | |
6524 | |
7 | 6525 /* |
6526 * Don't allow the use of backticks in secure and restricted mode. | |
6527 */ | |
428 | 6528 if (secure || restricted) |
7 | 6529 for (i = 0; i < num_pat; ++i) |
6530 if (vim_strchr(pat[i], '`') != NULL | |
6531 && (check_restricted() || check_secure())) | |
6532 return FAIL; | |
6533 | |
6534 /* | |
6535 * get a name for the temp file | |
6536 */ | |
6721 | 6537 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 6538 { |
6539 EMSG(_(e_notmp)); | |
6540 return FAIL; | |
6541 } | |
6542 | |
6543 /* | |
6544 * Let the shell expand the patterns and write the result into the temp | |
1508 | 6545 * file. |
6546 * STYLE_BT: NL separated | |
6547 * If expanding `cmd` execute it directly. | |
6548 * STYLE_GLOB: NUL separated | |
6549 * If we use *csh, "glob" will work better than "echo". | |
6550 * STYLE_PRINT: NL or NUL separated | |
6551 * If we use *zsh, "print -N" will work better than "glob". | |
6552 * STYLE_VIMGLOB: NL separated | |
6553 * If we use *sh*, we define "vimglob()". | |
6554 * STYLE_ECHO: space separated. | |
6555 * A shell we don't know, stay safe and use "echo". | |
7 | 6556 */ |
6557 if (num_pat == 1 && *pat[0] == '`' | |
6558 && (len = STRLEN(pat[0])) > 2 | |
6559 && *(pat[0] + len - 1) == '`') | |
6560 shell_style = STYLE_BT; | |
6561 else if ((len = STRLEN(p_sh)) >= 3) | |
6562 { | |
6563 if (STRCMP(p_sh + len - 3, "csh") == 0) | |
6564 shell_style = STYLE_GLOB; | |
6565 else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
6566 shell_style = STYLE_PRINT; | |
6567 } | |
1508 | 6568 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), |
6569 "sh") != NULL) | |
6570 shell_style = STYLE_VIMGLOB; | |
6571 | |
6572 /* Compute the length of the command. We need 2 extra bytes: for the | |
6573 * optional '&' and for the NUL. | |
6574 * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
7 | 6575 len = STRLEN(tempname) + 29; |
1508 | 6576 if (shell_style == STYLE_VIMGLOB) |
6577 len += STRLEN(sh_vimglob_func); | |
6578 | |
147 | 6579 for (i = 0; i < num_pat; ++i) |
6580 { | |
6581 /* Count the length of the patterns in the same way as they are put in | |
6582 * "command" below. */ | |
6583 #ifdef USE_SYSTEM | |
7 | 6584 len += STRLEN(pat[i]) + 3; /* add space and two quotes */ |
147 | 6585 #else |
6586 ++len; /* add space */ | |
628 | 6587 for (j = 0; pat[i][j] != NUL; ++j) |
6588 { | |
6589 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
6590 ++len; /* may add a backslash */ | |
6591 ++len; | |
6592 } | |
147 | 6593 #endif |
6594 } | |
7 | 6595 command = alloc(len); |
6596 if (command == NULL) | |
6597 { | |
6598 /* out of memory */ | |
6599 vim_free(tempname); | |
6600 return FAIL; | |
6601 } | |
6602 | |
6603 /* | |
6604 * Build the shell command: | |
6605 * - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell | |
6606 * recognizes this). | |
6607 * - Add the shell command to print the expanded names. | |
6608 * - Add the temp file name. | |
6609 * - Add the file name patterns. | |
6610 */ | |
6611 if (shell_style == STYLE_BT) | |
6612 { | |
628 | 6613 /* change `command; command& ` to (command; command ) */ |
6614 STRCPY(command, "("); | |
6615 STRCAT(command, pat[0] + 1); /* exclude first backtick */ | |
7 | 6616 p = command + STRLEN(command) - 1; |
628 | 6617 *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
|
6618 while (p > command && VIM_ISWHITE(*p)) |
7 | 6619 --p; |
6620 if (*p == '&') /* remove trailing '&' */ | |
6621 { | |
6622 ampersent = TRUE; | |
6623 *p = ' '; | |
6624 } | |
6625 STRCAT(command, ">"); | |
6626 } | |
6627 else | |
6628 { | |
6629 if (flags & EW_NOTFOUND) | |
6630 STRCPY(command, "set nonomatch; "); | |
6631 else | |
6632 STRCPY(command, "unset nonomatch; "); | |
6633 if (shell_style == STYLE_GLOB) | |
6634 STRCAT(command, "glob >"); | |
6635 else if (shell_style == STYLE_PRINT) | |
6636 STRCAT(command, "print -N >"); | |
1508 | 6637 else if (shell_style == STYLE_VIMGLOB) |
6638 STRCAT(command, sh_vimglob_func); | |
7 | 6639 else |
6640 STRCAT(command, "echo >"); | |
6641 } | |
1508 | 6642 |
7 | 6643 STRCAT(command, tempname); |
1508 | 6644 |
7 | 6645 if (shell_style != STYLE_BT) |
6646 for (i = 0; i < num_pat; ++i) | |
6647 { | |
6648 /* When using system() always add extra quotes, because the shell | |
628 | 6649 * is started twice. Otherwise put a backslash before special |
1450 | 6650 * characters, except inside ``. */ |
7 | 6651 #ifdef USE_SYSTEM |
6652 STRCAT(command, " \""); | |
6653 STRCAT(command, pat[i]); | |
6654 STRCAT(command, "\""); | |
6655 #else | |
233 | 6656 int intick = FALSE; |
6657 | |
7 | 6658 p = command + STRLEN(command); |
6659 *p++ = ' '; | |
628 | 6660 for (j = 0; pat[i][j] != NUL; ++j) |
233 | 6661 { |
6662 if (pat[i][j] == '`') | |
6663 intick = !intick; | |
628 | 6664 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) |
6665 { | |
644 | 6666 /* Remove a backslash, take char literally. But keep |
652 | 6667 * backslash inside backticks, before a special character |
6668 * and before a backtick. */ | |
644 | 6669 if (intick |
652 | 6670 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL |
6671 || pat[i][j + 1] == '`') | |
644 | 6672 *p++ = '\\'; |
648 | 6673 ++j; |
628 | 6674 } |
6174 | 6675 else if (!intick |
6676 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') | |
6677 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
628 | 6678 /* Put a backslash before a special character, but not |
6174 | 6679 * when inside ``. And not for $var when EW_KEEPDOLLAR is |
6680 * set. */ | |
628 | 6681 *p++ = '\\'; |
648 | 6682 |
6683 /* Copy one character. */ | |
6684 *p++ = pat[i][j]; | |
233 | 6685 } |
7 | 6686 *p = NUL; |
6687 #endif | |
6688 } | |
6689 if (flags & EW_SILENT) | |
6690 show_shell_mess = FALSE; | |
6691 if (ampersent) | |
1508 | 6692 STRCAT(command, "&"); /* put the '&' after the redirection */ |
7 | 6693 |
6694 /* | |
6695 * Using zsh -G: If a pattern has no matches, it is just deleted from | |
6696 * the argument list, otherwise zsh gives an error message and doesn't | |
6697 * expand any other pattern. | |
6698 */ | |
6699 if (shell_style == STYLE_PRINT) | |
6700 extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ | |
6701 | |
6702 /* | |
6703 * If we use -f then shell variables set in .cshrc won't get expanded. | |
6704 * vi can do it, so we will too, but it is only necessary if there is a "$" | |
6705 * in one of the patterns, otherwise we can still use the fast option. | |
6706 */ | |
6707 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) | |
6708 extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ | |
6709 | |
6710 /* | |
6711 * execute the shell command | |
6712 */ | |
6713 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); | |
6714 | |
6715 /* When running in the background, give it some time to create the temp | |
6716 * file, but don't wait for it to finish. */ | |
6717 if (ampersent) | |
6718 mch_delay(10L, TRUE); | |
6719 | |
6720 extra_shell_arg = NULL; /* cleanup */ | |
6721 show_shell_mess = TRUE; | |
6722 vim_free(command); | |
6723 | |
1508 | 6724 if (i != 0) /* mch_call_shell() failed */ |
7 | 6725 { |
6726 mch_remove(tempname); | |
6727 vim_free(tempname); | |
6728 /* | |
6729 * With interactive completion, the error message is not printed. | |
6730 * However with USE_SYSTEM, I don't know how to turn off error messages | |
6731 * from the shell, so screen may still get messed up -- webb. | |
6732 */ | |
6733 #ifndef USE_SYSTEM | |
6734 if (!(flags & EW_SILENT)) | |
6735 #endif | |
6736 { | |
6737 redraw_later_clear(); /* probably messed up screen */ | |
6738 msg_putchar('\n'); /* clear bottom line quickly */ | |
6739 cmdline_row = Rows - 1; /* continue on last line */ | |
6740 #ifdef USE_SYSTEM | |
6741 if (!(flags & EW_SILENT)) | |
6742 #endif | |
6743 { | |
6744 MSG(_(e_wildexpand)); | |
6745 msg_start(); /* don't overwrite this message */ | |
6746 } | |
6747 } | |
6748 /* If a `cmd` expansion failed, don't list `cmd` as a match, even when | |
6749 * EW_NOTFOUND is given */ | |
6750 if (shell_style == STYLE_BT) | |
6751 return FAIL; | |
6752 goto notfound; | |
6753 } | |
6754 | |
6755 /* | |
6756 * read the names from the file into memory | |
6757 */ | |
6758 fd = fopen((char *)tempname, READBIN); | |
6759 if (fd == NULL) | |
6760 { | |
6761 /* Something went wrong, perhaps a file name with a special char. */ | |
6762 if (!(flags & EW_SILENT)) | |
6763 { | |
6764 MSG(_(e_wildexpand)); | |
6765 msg_start(); /* don't overwrite this message */ | |
6766 } | |
6767 vim_free(tempname); | |
6768 goto notfound; | |
6769 } | |
6770 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
|
6771 llen = ftell(fd); /* get size of temp file */ |
7 | 6772 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
|
6773 if (llen < 0) |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6774 /* 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
|
6775 buffer = NULL; |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6776 else |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6777 buffer = alloc(llen + 1); |
7 | 6778 if (buffer == NULL) |
6779 { | |
6780 /* out of memory */ | |
6781 mch_remove(tempname); | |
6782 vim_free(tempname); | |
6783 fclose(fd); | |
6784 return FAIL; | |
6785 } | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6786 len = llen; |
7 | 6787 i = fread((char *)buffer, 1, len, fd); |
6788 fclose(fd); | |
6789 mch_remove(tempname); | |
1877 | 6790 if (i != (int)len) |
7 | 6791 { |
6792 /* unexpected read error */ | |
6793 EMSG2(_(e_notread), tempname); | |
6794 vim_free(tempname); | |
6795 vim_free(buffer); | |
6796 return FAIL; | |
6797 } | |
6798 vim_free(tempname); | |
6799 | |
1508 | 6800 # if defined(__CYGWIN__) || defined(__CYGWIN32__) |
7 | 6801 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ |
6802 p = buffer; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
6803 for (i = 0; i < (int)len; ++i) |
7 | 6804 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) |
6805 *p++ = buffer[i]; | |
6806 len = p - buffer; | |
6807 # endif | |
6808 | |
6809 | |
6810 /* file names are separated with Space */ | |
6811 if (shell_style == STYLE_ECHO) | |
6812 { | |
6813 buffer[len] = '\n'; /* make sure the buffer ends in NL */ | |
6814 p = buffer; | |
6815 for (i = 0; *p != '\n'; ++i) /* count number of entries */ | |
6816 { | |
6817 while (*p != ' ' && *p != '\n') | |
6818 ++p; | |
6819 p = skipwhite(p); /* skip to next entry */ | |
6820 } | |
6821 } | |
6822 /* file names are separated with NL */ | |
1508 | 6823 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) |
7 | 6824 { |
6825 buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
6826 p = buffer; | |
6827 for (i = 0; *p != NUL; ++i) /* count number of entries */ | |
6828 { | |
6829 while (*p != '\n' && *p != NUL) | |
6830 ++p; | |
6831 if (*p != NUL) | |
6832 ++p; | |
6833 p = skipwhite(p); /* skip leading white space */ | |
6834 } | |
6835 } | |
6836 /* file names are separated with NUL */ | |
6837 else | |
6838 { | |
6839 /* | |
6840 * Some versions of zsh use spaces instead of NULs to separate | |
6841 * results. Only do this when there is no NUL before the end of the | |
6842 * buffer, otherwise we would never be able to use file names with | |
6843 * embedded spaces when zsh does use NULs. | |
6844 * When we found a NUL once, we know zsh is OK, set did_find_nul and | |
6845 * don't check for spaces again. | |
6846 */ | |
6847 check_spaces = FALSE; | |
6848 if (shell_style == STYLE_PRINT && !did_find_nul) | |
6849 { | |
6850 /* If there is a NUL, set did_find_nul, else set check_spaces */ | |
2768 | 6851 buffer[len] = NUL; |
5533 | 6852 if (len && (int)STRLEN(buffer) < (int)len) |
7 | 6853 did_find_nul = TRUE; |
6854 else | |
6855 check_spaces = TRUE; | |
6856 } | |
6857 | |
6858 /* | |
6859 * Make sure the buffer ends with a NUL. For STYLE_PRINT there | |
6860 * already is one, for STYLE_GLOB it needs to be added. | |
6861 */ | |
6862 if (len && buffer[len - 1] == NUL) | |
6863 --len; | |
6864 else | |
6865 buffer[len] = NUL; | |
6866 i = 0; | |
6867 for (p = buffer; p < buffer + len; ++p) | |
6868 if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ | |
6869 { | |
6870 ++i; | |
6871 *p = NUL; | |
6872 } | |
6873 if (len) | |
6874 ++i; /* count last entry */ | |
6875 } | |
6876 if (i == 0) | |
6877 { | |
6878 /* | |
6879 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I". | |
6880 * /bin/sh will happily expand it to nothing rather than returning an | |
6881 * error; and hey, it's good to check anyway -- webb. | |
6882 */ | |
6883 vim_free(buffer); | |
6884 goto notfound; | |
6885 } | |
6886 *num_file = i; | |
6887 *file = (char_u **)alloc(sizeof(char_u *) * i); | |
6888 if (*file == NULL) | |
6889 { | |
6890 /* out of memory */ | |
6891 vim_free(buffer); | |
6892 return FAIL; | |
6893 } | |
6894 | |
6895 /* | |
6896 * Isolate the individual file names. | |
6897 */ | |
6898 p = buffer; | |
6899 for (i = 0; i < *num_file; ++i) | |
6900 { | |
6901 (*file)[i] = p; | |
6902 /* Space or NL separates */ | |
1508 | 6903 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT |
6904 || shell_style == STYLE_VIMGLOB) | |
7 | 6905 { |
652 | 6906 while (!(shell_style == STYLE_ECHO && *p == ' ') |
6907 && *p != '\n' && *p != NUL) | |
7 | 6908 ++p; |
6909 if (p == buffer + len) /* last entry */ | |
6910 *p = NUL; | |
6911 else | |
6912 { | |
6913 *p++ = NUL; | |
6914 p = skipwhite(p); /* skip to next entry */ | |
6915 } | |
6916 } | |
6917 else /* NUL separates */ | |
6918 { | |
6919 while (*p && p < buffer + len) /* skip entry */ | |
6920 ++p; | |
6921 ++p; /* skip NUL */ | |
6922 } | |
6923 } | |
6924 | |
6925 /* | |
6926 * Move the file names to allocated memory. | |
6927 */ | |
6928 for (j = 0, i = 0; i < *num_file; ++i) | |
6929 { | |
6930 /* Require the files to exist. Helps when using /bin/sh */ | |
6931 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) | |
6932 continue; | |
6933 | |
6934 /* check if this entry should be included */ | |
6935 dir = (mch_isdir((*file)[i])); | |
6936 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) | |
6937 continue; | |
6938 | |
715 | 6939 /* Skip files that are not executable if we check for that. */ |
6695 | 6940 if (!dir && (flags & EW_EXEC) |
6941 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) | |
715 | 6942 continue; |
6943 | |
7 | 6944 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); |
6945 if (p) | |
6946 { | |
6947 STRCPY(p, (*file)[i]); | |
6948 if (dir) | |
1479 | 6949 add_pathsep(p); /* add '/' to a directory name */ |
7 | 6950 (*file)[j++] = p; |
6951 } | |
6952 } | |
6953 vim_free(buffer); | |
6954 *num_file = j; | |
6955 | |
6956 if (*num_file == 0) /* rejected all entries */ | |
6957 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
6958 VIM_CLEAR(*file); |
7 | 6959 goto notfound; |
6960 } | |
6961 | |
6962 return OK; | |
6963 | |
6964 notfound: | |
6965 if (flags & EW_NOTFOUND) | |
6966 return save_patterns(num_pat, pat, num_file, file); | |
6967 return FAIL; | |
6968 } | |
6969 | |
6970 #endif /* VMS */ | |
6971 | |
6972 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6973 save_patterns( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6974 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6975 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6976 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6977 char_u ***file) |
7 | 6978 { |
6979 int i; | |
99 | 6980 char_u *s; |
7 | 6981 |
6982 *file = (char_u **)alloc(num_pat * sizeof(char_u *)); | |
6983 if (*file == NULL) | |
6984 return FAIL; | |
6985 for (i = 0; i < num_pat; i++) | |
99 | 6986 { |
6987 s = vim_strsave(pat[i]); | |
6988 if (s != NULL) | |
6989 /* Be compatible with expand_filename(): halve the number of | |
6990 * backslashes. */ | |
6991 backslash_halve(s); | |
6992 (*file)[i] = s; | |
6993 } | |
7 | 6994 *num_file = num_pat; |
6995 return OK; | |
6996 } | |
6997 | |
6998 /* | |
6999 * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can | |
7000 * expand. | |
7001 */ | |
7002 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7003 mch_has_exp_wildcard(char_u *p) |
7 | 7004 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
7005 for ( ; *p; MB_PTR_ADV(p)) |
7 | 7006 { |
7007 if (*p == '\\' && p[1] != NUL) | |
7008 ++p; | |
7009 else | |
7010 if (vim_strchr((char_u *) | |
7011 #ifdef VMS | |
7012 "*?%" | |
7013 #else | |
7014 "*?[{'" | |
7015 #endif | |
7016 , *p) != NULL) | |
7017 return TRUE; | |
7018 } | |
7019 return FALSE; | |
7020 } | |
7021 | |
7022 /* | |
7023 * Return TRUE if the string "p" contains a wildcard. | |
7024 * Don't recognize '~' at the end as a wildcard. | |
7025 */ | |
7026 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7027 mch_has_wildcard(char_u *p) |
7 | 7028 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
7029 for ( ; *p; MB_PTR_ADV(p)) |
7 | 7030 { |
7031 if (*p == '\\' && p[1] != NUL) | |
7032 ++p; | |
7033 else | |
7034 if (vim_strchr((char_u *) | |
7035 #ifdef VMS | |
7036 "*?%$" | |
7037 #else | |
7038 "*?[{`'$" | |
7039 #endif | |
7040 , *p) != NULL | |
7041 || (*p == '~' && p[1] != NUL)) | |
7042 return TRUE; | |
7043 } | |
7044 return FALSE; | |
7045 } | |
7046 | |
7047 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7048 have_wildcard(int num, char_u **file) |
7 | 7049 { |
7050 int i; | |
7051 | |
7052 for (i = 0; i < num; i++) | |
7053 if (mch_has_wildcard(file[i])) | |
7054 return 1; | |
7055 return 0; | |
7056 } | |
7057 | |
7058 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7059 have_dollars(int num, char_u **file) |
7 | 7060 { |
7061 int i; | |
7062 | |
7063 for (i = 0; i < num; i++) | |
7064 if (vim_strchr(file[i], '$') != NULL) | |
7065 return TRUE; | |
7066 return FALSE; | |
7067 } | |
7068 | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7069 #if !defined(HAVE_RENAME) || defined(PROTO) |
7 | 7070 /* |
7071 * Scaled-down version of rename(), which is missing in Xenix. | |
7072 * This version can only move regular files and will fail if the | |
7073 * destination exists. | |
7074 */ | |
7075 int | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7076 mch_rename(const char *src, const char *dest) |
7 | 7077 { |
7078 struct stat st; | |
7079 | |
7080 if (stat(dest, &st) >= 0) /* fail if destination exists */ | |
7081 return -1; | |
7082 if (link(src, dest) != 0) /* link file to new name */ | |
7083 return -1; | |
7084 if (mch_remove(src) == 0) /* delete link to old name */ | |
7085 return 0; | |
7086 return -1; | |
7087 } | |
7088 #endif /* !HAVE_RENAME */ | |
7089 | |
7090 #ifdef FEAT_MOUSE_GPM | |
7091 /* | |
7092 * Initializes connection with gpm (if it isn't already opened) | |
7093 * Return 1 if succeeded (or connection already opened), 0 if failed | |
7094 */ | |
7095 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7096 gpm_open(void) |
7 | 7097 { |
7098 static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ | |
7099 | |
7100 if (!gpm_flag) | |
7101 { | |
7102 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); | |
7103 gpm_connect.defaultMask = ~GPM_HARD; | |
7104 /* Default handling for mouse move*/ | |
7105 gpm_connect.minMod = 0; /* Handle any modifier keys */ | |
7106 gpm_connect.maxMod = 0xffff; | |
7107 if (Gpm_Open(&gpm_connect, 0) > 0) | |
7108 { | |
7109 /* gpm library tries to handling TSTP causes | |
7110 * problems. Anyways, we close connection to Gpm whenever | |
7111 * we are going to suspend or starting an external process | |
1450 | 7112 * so we shouldn't have problem with this |
7 | 7113 */ |
1832 | 7114 # ifdef SIGTSTP |
7 | 7115 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); |
1832 | 7116 # endif |
7 | 7117 return 1; /* succeed */ |
7118 } | |
7119 if (gpm_fd == -2) | |
7120 Gpm_Close(); /* We don't want to talk to xterm via gpm */ | |
7121 return 0; | |
7122 } | |
7123 return 1; /* already open */ | |
7124 } | |
7125 | |
7126 /* | |
7127 * Closes connection to gpm | |
7128 */ | |
7129 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7130 gpm_close(void) |
7 | 7131 { |
7132 if (gpm_flag && gpm_fd >= 0) /* if Open */ | |
7133 Gpm_Close(); | |
7134 } | |
7135 | |
7136 /* Reads gpm event and adds special keys to input buf. Returns length of | |
7137 * generated key sequence. | |
5782 | 7138 * This function is styled after gui_send_mouse_event(). |
7 | 7139 */ |
7140 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7141 mch_gpm_process(void) |
7 | 7142 { |
7143 int button; | |
7144 static Gpm_Event gpm_event; | |
7145 char_u string[6]; | |
7146 int_u vim_modifiers; | |
7147 int row,col; | |
7148 unsigned char buttons_mask; | |
7149 unsigned char gpm_modifiers; | |
7150 static unsigned char old_buttons = 0; | |
7151 | |
7152 Gpm_GetEvent(&gpm_event); | |
7153 | |
7154 #ifdef FEAT_GUI | |
7155 /* Don't put events in the input queue now. */ | |
7156 if (hold_gui_events) | |
7157 return 0; | |
7158 #endif | |
7159 | |
7160 row = gpm_event.y - 1; | |
7161 col = gpm_event.x - 1; | |
7162 | |
7163 string[0] = ESC; /* Our termcode */ | |
7164 string[1] = 'M'; | |
7165 string[2] = 'G'; | |
7166 switch (GPM_BARE_EVENTS(gpm_event.type)) | |
7167 { | |
7168 case GPM_DRAG: | |
7169 string[3] = MOUSE_DRAG; | |
7170 break; | |
7171 case GPM_DOWN: | |
7172 buttons_mask = gpm_event.buttons & ~old_buttons; | |
7173 old_buttons = gpm_event.buttons; | |
7174 switch (buttons_mask) | |
7175 { | |
7176 case GPM_B_LEFT: | |
7177 button = MOUSE_LEFT; | |
7178 break; | |
7179 case GPM_B_MIDDLE: | |
7180 button = MOUSE_MIDDLE; | |
7181 break; | |
7182 case GPM_B_RIGHT: | |
7183 button = MOUSE_RIGHT; | |
7184 break; | |
7185 default: | |
7186 return 0; | |
7187 /*Don't know what to do. Can more than one button be | |
7188 * reported in one event? */ | |
7189 } | |
7190 string[3] = (char_u)(button | 0x20); | |
7191 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); | |
7192 break; | |
7193 case GPM_UP: | |
7194 string[3] = MOUSE_RELEASE; | |
7195 old_buttons &= ~gpm_event.buttons; | |
7196 break; | |
7197 default: | |
7198 return 0; | |
7199 } | |
7200 /*This code is based on gui_x11_mouse_cb in gui_x11.c */ | |
7201 gpm_modifiers = gpm_event.modifiers; | |
7202 vim_modifiers = 0x0; | |
7203 /* I ignore capslock stats. Aren't we all just hate capslock mixing with | |
7204 * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and | |
7205 * K_CAPSSHIFT is defined 8, so it probably isn't even reported | |
7206 */ | |
7207 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) | |
7208 vim_modifiers |= MOUSE_SHIFT; | |
7209 | |
7210 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL))) | |
7211 vim_modifiers |= MOUSE_CTRL; | |
7212 if (gpm_modifiers & ((1 << KG_ALT) | (1 << KG_ALTGR))) | |
7213 vim_modifiers |= MOUSE_ALT; | |
7214 string[3] |= vim_modifiers; | |
7215 string[4] = (char_u)(col + ' ' + 1); | |
7216 string[5] = (char_u)(row + ' ' + 1); | |
7217 add_to_input_buf(string, 6); | |
7218 return 6; | |
7219 } | |
7220 #endif /* FEAT_MOUSE_GPM */ | |
7221 | |
1620 | 7222 #ifdef FEAT_SYSMOUSE |
7223 /* | |
7224 * Initialize connection with sysmouse. | |
7225 * Let virtual console inform us with SIGUSR2 for pending sysmouse | |
7226 * output, any sysmouse output than will be processed via sig_sysmouse(). | |
7227 * Return OK if succeeded, FAIL if failed. | |
7228 */ | |
7229 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7230 sysmouse_open(void) |
1620 | 7231 { |
7232 struct mouse_info mouse; | |
7233 | |
7234 mouse.operation = MOUSE_MODE; | |
7235 mouse.u.mode.mode = 0; | |
7236 mouse.u.mode.signal = SIGUSR2; | |
7237 if (ioctl(1, CONS_MOUSECTL, &mouse) != -1) | |
7238 { | |
7239 signal(SIGUSR2, (RETSIGTYPE (*)())sig_sysmouse); | |
7240 mouse.operation = MOUSE_SHOW; | |
7241 ioctl(1, CONS_MOUSECTL, &mouse); | |
7242 return OK; | |
7243 } | |
7244 return FAIL; | |
7245 } | |
7246 | |
7247 /* | |
7248 * Stop processing SIGUSR2 signals, and also make sure that | |
7249 * virtual console do not send us any sysmouse related signal. | |
7250 */ | |
7251 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7252 sysmouse_close(void) |
1620 | 7253 { |
7254 struct mouse_info mouse; | |
7255 | |
7256 signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL); | |
7257 mouse.operation = MOUSE_MODE; | |
7258 mouse.u.mode.mode = 0; | |
7259 mouse.u.mode.signal = 0; | |
7260 ioctl(1, CONS_MOUSECTL, &mouse); | |
7261 } | |
7262 | |
7263 /* | |
7264 * Gets info from sysmouse and adds special keys to input buf. | |
7265 */ | |
7266 static RETSIGTYPE | |
7267 sig_sysmouse SIGDEFARG(sigarg) | |
7268 { | |
7269 struct mouse_info mouse; | |
7270 struct video_info video; | |
7271 char_u string[6]; | |
7272 int row, col; | |
7273 int button; | |
7274 int buttons; | |
7275 static int oldbuttons = 0; | |
7276 | |
7277 #ifdef FEAT_GUI | |
7278 /* Don't put events in the input queue now. */ | |
7279 if (hold_gui_events) | |
7280 return; | |
7281 #endif | |
7282 | |
7283 mouse.operation = MOUSE_GETINFO; | |
7284 if (ioctl(1, FBIO_GETMODE, &video.vi_mode) != -1 | |
7285 && ioctl(1, FBIO_MODEINFO, &video) != -1 | |
7286 && ioctl(1, CONS_MOUSECTL, &mouse) != -1 | |
7287 && video.vi_cheight > 0 && video.vi_cwidth > 0) | |
7288 { | |
7289 row = mouse.u.data.y / video.vi_cheight; | |
7290 col = mouse.u.data.x / video.vi_cwidth; | |
7291 buttons = mouse.u.data.buttons; | |
7292 string[0] = ESC; /* Our termcode */ | |
7293 string[1] = 'M'; | |
7294 string[2] = 'S'; | |
7295 if (oldbuttons == buttons && buttons != 0) | |
7296 { | |
7297 button = MOUSE_DRAG; | |
7298 } | |
7299 else | |
7300 { | |
7301 switch (buttons) | |
7302 { | |
7303 case 0: | |
7304 button = MOUSE_RELEASE; | |
7305 break; | |
7306 case 1: | |
7307 button = MOUSE_LEFT; | |
7308 break; | |
7309 case 2: | |
7310 button = MOUSE_MIDDLE; | |
7311 break; | |
7312 case 4: | |
7313 button = MOUSE_RIGHT; | |
7314 break; | |
7315 default: | |
7316 return; | |
7317 } | |
7318 oldbuttons = buttons; | |
7319 } | |
7320 string[3] = (char_u)(button); | |
7321 string[4] = (char_u)(col + ' ' + 1); | |
7322 string[5] = (char_u)(row + ' ' + 1); | |
7323 add_to_input_buf(string, 6); | |
7324 } | |
7325 return; | |
7326 } | |
7327 #endif /* FEAT_SYSMOUSE */ | |
7328 | |
7 | 7329 #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
|
7330 typedef char_u * (*STRPROCSTR)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7331 typedef char_u * (*INTPROCSTR)(int); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7332 typedef int (*STRPROCINT)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7333 typedef int (*INTPROCINT)(int); |
7 | 7334 |
7335 /* | |
7336 * Call a DLL routine which takes either a string or int param | |
7337 * and returns an allocated string. | |
7338 */ | |
7339 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7340 mch_libcall( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7341 char_u *libname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7342 char_u *funcname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7343 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
|
7344 int argint, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7345 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
|
7346 int *number_result) |
7 | 7347 { |
7348 # if defined(USE_DLOPEN) | |
7349 void *hinstLib; | |
12 | 7350 char *dlerr = NULL; |
7 | 7351 # else |
7352 shl_t hinstLib; | |
7353 # endif | |
7354 STRPROCSTR ProcAdd; | |
7355 INTPROCSTR ProcAddI; | |
7356 char_u *retval_str = NULL; | |
7357 int retval_int = 0; | |
7358 int success = FALSE; | |
7359 | |
900 | 7360 /* |
7361 * Get a handle to the DLL module. | |
7362 */ | |
7 | 7363 # if defined(USE_DLOPEN) |
900 | 7364 /* First clear any error, it's not cleared by the dlopen() call. */ |
7365 (void)dlerror(); | |
7366 | |
7 | 7367 hinstLib = dlopen((char *)libname, RTLD_LAZY |
7368 # ifdef RTLD_LOCAL | |
7369 | RTLD_LOCAL | |
7370 # endif | |
7371 ); | |
12 | 7372 if (hinstLib == NULL) |
7373 { | |
7374 /* "dlerr" must be used before dlclose() */ | |
7375 dlerr = (char *)dlerror(); | |
7376 if (dlerr != NULL) | |
7377 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7378 } | |
7 | 7379 # else |
7380 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); | |
7381 # endif | |
7382 | |
7383 /* If the handle is valid, try to get the function address. */ | |
7384 if (hinstLib != NULL) | |
7385 { | |
7386 # ifdef HAVE_SETJMP_H | |
7387 /* | |
7388 * Catch a crash when calling the library function. For example when | |
7389 * using a number where a string pointer is expected. | |
7390 */ | |
7391 mch_startjmp(); | |
7392 if (SETJMP(lc_jump_env) != 0) | |
7393 { | |
7394 success = FALSE; | |
857 | 7395 # if defined(USE_DLOPEN) |
12 | 7396 dlerr = NULL; |
857 | 7397 # endif |
7 | 7398 mch_didjmp(); |
7399 } | |
7400 else | |
7401 # endif | |
7402 { | |
7403 retval_str = NULL; | |
7404 retval_int = 0; | |
7405 | |
7406 if (argstring != NULL) | |
7407 { | |
7408 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7409 *(void **)(&ProcAdd) = dlsym(hinstLib, (const char *)funcname); |
12 | 7410 dlerr = (char *)dlerror(); |
7 | 7411 # else |
7412 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7413 TYPE_PROCEDURE, (void *)&ProcAdd) < 0) | |
7414 ProcAdd = NULL; | |
7415 # endif | |
12 | 7416 if ((success = (ProcAdd != NULL |
7417 # if defined(USE_DLOPEN) | |
7418 && dlerr == NULL | |
7419 # endif | |
7420 ))) | |
7 | 7421 { |
7422 if (string_result == NULL) | |
7423 retval_int = ((STRPROCINT)ProcAdd)(argstring); | |
7424 else | |
7425 retval_str = (ProcAdd)(argstring); | |
7426 } | |
7427 } | |
7428 else | |
7429 { | |
7430 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7431 *(void **)(&ProcAddI) = dlsym(hinstLib, (const char *)funcname); |
12 | 7432 dlerr = (char *)dlerror(); |
7 | 7433 # else |
7434 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7435 TYPE_PROCEDURE, (void *)&ProcAddI) < 0) | |
7436 ProcAddI = NULL; | |
7437 # endif | |
12 | 7438 if ((success = (ProcAddI != NULL |
7439 # if defined(USE_DLOPEN) | |
7440 && dlerr == NULL | |
7441 # endif | |
7442 ))) | |
7 | 7443 { |
7444 if (string_result == NULL) | |
7445 retval_int = ((INTPROCINT)ProcAddI)(argint); | |
7446 else | |
7447 retval_str = (ProcAddI)(argint); | |
7448 } | |
7449 } | |
7450 | |
7451 /* Save the string before we free the library. */ | |
7452 /* Assume that a "1" or "-1" result is an illegal pointer. */ | |
7453 if (string_result == NULL) | |
7454 *number_result = retval_int; | |
7455 else if (retval_str != NULL | |
7456 && retval_str != (char_u *)1 | |
7457 && retval_str != (char_u *)-1) | |
7458 *string_result = vim_strsave(retval_str); | |
7459 } | |
7460 | |
7461 # ifdef HAVE_SETJMP_H | |
7462 mch_endjmp(); | |
7463 # ifdef SIGHASARG | |
7464 if (lc_signal != 0) | |
7465 { | |
7466 int i; | |
7467 | |
7468 /* try to find the name of this signal */ | |
7469 for (i = 0; signal_info[i].sig != -1; i++) | |
7470 if (lc_signal == signal_info[i].sig) | |
7471 break; | |
7472 EMSG2("E368: got SIG%s in libcall()", signal_info[i].name); | |
7473 } | |
7474 # endif | |
7475 # endif | |
7476 | |
12 | 7477 # if defined(USE_DLOPEN) |
7478 /* "dlerr" must be used before dlclose() */ | |
7479 if (dlerr != NULL) | |
7480 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7481 | |
7 | 7482 /* Free the DLL module. */ |
7483 (void)dlclose(hinstLib); | |
7484 # else | |
7485 (void)shl_unload(hinstLib); | |
7486 # endif | |
7487 } | |
7488 | |
7489 if (!success) | |
7490 { | |
7491 EMSG2(_(e_libcall), funcname); | |
7492 return FAIL; | |
7493 } | |
7494 | |
7495 return OK; | |
7496 } | |
7497 #endif | |
7498 | |
7499 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) | |
7500 static int xterm_trace = -1; /* default: disabled */ | |
7501 static int xterm_button; | |
7502 | |
7503 /* | |
7504 * Setup a dummy window for X selections in a terminal. | |
7505 */ | |
7506 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7507 setup_term_clip(void) |
7 | 7508 { |
7509 int z = 0; | |
7510 char *strp = ""; | |
7511 Widget AppShell; | |
7512 | |
7513 if (!x_connect_to_server()) | |
7514 return; | |
7515 | |
7516 open_app_context(); | |
7517 if (app_context != NULL && xterm_Shell == (Widget)0) | |
7518 { | |
7519 int (*oldhandler)(); | |
7520 #if defined(HAVE_SETJMP_H) | |
7521 int (*oldIOhandler)(); | |
7522 #endif | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7523 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7524 ELAPSED_TYPE start_tv; |
7 | 7525 |
7526 if (p_verbose > 0) | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7527 ELAPSED_INIT(start_tv); |
7 | 7528 # endif |
7529 | |
7530 /* Ignore X errors while opening the display */ | |
7531 oldhandler = XSetErrorHandler(x_error_check); | |
7532 | |
7533 #if defined(HAVE_SETJMP_H) | |
7534 /* Ignore X IO errors while opening the display */ | |
7535 oldIOhandler = XSetIOErrorHandler(x_IOerror_check); | |
7536 mch_startjmp(); | |
7537 if (SETJMP(lc_jump_env) != 0) | |
7538 { | |
7539 mch_didjmp(); | |
7540 xterm_dpy = NULL; | |
7541 } | |
7542 else | |
7543 #endif | |
7544 { | |
7545 xterm_dpy = XtOpenDisplay(app_context, xterm_display, | |
7546 "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); | |
7547 #if defined(HAVE_SETJMP_H) | |
7548 mch_endjmp(); | |
7549 #endif | |
7550 } | |
7551 | |
7552 #if defined(HAVE_SETJMP_H) | |
7553 /* Now handle X IO errors normally. */ | |
7554 (void)XSetIOErrorHandler(oldIOhandler); | |
7555 #endif | |
7556 /* Now handle X errors normally. */ | |
7557 (void)XSetErrorHandler(oldhandler); | |
7558 | |
7559 if (xterm_dpy == NULL) | |
7560 { | |
7561 if (p_verbose > 0) | |
292 | 7562 verb_msg((char_u *)_("Opening the X display failed")); |
7 | 7563 return; |
7564 } | |
7565 | |
7566 /* Catch terminating error of the X server connection. */ | |
7567 (void)XSetIOErrorHandler(x_IOerror_handler); | |
7568 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7569 # ifdef ELAPSED_FUNC |
7 | 7570 if (p_verbose > 0) |
292 | 7571 { |
7572 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7573 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 7574 verbose_leave(); |
7575 } | |
7 | 7576 # endif |
7577 | |
7578 /* Create a Shell to make converters work. */ | |
7579 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", | |
7580 applicationShellWidgetClass, xterm_dpy, | |
7581 NULL); | |
7582 if (AppShell == (Widget)0) | |
7583 return; | |
7584 xterm_Shell = XtVaCreatePopupShell("VIM", | |
7585 topLevelShellWidgetClass, AppShell, | |
7586 XtNmappedWhenManaged, 0, | |
7587 XtNwidth, 1, | |
7588 XtNheight, 1, | |
7589 NULL); | |
7590 if (xterm_Shell == (Widget)0) | |
7591 return; | |
7592 | |
7593 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
|
7594 x11_setup_selection(xterm_Shell); |
7 | 7595 if (x11_display == NULL) |
7596 x11_display = xterm_dpy; | |
7597 | |
7598 XtRealizeWidget(xterm_Shell); | |
7599 XSync(xterm_dpy, False); | |
7600 xterm_update(); | |
7601 } | |
7602 if (xterm_Shell != (Widget)0) | |
7603 { | |
7604 clip_init(TRUE); | |
7605 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) | |
7606 x11_window = (Window)atol(strp); | |
7607 /* Check if $WINDOWID is valid. */ | |
7608 if (test_x11_window(xterm_dpy) == FAIL) | |
7609 x11_window = 0; | |
7610 if (x11_window != 0) | |
7611 xterm_trace = 0; | |
7612 } | |
7613 } | |
7614 | |
7615 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7616 start_xterm_trace(int button) |
7 | 7617 { |
7618 if (x11_window == 0 || xterm_trace < 0 || xterm_Shell == (Widget)0) | |
7619 return; | |
7620 xterm_trace = 1; | |
7621 xterm_button = button; | |
7622 do_xterm_trace(); | |
7623 } | |
7624 | |
7625 | |
7626 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7627 stop_xterm_trace(void) |
7 | 7628 { |
7629 if (xterm_trace < 0) | |
7630 return; | |
7631 xterm_trace = 0; | |
7632 } | |
7633 | |
7634 /* | |
7635 * Query the xterm pointer and generate mouse termcodes if necessary | |
7636 * return TRUE if dragging is active, else FALSE | |
7637 */ | |
7638 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7639 do_xterm_trace(void) |
7 | 7640 { |
7641 Window root, child; | |
7642 int root_x, root_y; | |
7643 int win_x, win_y; | |
7644 int row, col; | |
7645 int_u mask_return; | |
7646 char_u buf[50]; | |
7647 char_u *strp; | |
7648 long got_hints; | |
7649 static char_u *mouse_code; | |
7650 static char_u mouse_name[2] = {KS_MOUSE, KE_FILLER}; | |
7651 static int prev_row = 0, prev_col = 0; | |
7652 static XSizeHints xterm_hints; | |
7653 | |
7654 if (xterm_trace <= 0) | |
7655 return FALSE; | |
7656 | |
7657 if (xterm_trace == 1) | |
7658 { | |
7659 /* Get the hints just before tracking starts. The font size might | |
1510 | 7660 * have changed recently. */ |
7661 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) | |
7662 || !(got_hints & PResizeInc) | |
7 | 7663 || xterm_hints.width_inc <= 1 |
7664 || xterm_hints.height_inc <= 1) | |
7665 { | |
7666 xterm_trace = -1; /* Not enough data -- disable tracing */ | |
7667 return FALSE; | |
7668 } | |
7669 | |
7670 /* Rely on the same mouse code for the duration of this */ | |
7671 mouse_code = find_termcode(mouse_name); | |
7672 prev_row = mouse_row; | |
7009 | 7673 prev_col = mouse_col; |
7 | 7674 xterm_trace = 2; |
7675 | |
7676 /* Find the offset of the chars, there might be a scrollbar on the | |
7677 * left of the window and/or a menu on the top (eterm etc.) */ | |
7678 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7679 &win_x, &win_y, &mask_return); | |
7680 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) | |
7681 - (xterm_hints.height_inc / 2); | |
7682 if (xterm_hints.y <= xterm_hints.height_inc / 2) | |
7683 xterm_hints.y = 2; | |
7684 xterm_hints.x = win_x - (xterm_hints.width_inc * mouse_col) | |
7685 - (xterm_hints.width_inc / 2); | |
7686 if (xterm_hints.x <= xterm_hints.width_inc / 2) | |
7687 xterm_hints.x = 2; | |
7688 return TRUE; | |
7689 } | |
2768 | 7690 if (mouse_code == NULL || STRLEN(mouse_code) > 45) |
7 | 7691 { |
7692 xterm_trace = 0; | |
7693 return FALSE; | |
7694 } | |
7695 | |
7696 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7697 &win_x, &win_y, &mask_return); | |
7698 | |
7699 row = check_row((win_y - xterm_hints.y) / xterm_hints.height_inc); | |
7700 col = check_col((win_x - xterm_hints.x) / xterm_hints.width_inc); | |
7701 if (row == prev_row && col == prev_col) | |
7702 return TRUE; | |
7703 | |
7704 STRCPY(buf, mouse_code); | |
7705 strp = buf + STRLEN(buf); | |
7706 *strp++ = (xterm_button | MOUSE_DRAG) & ~0x20; | |
7707 *strp++ = (char_u)(col + ' ' + 1); | |
7708 *strp++ = (char_u)(row + ' ' + 1); | |
7709 *strp = 0; | |
7710 add_to_input_buf(buf, STRLEN(buf)); | |
7711 | |
7712 prev_row = row; | |
7713 prev_col = col; | |
7714 return TRUE; | |
7715 } | |
7716 | |
7717 # if defined(FEAT_GUI) || defined(PROTO) | |
7718 /* | |
7719 * Destroy the display, window and app_context. Required for GTK. | |
7720 */ | |
7721 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7722 clear_xterm_clip(void) |
7 | 7723 { |
7724 if (xterm_Shell != (Widget)0) | |
7725 { | |
7726 XtDestroyWidget(xterm_Shell); | |
7727 xterm_Shell = (Widget)0; | |
7728 } | |
7729 if (xterm_dpy != NULL) | |
7730 { | |
1605 | 7731 # if 0 |
7 | 7732 /* Lesstif and Solaris crash here, lose some memory */ |
7733 XtCloseDisplay(xterm_dpy); | |
1605 | 7734 # endif |
7 | 7735 if (x11_display == xterm_dpy) |
7736 x11_display = NULL; | |
7737 xterm_dpy = NULL; | |
7738 } | |
1605 | 7739 # if 0 |
7 | 7740 if (app_context != (XtAppContext)NULL) |
7741 { | |
7742 /* Lesstif and Solaris crash here, lose some memory */ | |
7743 XtDestroyApplicationContext(app_context); | |
7744 app_context = (XtAppContext)NULL; | |
7745 } | |
1605 | 7746 # endif |
7 | 7747 } |
7748 # endif | |
7749 | |
7750 /* | |
4230 | 7751 * Catch up with GUI or X events. |
7752 */ | |
7753 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7754 clip_update(void) |
4230 | 7755 { |
7756 # ifdef FEAT_GUI | |
7757 if (gui.in_use) | |
7758 gui_mch_update(); | |
7759 else | |
7760 # endif | |
7761 if (xterm_Shell != (Widget)0) | |
7762 xterm_update(); | |
7763 } | |
7764 | |
7765 /* | |
7 | 7766 * Catch up with any queued X events. This may put keyboard input into the |
7767 * input buffer, call resize call-backs, trigger timers etc. If there is | |
7768 * nothing in the X event queue (& no timers pending), then we return | |
7769 * immediately. | |
7770 */ | |
7771 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7772 xterm_update(void) |
7 | 7773 { |
7774 XEvent event; | |
7775 | |
6683 | 7776 for (;;) |
7 | 7777 { |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7778 XtInputMask mask = XtAppPending(app_context); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7779 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7780 if (mask == 0 || vim_is_input_buf_full()) |
6683 | 7781 break; |
7782 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7783 if (mask & XtIMXEvent) |
7 | 7784 { |
6683 | 7785 /* 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
|
7786 XtAppNextEvent(app_context, &event); |
6683 | 7787 #ifdef FEAT_CLIENTSERVER |
7788 { | |
7789 XPropertyEvent *e = (XPropertyEvent *)&event; | |
7790 | |
7791 if (e->type == PropertyNotify && e->window == commWindow | |
7 | 7792 && 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
|
7793 serverEventProc(xterm_dpy, &event, 0); |
6683 | 7794 } |
7795 #endif | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7796 XtDispatchEvent(&event); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7797 } |
6683 | 7798 else |
7799 { | |
7800 /* 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
|
7801 XtAppProcessEvent(app_context, mask); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7802 } |
7 | 7803 } |
7804 } | |
7805 | |
7806 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7807 clip_xterm_own_selection(VimClipboard *cbd) |
7 | 7808 { |
7809 if (xterm_Shell != (Widget)0) | |
7810 return clip_x11_own_selection(xterm_Shell, cbd); | |
7811 return FAIL; | |
7812 } | |
7813 | |
7814 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7815 clip_xterm_lose_selection(VimClipboard *cbd) |
7 | 7816 { |
7817 if (xterm_Shell != (Widget)0) | |
7818 clip_x11_lose_selection(xterm_Shell, cbd); | |
7819 } | |
7820 | |
7821 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7822 clip_xterm_request_selection(VimClipboard *cbd) |
7 | 7823 { |
7824 if (xterm_Shell != (Widget)0) | |
7825 clip_x11_request_selection(xterm_Shell, xterm_dpy, cbd); | |
7826 } | |
7827 | |
7828 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7829 clip_xterm_set_selection(VimClipboard *cbd) |
7 | 7830 { |
7831 clip_x11_set_selection(cbd); | |
7832 } | |
7833 #endif | |
7834 | |
7835 | |
7836 #if defined(USE_XSMP) || defined(PROTO) | |
7837 /* | |
7838 * Code for X Session Management Protocol. | |
7839 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7840 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
|
7841 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
|
7842 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
|
7843 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
|
7844 static void xsmp_ice_connection(IceConn iceConn, IcePointer clientData, Bool opening, IcePointer *watchData); |
7 | 7845 |
7846 | |
7847 # 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
|
7848 static void xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data); |
7 | 7849 |
7850 /* | |
7851 * This is our chance to ask the user if they want to save, | |
7852 * or abort the logout | |
7853 */ | |
7854 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7855 xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data UNUSED) |
7 | 7856 { |
7857 cmdmod_T save_cmdmod; | |
7858 int cancel_shutdown = False; | |
7859 | |
7860 save_cmdmod = cmdmod; | |
7861 cmdmod.confirm = TRUE; | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7420
diff
changeset
|
7862 if (check_changed_any(FALSE, FALSE)) |
7 | 7863 /* Mustn't logout */ |
7864 cancel_shutdown = True; | |
7865 cmdmod = save_cmdmod; | |
7866 setcursor(); /* position cursor */ | |
7867 out_flush(); | |
7868 | |
7869 /* Done interaction */ | |
7870 SmcInteractDone(smc_conn, cancel_shutdown); | |
7871 | |
7872 /* Finish off | |
7873 * Only end save-yourself here if we're not cancelling shutdown; | |
7874 * we'll get a cancelled callback later in which we'll end it. | |
7875 * Hopefully get around glitchy SMs (like GNOME-1) | |
7876 */ | |
7877 if (!cancel_shutdown) | |
7878 { | |
7879 xsmp.save_yourself = False; | |
7880 SmcSaveYourselfDone(smc_conn, True); | |
7881 } | |
7882 } | |
7883 # endif | |
7884 | |
7885 /* | |
7886 * Callback that starts save-yourself. | |
7887 */ | |
7888 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7889 xsmp_handle_save_yourself( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7890 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7891 SmPointer client_data UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7892 int save_type UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7893 Bool shutdown, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7894 int interact_style UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7895 Bool fast UNUSED) |
7 | 7896 { |
7897 /* Handle already being in saveyourself */ | |
7898 if (xsmp.save_yourself) | |
7899 SmcSaveYourselfDone(smc_conn, True); | |
7900 xsmp.save_yourself = True; | |
7901 xsmp.shutdown = shutdown; | |
7902 | |
7903 /* First up, preserve all files */ | |
7904 out_flush(); | |
7905 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
7906 | |
7907 if (p_verbose > 0) | |
292 | 7908 verb_msg((char_u *)_("XSMP handling save-yourself request")); |
7 | 7909 |
7910 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7911 /* Now see if we can ask about unsaved files */ | |
7912 if (shutdown && !fast && gui.in_use) | |
7913 /* Need to interact with user, but need SM's permission */ | |
7914 SmcInteractRequest(smc_conn, SmDialogError, | |
7915 xsmp_handle_interaction, client_data); | |
7916 else | |
7917 # endif | |
7918 { | |
7919 /* Can stop the cycle here */ | |
7920 SmcSaveYourselfDone(smc_conn, True); | |
7921 xsmp.save_yourself = False; | |
7922 } | |
7923 } | |
7924 | |
7925 | |
7926 /* | |
7927 * Callback to warn us of imminent death. | |
7928 */ | |
7929 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7930 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED) |
7 | 7931 { |
7932 xsmp_close(); | |
7933 | |
7934 /* quit quickly leaving swapfiles for modified buffers behind */ | |
7935 getout_preserve_modified(0); | |
7936 } | |
7937 | |
7938 | |
7939 /* | |
7940 * Callback to tell us that save-yourself has completed. | |
7941 */ | |
7942 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7943 xsmp_save_complete( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7944 SmcConn smc_conn UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7945 SmPointer client_data UNUSED) |
7 | 7946 { |
7947 xsmp.save_yourself = False; | |
7948 } | |
7949 | |
7950 | |
7951 /* | |
7952 * Callback to tell us that an instigated shutdown was cancelled | |
7953 * (maybe even by us) | |
7954 */ | |
7955 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7956 xsmp_shutdown_cancelled( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7957 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7958 SmPointer client_data UNUSED) |
7 | 7959 { |
7960 if (xsmp.save_yourself) | |
7961 SmcSaveYourselfDone(smc_conn, True); | |
7962 xsmp.save_yourself = False; | |
7963 xsmp.shutdown = False; | |
7964 } | |
7965 | |
7966 | |
7967 /* | |
7968 * Callback to tell us that a new ICE connection has been established. | |
7969 */ | |
7970 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7971 xsmp_ice_connection( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7972 IceConn iceConn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7973 IcePointer clientData UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7974 Bool opening, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7975 IcePointer *watchData UNUSED) |
7 | 7976 { |
7977 /* Intercept creation of ICE connection fd */ | |
7978 if (opening) | |
7979 { | |
7980 xsmp_icefd = IceConnectionNumber(iceConn); | |
7981 IceRemoveConnectionWatch(xsmp_ice_connection, NULL); | |
7982 } | |
7983 } | |
7984 | |
7985 | |
7986 /* Handle any ICE processing that's required; return FAIL if SM lost */ | |
7987 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7988 xsmp_handle_requests(void) |
7 | 7989 { |
7990 Bool rep; | |
7991 | |
7992 if (IceProcessMessages(xsmp.iceconn, NULL, &rep) | |
7993 == IceProcessMessagesIOError) | |
7994 { | |
7995 /* Lost ICE */ | |
7996 if (p_verbose > 0) | |
292 | 7997 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 7998 xsmp_close(); |
7999 return FAIL; | |
8000 } | |
8001 else | |
8002 return OK; | |
8003 } | |
8004 | |
8005 static int dummy; | |
8006 | |
8007 /* Set up X Session Management Protocol */ | |
8008 void | |
8009 xsmp_init(void) | |
8010 { | |
8011 char errorstring[80]; | |
8012 SmcCallbacks smcallbacks; | |
8013 #if 0 | |
8014 SmPropValue smname; | |
8015 SmProp smnameprop; | |
8016 SmProp *smprops[1]; | |
8017 #endif | |
8018 | |
8019 if (p_verbose > 0) | |
292 | 8020 verb_msg((char_u *)_("XSMP opening connection")); |
7 | 8021 |
8022 xsmp.save_yourself = xsmp.shutdown = False; | |
8023 | |
8024 /* Set up SM callbacks - must have all, even if they're not used */ | |
8025 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; | |
8026 smcallbacks.save_yourself.client_data = NULL; | |
8027 smcallbacks.die.callback = xsmp_die; | |
8028 smcallbacks.die.client_data = NULL; | |
8029 smcallbacks.save_complete.callback = xsmp_save_complete; | |
8030 smcallbacks.save_complete.client_data = NULL; | |
8031 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; | |
8032 smcallbacks.shutdown_cancelled.client_data = NULL; | |
8033 | |
8034 /* Set up a watch on ICE connection creations. The "dummy" argument is | |
8035 * apparently required for FreeBSD (we get a BUS error when using NULL). */ | |
8036 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) | |
8037 { | |
8038 if (p_verbose > 0) | |
292 | 8039 verb_msg((char_u *)_("XSMP ICE connection watch failed")); |
7 | 8040 return; |
8041 } | |
8042 | |
8043 /* Create an SM connection */ | |
8044 xsmp.smcconn = SmcOpenConnection( | |
8045 NULL, | |
8046 NULL, | |
8047 SmProtoMajor, | |
8048 SmProtoMinor, | |
8049 SmcSaveYourselfProcMask | SmcDieProcMask | |
8050 | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
8051 &smcallbacks, | |
8052 NULL, | |
1605 | 8053 &xsmp.clientid, |
7 | 8054 sizeof(errorstring), |
8055 errorstring); | |
8056 if (xsmp.smcconn == NULL) | |
8057 { | |
8058 char errorreport[132]; | |
273 | 8059 |
292 | 8060 if (p_verbose > 0) |
8061 { | |
8062 vim_snprintf(errorreport, sizeof(errorreport), | |
273 | 8063 _("XSMP SmcOpenConnection failed: %s"), errorstring); |
292 | 8064 verb_msg((char_u *)errorreport); |
8065 } | |
7 | 8066 return; |
8067 } | |
8068 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); | |
8069 | |
8070 #if 0 | |
8071 /* ID ourselves */ | |
8072 smname.value = "vim"; | |
8073 smname.length = 3; | |
8074 smnameprop.name = "SmProgram"; | |
8075 smnameprop.type = "SmARRAY8"; | |
8076 smnameprop.num_vals = 1; | |
8077 smnameprop.vals = &smname; | |
8078 | |
8079 smprops[0] = &smnameprop; | |
8080 SmcSetProperties(xsmp.smcconn, 1, smprops); | |
8081 #endif | |
8082 } | |
8083 | |
8084 | |
8085 /* Shut down XSMP comms. */ | |
8086 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8087 xsmp_close(void) |
7 | 8088 { |
8089 if (xsmp_icefd != -1) | |
8090 { | |
8091 SmcCloseConnection(xsmp.smcconn, 0, NULL); | |
1737 | 8092 if (xsmp.clientid != NULL) |
8093 free(xsmp.clientid); | |
1605 | 8094 xsmp.clientid = NULL; |
7 | 8095 xsmp_icefd = -1; |
8096 } | |
8097 } | |
8098 #endif /* USE_XSMP */ | |
8099 | |
8100 | |
8101 #ifdef EBCDIC | |
8102 /* Translate character to its CTRL- value */ | |
8103 char CtrlTable[] = | |
8104 { | |
8105 /* 00 - 5E */ | |
8106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8112 /* ^ */ 0x1E, | |
8113 /* - */ 0x1F, | |
8114 /* 61 - 6C */ | |
8115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8116 /* _ */ 0x1F, | |
8117 /* 6E - 80 */ | |
8118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8119 /* a */ 0x01, | |
8120 /* b */ 0x02, | |
8121 /* c */ 0x03, | |
8122 /* d */ 0x37, | |
8123 /* e */ 0x2D, | |
8124 /* f */ 0x2E, | |
8125 /* g */ 0x2F, | |
8126 /* h */ 0x16, | |
8127 /* i */ 0x05, | |
8128 /* 8A - 90 */ | |
8129 0, 0, 0, 0, 0, 0, 0, | |
8130 /* j */ 0x15, | |
8131 /* k */ 0x0B, | |
8132 /* l */ 0x0C, | |
8133 /* m */ 0x0D, | |
8134 /* n */ 0x0E, | |
8135 /* o */ 0x0F, | |
8136 /* p */ 0x10, | |
8137 /* q */ 0x11, | |
8138 /* r */ 0x12, | |
8139 /* 9A - A1 */ | |
8140 0, 0, 0, 0, 0, 0, 0, 0, | |
8141 /* s */ 0x13, | |
8142 /* t */ 0x3C, | |
8143 /* u */ 0x3D, | |
8144 /* v */ 0x32, | |
8145 /* w */ 0x26, | |
8146 /* x */ 0x18, | |
8147 /* y */ 0x19, | |
8148 /* z */ 0x3F, | |
8149 /* AA - AC */ | |
8150 0, 0, 0, | |
8151 /* [ */ 0x27, | |
8152 /* AE - BC */ | |
8153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8154 /* ] */ 0x1D, | |
8155 /* BE - C0 */ 0, 0, 0, | |
8156 /* A */ 0x01, | |
8157 /* B */ 0x02, | |
8158 /* C */ 0x03, | |
8159 /* D */ 0x37, | |
8160 /* E */ 0x2D, | |
8161 /* F */ 0x2E, | |
8162 /* G */ 0x2F, | |
8163 /* H */ 0x16, | |
8164 /* I */ 0x05, | |
8165 /* CA - D0 */ 0, 0, 0, 0, 0, 0, 0, | |
8166 /* J */ 0x15, | |
8167 /* K */ 0x0B, | |
8168 /* L */ 0x0C, | |
8169 /* M */ 0x0D, | |
8170 /* N */ 0x0E, | |
8171 /* O */ 0x0F, | |
8172 /* P */ 0x10, | |
8173 /* Q */ 0x11, | |
8174 /* R */ 0x12, | |
8175 /* DA - DF */ 0, 0, 0, 0, 0, 0, | |
8176 /* \ */ 0x1C, | |
8177 /* E1 */ 0, | |
8178 /* S */ 0x13, | |
8179 /* T */ 0x3C, | |
8180 /* U */ 0x3D, | |
8181 /* V */ 0x32, | |
8182 /* W */ 0x26, | |
8183 /* X */ 0x18, | |
8184 /* Y */ 0x19, | |
8185 /* Z */ 0x3F, | |
8186 /* EA - FF*/ 0, 0, 0, 0, 0, 0, | |
8187 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8188 }; | |
8189 | |
8190 char MetaCharTable[]= | |
8191 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
8192 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, | |
8193 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, | |
8194 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, | |
8195 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0 | |
8196 }; | |
8197 | |
8198 | |
8199 /* TODO: Use characters NOT numbers!!! */ | |
8200 char CtrlCharTable[]= | |
8201 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
8202 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, | |
8203 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, | |
8204 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, | |
8205 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233, | |
8206 }; | |
8207 | |
8208 | |
8209 #endif |