Mercurial > vim
annotate src/os_unix.c @ 15559:59d32a45da1a v8.1.0787
patch 8.1.0787: compiler warning for unused function
commit https://github.com/vim/vim/commit/edce7420d044a503f38284188770efba87121bd6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 20 18:39:30 2019 +0100
patch 8.1.0787: compiler warning for unused function
Problem: Compiler warning for unused function. (Tony Mechelynck)
Solution: Tune #ifdef around setjmp functions.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 20 Jan 2019 18:45:05 +0100 |
parents | d89c5b339c2a |
children | ea9f1180d337 |
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 #include "vim.h" | |
22 | |
14 | 23 #ifdef FEAT_MZSCHEME |
24 # include "if_mzsch.h" | |
25 #endif | |
26 | |
7 | 27 #include "os_unixx.h" /* unix includes for os_unix.c only */ |
28 | |
29 #ifdef USE_XSMP | |
30 # include <X11/SM/SMlib.h> | |
31 #endif | |
32 | |
1583 | 33 #ifdef HAVE_SELINUX |
34 # include <selinux/selinux.h> | |
35 static int selinux_enabled = -1; | |
36 #endif | |
37 | |
5788 | 38 #ifdef HAVE_SMACK |
39 # include <attr/xattr.h> | |
40 # include <linux/xattr.h> | |
41 # ifndef SMACK_LABEL_LEN | |
42 # define SMACK_LABEL_LEN 1024 | |
43 # endif | |
44 #endif | |
45 | |
14718
cf33c47d66aa
patch 8.1.0371: argument types for select() may be wrong
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
46 #ifdef __BEOS__ |
1076 | 47 # undef select |
14718
cf33c47d66aa
patch 8.1.0371: argument types for select() may be wrong
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
48 # define select beos_select |
7 | 49 #endif |
50 | |
1102 | 51 #ifdef __CYGWIN__ |
52 # ifndef WIN32 | |
1657 | 53 # include <cygwin/version.h> |
54 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or | |
55 * for cygwin_conv_path() */ | |
4168 | 56 # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
57 # define WIN32_LEAN_AND_MEAN | |
58 # include <windows.h> | |
59 # include "winclip.pro" | |
60 # endif | |
1102 | 61 # endif |
62 #endif | |
63 | |
7 | 64 #ifdef FEAT_MOUSE_GPM |
65 # include <gpm.h> | |
66 /* <linux/keyboard.h> contains defines conflicting with "keymap.h", | |
67 * I just copied relevant defines here. A cleaner solution would be to put gpm | |
68 * code into separate file and include there linux/keyboard.h | |
69 */ | |
70 /* #include <linux/keyboard.h> */ | |
71 # define KG_SHIFT 0 | |
72 # define KG_CTRL 2 | |
73 # define KG_ALT 3 | |
74 # define KG_ALTGR 1 | |
75 # define KG_SHIFTL 4 | |
76 # define KG_SHIFTR 5 | |
77 # define KG_CTRLL 6 | |
78 # define KG_CTRLR 7 | |
79 # define KG_CAPSSHIFT 8 | |
80 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
81 static void gpm_close(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
82 static int gpm_open(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
83 static int mch_gpm_process(void); |
7 | 84 #endif |
85 | |
1620 | 86 #ifdef FEAT_SYSMOUSE |
87 # include <sys/consio.h> | |
88 # include <sys/fbio.h> | |
89 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
90 static int sysmouse_open(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
91 static void sysmouse_close(void); |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
92 static RETSIGTYPE sig_sysmouse SIGPROTOARG; |
1620 | 93 #endif |
94 | |
7 | 95 /* |
96 * end of autoconf section. To be extended... | |
97 */ | |
98 | |
99 /* Are the following #ifdefs still required? And why? Is that for X11? */ | |
100 | |
101 #if defined(ESIX) || defined(M_UNIX) && !defined(SCO) | |
102 # ifdef SIGWINCH | |
103 # undef SIGWINCH | |
104 # endif | |
105 # ifdef TIOCGWINSZ | |
106 # undef TIOCGWINSZ | |
107 # endif | |
108 #endif | |
109 | |
110 #if defined(SIGWINDOW) && !defined(SIGWINCH) /* hpux 9.01 has it */ | |
111 # define SIGWINCH SIGWINDOW | |
112 #endif | |
113 | |
114 #ifdef FEAT_X11 | |
115 # include <X11/Xlib.h> | |
116 # include <X11/Xutil.h> | |
117 # include <X11/Xatom.h> | |
118 # ifdef FEAT_XCLIPBOARD | |
119 # include <X11/Intrinsic.h> | |
120 # include <X11/Shell.h> | |
121 # include <X11/StringDefs.h> | |
122 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
|
123 static void clip_update(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
124 static void xterm_update(void); |
7 | 125 # endif |
126 | |
127 # if defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE) | |
128 Window x11_window = 0; | |
129 # endif | |
130 Display *x11_display = NULL; | |
131 #endif | |
132 | |
133 #ifdef FEAT_TITLE | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
134 static int get_x11_title(int); |
7 | 135 |
136 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
|
137 static volatile sig_atomic_t oldtitle_outdated = FALSE; |
7 | 138 static int did_set_title = FALSE; |
139 static char_u *oldicon = NULL; | |
140 static int did_set_icon = FALSE; | |
141 #endif | |
142 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
143 static void may_core_dump(void); |
7 | 144 |
3048 | 145 #ifdef HAVE_UNION_WAIT |
146 typedef union wait waitstatus; | |
147 #else | |
148 typedef int waitstatus; | |
149 #endif | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
150 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
|
151 static int WaitForCharOrMouse(long msec, int *interrupted, int ignore_input); |
5541 | 152 #if defined(__BEOS__) || defined(VMS) |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
153 int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 154 #else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
155 static int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 156 #endif |
157 | |
158 #ifdef FEAT_XCLIPBOARD | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
159 static int do_xterm_trace(void); |
331 | 160 # define XT_TRACE_DELAY 50 /* delay for xterm tracing */ |
7 | 161 #endif |
162 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
163 static void handle_resize(void); |
7 | 164 |
165 #if defined(SIGWINCH) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
166 static RETSIGTYPE sig_winch SIGPROTOARG; |
7 | 167 #endif |
168 #if defined(SIGINT) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
169 static RETSIGTYPE catch_sigint SIGPROTOARG; |
7 | 170 #endif |
171 #if defined(SIGPWR) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
172 static RETSIGTYPE catch_sigpwr SIGPROTOARG; |
7 | 173 #endif |
174 #if defined(SIGALRM) && defined(FEAT_X11) \ | |
175 && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) | |
176 # define SET_SIG_ALARM | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
177 static RETSIGTYPE sig_alarm SIGPROTOARG; |
1832 | 178 /* 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
|
179 static volatile sig_atomic_t sig_alarm_called; |
7 | 180 #endif |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
181 static RETSIGTYPE deathtrap SIGPROTOARG; |
7 | 182 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
183 static void catch_int_signal(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
184 static void set_signals(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
185 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
|
186 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
187 # 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
|
188 # 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
|
189 # 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
|
190 #else |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
191 # define SIGSET_DECL(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
192 # 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
|
193 # 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
|
194 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
195 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
|
196 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
|
197 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
198 static int save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file); |
7 | 199 |
200 #ifndef SIG_ERR | |
1879 | 201 # define SIG_ERR ((RETSIGTYPE (*)())-1) |
7 | 202 #endif |
203 | |
1832 | 204 /* 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
|
205 static volatile sig_atomic_t do_resize = FALSE; |
7 | 206 static char_u *extra_shell_arg = NULL; |
207 static int show_shell_mess = TRUE; | |
1832 | 208 /* 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
|
209 static volatile sig_atomic_t deadly_signal = 0; /* The signal we caught */ |
1832 | 210 /* 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
|
211 static volatile sig_atomic_t in_mch_delay = FALSE; /* sleeping in mch_delay() */ |
7 | 212 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
213 #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
|
214 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
|
215 #endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
216 |
7 | 217 static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ |
218 | |
219 #ifdef USE_XSMP | |
220 typedef struct | |
221 { | |
222 SmcConn smcconn; /* The SM connection ID */ | |
223 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
|
224 char *clientid; /* The client ID for the current smc session */ |
7 | 225 Bool save_yourself; /* If we're in the middle of a save_yourself */ |
226 Bool shutdown; /* If we're in shutdown mode */ | |
227 } xsmp_config_T; | |
228 | |
229 static xsmp_config_T xsmp; | |
230 #endif | |
231 | |
232 #ifdef SYS_SIGLIST_DECLARED | |
233 /* | |
234 * I have seen | |
235 * extern char *_sys_siglist[NSIG]; | |
236 * on Irix, Linux, NetBSD and Solaris. It contains a nice list of strings | |
237 * that describe the signals. That is nearly what we want here. But | |
238 * autoconf does only check for sys_siglist (without the underscore), I | |
239 * 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
|
240 * This is why AC_DECL_SYS_SIGLIST is commented out in configure.ac. |
7 | 241 */ |
242 #endif | |
243 | |
244 static struct signalinfo | |
245 { | |
246 int sig; /* Signal number, eg. SIGSEGV etc */ | |
247 char *name; /* Signal name (not char_u!). */ | |
248 char deadly; /* Catch as a deadly signal? */ | |
249 } signal_info[] = | |
250 { | |
251 #ifdef SIGHUP | |
252 {SIGHUP, "HUP", TRUE}, | |
253 #endif | |
254 #ifdef SIGQUIT | |
255 {SIGQUIT, "QUIT", TRUE}, | |
256 #endif | |
257 #ifdef SIGILL | |
258 {SIGILL, "ILL", TRUE}, | |
259 #endif | |
260 #ifdef SIGTRAP | |
261 {SIGTRAP, "TRAP", TRUE}, | |
262 #endif | |
263 #ifdef SIGABRT | |
264 {SIGABRT, "ABRT", TRUE}, | |
265 #endif | |
266 #ifdef SIGEMT | |
267 {SIGEMT, "EMT", TRUE}, | |
268 #endif | |
269 #ifdef SIGFPE | |
270 {SIGFPE, "FPE", TRUE}, | |
271 #endif | |
272 #ifdef SIGBUS | |
273 {SIGBUS, "BUS", TRUE}, | |
274 #endif | |
4074 | 275 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) |
276 /* MzScheme uses SEGV in its garbage collector */ | |
7 | 277 {SIGSEGV, "SEGV", TRUE}, |
278 #endif | |
279 #ifdef SIGSYS | |
280 {SIGSYS, "SYS", TRUE}, | |
281 #endif | |
282 #ifdef SIGALRM | |
283 {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ | |
284 #endif | |
285 #ifdef SIGTERM | |
286 {SIGTERM, "TERM", TRUE}, | |
287 #endif | |
2701 | 288 #if defined(SIGVTALRM) && !defined(FEAT_RUBY) |
7 | 289 {SIGVTALRM, "VTALRM", TRUE}, |
290 #endif | |
1560 | 291 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) |
292 /* MzScheme uses SIGPROF for its own needs; On Linux with profiling | |
293 * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ | |
7 | 294 {SIGPROF, "PROF", TRUE}, |
295 #endif | |
296 #ifdef SIGXCPU | |
297 {SIGXCPU, "XCPU", TRUE}, | |
298 #endif | |
299 #ifdef SIGXFSZ | |
300 {SIGXFSZ, "XFSZ", TRUE}, | |
301 #endif | |
302 #ifdef SIGUSR1 | |
303 {SIGUSR1, "USR1", TRUE}, | |
304 #endif | |
1620 | 305 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) |
306 /* Used for sysmouse handling */ | |
7 | 307 {SIGUSR2, "USR2", TRUE}, |
308 #endif | |
309 #ifdef SIGINT | |
310 {SIGINT, "INT", FALSE}, | |
311 #endif | |
312 #ifdef SIGWINCH | |
313 {SIGWINCH, "WINCH", FALSE}, | |
314 #endif | |
315 #ifdef SIGTSTP | |
316 {SIGTSTP, "TSTP", FALSE}, | |
317 #endif | |
318 #ifdef SIGPIPE | |
319 {SIGPIPE, "PIPE", FALSE}, | |
320 #endif | |
321 {-1, "Unknown!", FALSE} | |
322 }; | |
323 | |
1935 | 324 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
325 mch_chdir(char *path) |
1935 | 326 { |
327 if (p_verbose >= 5) | |
328 { | |
329 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
330 smsg("chdir(%s)", path); |
1935 | 331 verbose_leave(); |
332 } | |
333 # ifdef VMS | |
334 return chdir(vms_fixfilename(path)); | |
335 # else | |
336 return chdir(path); | |
337 # endif | |
338 } | |
339 | |
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
|
340 /* 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
|
341 #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
|
342 # 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
|
343 #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
|
344 |
1757 | 345 /* |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
346 * Write s[len] to the screen (stdout). |
1757 | 347 */ |
7 | 348 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
349 mch_write(char_u *s, int len) |
7 | 350 { |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
351 vim_ignored = (int)write(1, (char *)s, len); |
7 | 352 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
|
353 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); |
7 | 354 } |
355 | |
356 /* | |
1450 | 357 * mch_inchar(): low level input function. |
7 | 358 * Get a characters from the keyboard. |
359 * Return the number of characters that are available. | |
360 * If wtime == 0 do not wait for characters. | |
361 * If wtime == n wait a short time for characters. | |
362 * If wtime == -1 wait forever for characters. | |
363 */ | |
364 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
365 mch_inchar( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
366 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
367 int maxlen, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
368 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
|
369 int tb_change_cnt) |
7 | 370 { |
371 int len; | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
372 int interrupted = FALSE; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
373 int did_start_blocking = FALSE; |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
374 long wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
375 long elapsed_time = 0; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
376 #ifdef ELAPSED_FUNC |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
377 elapsed_T start_tv; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
378 |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
379 ELAPSED_INIT(start_tv); |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
380 #endif |
7 | 381 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
382 /* 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
|
383 for (;;) |
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
384 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
385 /* 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
|
386 * columns=99" command was used. */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
387 while (do_resize) |
7 | 388 handle_resize(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
389 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
390 #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
|
391 // 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
|
392 if (wtime != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
393 { |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
394 parse_queued_messages(); |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
395 // 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
|
396 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
|
397 return 0; |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14631
diff
changeset
|
398 } |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
399 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
400 if (wtime < 0 && did_start_blocking) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
401 /* 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
|
402 wait_time = -1; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
403 else |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
404 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
405 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
406 wait_time = wtime; |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
407 else |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
408 /* going to block after p_ut */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
409 wait_time = p_ut; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
410 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
411 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
|
412 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
413 wait_time -= elapsed_time; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
414 if (wait_time < 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
415 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
416 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
417 /* no character available within "wtime" */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
418 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
419 |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
420 else |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
421 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
422 /* no character available within 'updatetime' */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
423 did_start_blocking = TRUE; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
424 if (trigger_cursorhold() && maxlen >= 3 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
425 && !typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
426 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
427 buf[0] = K_SPECIAL; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
428 buf[1] = KS_EXTRA; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
429 buf[2] = (int)KE_CURSORHOLD; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
430 return 3; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
431 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
432 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
433 * 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
|
434 * 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
|
435 * Also done when interrupted by SIGWINCH. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
436 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
437 before_blocking(); |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
438 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
439 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
440 } |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
441 } |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
442 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
443 #ifdef FEAT_JOB_CHANNEL |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
444 /* 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
|
445 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
|
446 wait_time = 100L; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
447 /* 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
|
448 * should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
449 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
|
450 wait_time = 10L; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
451 #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
|
452 #ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
453 if (p_beval && wait_time > 100L) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
454 /* 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
|
455 * 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
|
456 wait_time = 100L; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
457 #endif |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
458 |
7 | 459 /* |
2436 | 460 * We want to be interrupted by the winch signal |
461 * or by an event on the monitored file descriptors. | |
7 | 462 */ |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
463 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
|
464 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
465 /* 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
|
466 if (typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
467 return 0; |
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 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
470 * 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
|
471 * 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
|
472 * trying until none is available |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
473 * 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
|
474 * do it. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
475 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
476 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
|
477 if (len > 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
478 return len; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
479 continue; |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
480 } |
7 | 481 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
482 /* no character available */ |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
483 #ifndef ELAPSED_FUNC |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
484 /* estimate the elapsed time */ |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
485 elapsed_time += wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
486 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
487 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
488 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
|
489 #ifdef FEAT_CLIENTSERVER |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
490 || server_waiting() |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
491 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
492 #ifdef MESSAGE_QUEUE |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
493 || interrupted |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
494 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
495 || 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
|
496 || (wtime < 0 && !did_start_blocking)) |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
497 continue; |
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 /* no character available or interrupted */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
500 break; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
501 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
502 return 0; |
7 | 503 } |
504 | |
505 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
506 handle_resize(void) |
7 | 507 { |
508 do_resize = FALSE; | |
509 shell_resized(); | |
510 } | |
511 | |
512 /* | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
513 * Return non-zero if a character is available. |
7 | 514 */ |
515 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
516 mch_char_avail(void) |
7 | 517 { |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
518 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
|
519 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
520 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
521 #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
|
522 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
523 * 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
|
524 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
525 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
526 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
527 { |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
528 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
|
529 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
530 #endif |
7 | 531 |
532 #if defined(HAVE_TOTAL_MEM) || defined(PROTO) | |
533 # ifdef HAVE_SYS_RESOURCE_H | |
1879 | 534 # include <sys/resource.h> |
7 | 535 # endif |
536 # if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTL) | |
537 # include <sys/sysctl.h> | |
538 # endif | |
539 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) | |
540 # include <sys/sysinfo.h> | |
541 # endif | |
13396
5252ca53093a
patch 8.0.1572: Mac: getting memory size doesn't work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13388
diff
changeset
|
542 # 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
|
543 # 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
|
544 # 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
|
545 # endif |
7 | 546 |
547 /* | |
1110 | 548 * Return total amount of memory available in Kbyte. |
549 * Doesn't change when memory has been allocated. | |
7 | 550 */ |
551 long_u | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
552 mch_total_mem(int special UNUSED) |
7 | 553 { |
554 long_u mem = 0; | |
1110 | 555 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ |
7 | 556 |
13396
5252ca53093a
patch 8.0.1572: Mac: getting memory size doesn't work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13388
diff
changeset
|
557 # 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
|
558 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
559 /* 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
|
560 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
|
561 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
|
562 # 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
|
563 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
|
564 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
|
565 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
566 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
|
567 (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
|
568 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
569 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
|
570 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
|
571 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
572 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
|
573 (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
|
574 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
575 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
|
576 /* 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
|
577 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
|
578 + 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
|
579 # 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
|
580 + 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
|
581 # endif |
13511
8db9449b5c79
patch 8.0.1629: Mac: getpagesize() is deprecated
Christian Brabandt <cb@256bit.org>
parents:
13478
diff
changeset
|
582 ) * 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
|
583 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
|
584 } |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
585 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
586 |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
587 # 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
|
588 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
|
589 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
590 /* 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
|
591 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
|
592 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
|
593 # 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
|
594 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
|
595 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
596 /* 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
|
597 union { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
598 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
|
599 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
|
600 } physmem; |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
601 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
602 |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
603 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
|
604 # 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
|
605 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
|
606 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
607 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
|
608 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
609 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
|
610 { |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
611 # 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
|
612 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
|
613 # else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
614 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
|
615 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
|
616 else |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
617 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
|
618 # endif |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
619 } |
0bc67f4e2947
patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
620 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
621 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
622 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
623 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) |
7 | 624 if (mem == 0) |
625 { | |
626 struct sysinfo sinfo; | |
627 | |
628 /* Linux way of getting amount of RAM available */ | |
629 if (sysinfo(&sinfo) == 0) | |
1110 | 630 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
631 # ifdef HAVE_SYSINFO_MEM_UNIT |
1110 | 632 /* avoid overflow as much as possible */ |
633 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) | |
634 { | |
635 sinfo.mem_unit = sinfo.mem_unit >> 1; | |
636 --shiftright; | |
637 } | |
638 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
|
639 # else |
7 | 640 mem = sinfo.totalram; |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
641 # endif |
1110 | 642 } |
7 | 643 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
644 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
645 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
646 # ifdef HAVE_SYSCONF |
7 | 647 if (mem == 0) |
648 { | |
649 long pagesize, pagecount; | |
650 | |
651 /* Solaris way of getting amount of RAM available */ | |
652 pagesize = sysconf(_SC_PAGESIZE); | |
653 pagecount = sysconf(_SC_PHYS_PAGES); | |
654 if (pagesize > 0 && pagecount > 0) | |
1110 | 655 { |
656 /* avoid overflow as much as possible */ | |
657 while (shiftright > 0 && (pagesize & 1) == 0) | |
658 { | |
1204 | 659 pagesize = (long_u)pagesize >> 1; |
1110 | 660 --shiftright; |
661 } | |
7 | 662 mem = (long_u)pagesize * pagecount; |
1110 | 663 } |
7 | 664 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
665 # endif |
7 | 666 |
667 /* Return the minimum of the physical memory and the user limit, because | |
668 * 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
|
669 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) |
7 | 670 { |
671 struct rlimit rlp; | |
672 | |
673 if (getrlimit(RLIMIT_DATA, &rlp) == 0 | |
674 && 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
|
675 # ifdef RLIM_INFINITY |
7 | 676 && rlp.rlim_cur != RLIM_INFINITY |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
677 # endif |
1110 | 678 && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright) |
7 | 679 ) |
1110 | 680 { |
681 mem = (long_u)rlp.rlim_cur; | |
682 shiftright = 10; | |
683 } | |
7 | 684 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
685 # endif |
7 | 686 |
687 if (mem > 0) | |
1110 | 688 return mem >> shiftright; |
689 return (long_u)0x1fffff; | |
7 | 690 } |
691 #endif | |
692 | |
693 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
694 mch_delay(long msec, int ignoreinput) |
7 | 695 { |
696 int old_tmode; | |
14 | 697 #ifdef FEAT_MZSCHEME |
698 long total = msec; /* remember original value */ | |
699 #endif | |
7 | 700 |
701 if (ignoreinput) | |
702 { | |
703 /* Go to cooked mode without echo, to allow SIGINT interrupting us | |
1530 | 704 * here. But we don't want QUIT to kill us (CTRL-\ used in a |
705 * shell may produce SIGQUIT). */ | |
706 in_mch_delay = TRUE; | |
7 | 707 old_tmode = curr_tmode; |
708 if (curr_tmode == TMODE_RAW) | |
709 settmode(TMODE_SLEEP); | |
710 | |
711 /* | |
712 * Everybody sleeps in a different way... | |
713 * Prefer nanosleep(), some versions of usleep() can only sleep up to | |
714 * one second. | |
715 */ | |
14 | 716 #ifdef FEAT_MZSCHEME |
717 do | |
718 { | |
719 /* if total is large enough, wait by portions in p_mzq */ | |
720 if (total > p_mzq) | |
721 msec = p_mzq; | |
722 else | |
723 msec = total; | |
724 total -= msec; | |
725 #endif | |
7 | 726 #ifdef HAVE_NANOSLEEP |
727 { | |
728 struct timespec ts; | |
729 | |
730 ts.tv_sec = msec / 1000; | |
731 ts.tv_nsec = (msec % 1000) * 1000000; | |
732 (void)nanosleep(&ts, NULL); | |
733 } | |
734 #else | |
735 # ifdef HAVE_USLEEP | |
736 while (msec >= 1000) | |
737 { | |
738 usleep((unsigned int)(999 * 1000)); | |
739 msec -= 999; | |
740 } | |
741 usleep((unsigned int)(msec * 1000)); | |
742 # else | |
743 # ifndef HAVE_SELECT | |
744 poll(NULL, 0, (int)msec); | |
745 # else | |
746 { | |
747 struct timeval tv; | |
748 | |
749 tv.tv_sec = msec / 1000; | |
750 tv.tv_usec = (msec % 1000) * 1000; | |
751 /* | |
752 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get | |
753 * a patch from Sun to fix this. Reported by Gunnar Pedersen. | |
754 */ | |
755 select(0, NULL, NULL, NULL, &tv); | |
756 } | |
757 # endif /* HAVE_SELECT */ | |
758 # endif /* HAVE_NANOSLEEP */ | |
759 #endif /* HAVE_USLEEP */ | |
14 | 760 #ifdef FEAT_MZSCHEME |
761 } | |
762 while (total > 0); | |
763 #endif | |
7 | 764 |
765 settmode(old_tmode); | |
1530 | 766 in_mch_delay = FALSE; |
7 | 767 } |
768 else | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
769 WaitForChar(msec, NULL, FALSE); |
7 | 770 } |
771 | |
180 | 772 #if defined(HAVE_STACK_LIMIT) \ |
7 | 773 || (!defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGSTACK)) |
774 # define HAVE_CHECK_STACK_GROWTH | |
775 /* | |
776 * Support for checking for an almost-out-of-stack-space situation. | |
777 */ | |
778 | |
779 /* | |
780 * Return a pointer to an item on the stack. Used to find out if the stack | |
781 * grows up or down. | |
782 */ | |
783 static int stack_grows_downwards; | |
784 | |
785 /* | |
786 * Find out if the stack grows upwards or downwards. | |
787 * "p" points to a variable on the stack of the caller. | |
788 */ | |
789 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
790 check_stack_growth(char *p) |
7 | 791 { |
792 int i; | |
793 | |
794 stack_grows_downwards = (p > (char *)&i); | |
795 } | |
796 #endif | |
797 | |
180 | 798 #if defined(HAVE_STACK_LIMIT) || defined(PROTO) |
7 | 799 static char *stack_limit = NULL; |
800 | |
801 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
802 # include <pthread.h> | |
803 # include <pthread_np.h> | |
804 #endif | |
805 | |
806 /* | |
807 * Find out until how var the stack can grow without getting into trouble. | |
808 * Called when starting up and when switching to the signal stack in | |
809 * deathtrap(). | |
810 */ | |
811 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
812 get_stack_limit(void) |
7 | 813 { |
814 struct rlimit rlp; | |
815 int i; | |
816 long lim; | |
817 | |
818 /* Set the stack limit to 15/16 of the allowable size. Skip this when the | |
819 * limit doesn't fit in a long (rlim_cur might be "long long"). */ | |
820 if (getrlimit(RLIMIT_STACK, &rlp) == 0 | |
821 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
822 # ifdef RLIM_INFINITY | |
823 && rlp.rlim_cur != RLIM_INFINITY | |
824 # endif | |
825 ) | |
826 { | |
827 lim = (long)rlp.rlim_cur; | |
828 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
829 { | |
830 pthread_attr_t attr; | |
831 size_t size; | |
832 | |
833 /* On FreeBSD the initial thread always has a fixed stack size, no | |
834 * matter what the limits are set to. Normally it's 1 Mbyte. */ | |
835 pthread_attr_init(&attr); | |
836 if (pthread_attr_get_np(pthread_self(), &attr) == 0) | |
837 { | |
838 pthread_attr_getstacksize(&attr, &size); | |
839 if (lim > (long)size) | |
840 lim = (long)size; | |
841 } | |
842 pthread_attr_destroy(&attr); | |
843 } | |
844 #endif | |
845 if (stack_grows_downwards) | |
846 { | |
847 stack_limit = (char *)((long)&i - (lim / 16L * 15L)); | |
848 if (stack_limit >= (char *)&i) | |
849 /* overflow, set to 1/16 of current stack position */ | |
850 stack_limit = (char *)((long)&i / 16L); | |
851 } | |
852 else | |
853 { | |
854 stack_limit = (char *)((long)&i + (lim / 16L * 15L)); | |
855 if (stack_limit <= (char *)&i) | |
856 stack_limit = NULL; /* overflow */ | |
857 } | |
858 } | |
859 } | |
860 | |
861 /* | |
862 * Return FAIL when running out of stack space. | |
863 * "p" must point to any variable local to the caller that's on the stack. | |
864 */ | |
865 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
866 mch_stackcheck(char *p) |
7 | 867 { |
868 if (stack_limit != NULL) | |
869 { | |
870 if (stack_grows_downwards) | |
871 { | |
872 if (p < stack_limit) | |
873 return FAIL; | |
874 } | |
875 else if (p > stack_limit) | |
876 return FAIL; | |
877 } | |
878 return OK; | |
879 } | |
880 #endif | |
881 | |
882 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
883 /* | |
884 * Support for using the signal stack. | |
885 * This helps when we run out of stack space, which causes a SIGSEGV. The | |
886 * signal handler then must run on another stack, since the normal stack is | |
887 * completely full. | |
888 */ | |
889 | |
890 #ifndef SIGSTKSZ | |
891 # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ | |
892 #endif | |
893 | |
894 # ifdef HAVE_SIGALTSTACK | |
895 static stack_t sigstk; /* for sigaltstack() */ | |
896 # else | |
897 static struct sigstack sigstk; /* for sigstack() */ | |
898 # endif | |
899 | |
900 static char *signal_stack; | |
901 | |
902 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
903 init_signal_stack(void) |
7 | 904 { |
905 if (signal_stack != NULL) | |
906 { | |
907 # ifdef HAVE_SIGALTSTACK | |
908 # ifdef HAVE_SS_BASE | |
909 sigstk.ss_base = signal_stack; | |
910 # else | |
911 sigstk.ss_sp = signal_stack; | |
912 # endif | |
913 sigstk.ss_size = SIGSTKSZ; | |
914 sigstk.ss_flags = 0; | |
915 (void)sigaltstack(&sigstk, NULL); | |
916 # else | |
917 sigstk.ss_sp = signal_stack; | |
918 if (stack_grows_downwards) | |
919 sigstk.ss_sp += SIGSTKSZ - 1; | |
920 sigstk.ss_onstack = 0; | |
921 (void)sigstack(&sigstk, NULL); | |
922 # endif | |
923 } | |
924 } | |
925 #endif | |
926 | |
927 /* | |
1832 | 928 * We need correct prototypes for a signal function, otherwise mean compilers |
7 | 929 * will barf when the second argument to signal() is ``wrong''. |
930 * Let me try it with a few tricky defines from my own osdef.h (jw). | |
931 */ | |
932 #if defined(SIGWINCH) | |
933 static RETSIGTYPE | |
934 sig_winch SIGDEFARG(sigarg) | |
935 { | |
936 /* this is not required on all systems, but it doesn't hurt anybody */ | |
937 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
938 do_resize = TRUE; | |
939 SIGRETURN; | |
940 } | |
941 #endif | |
942 | |
943 #if defined(SIGINT) | |
944 static RETSIGTYPE | |
945 catch_sigint SIGDEFARG(sigarg) | |
946 { | |
947 /* this is not required on all systems, but it doesn't hurt anybody */ | |
948 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
949 got_int = TRUE; | |
950 SIGRETURN; | |
951 } | |
952 #endif | |
953 | |
954 #if defined(SIGPWR) | |
955 static RETSIGTYPE | |
956 catch_sigpwr SIGDEFARG(sigarg) | |
957 { | |
37 | 958 /* this is not required on all systems, but it doesn't hurt anybody */ |
959 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
7 | 960 /* |
961 * I'm not sure we get the SIGPWR signal when the system is really going | |
962 * down or when the batteries are almost empty. Just preserve the swap | |
963 * files and don't exit, that can't do any harm. | |
964 */ | |
965 ml_sync_all(FALSE, FALSE); | |
966 SIGRETURN; | |
967 } | |
968 #endif | |
969 | |
970 #ifdef SET_SIG_ALARM | |
971 /* | |
972 * signal function for alarm(). | |
973 */ | |
974 static RETSIGTYPE | |
975 sig_alarm SIGDEFARG(sigarg) | |
976 { | |
977 /* doesn't do anything, just to break a system call */ | |
978 sig_alarm_called = TRUE; | |
979 SIGRETURN; | |
980 } | |
981 #endif | |
982 | |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
983 #if (defined(HAVE_SETJMP_H) \ |
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
984 && ((defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) \ |
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
985 || defined(FEAT_LIBCALL))) \ |
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
986 || defined(PROTO) |
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
987 |
15282
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
988 // argument to SETJMP() |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
989 static JMP_BUF lc_jump_env; |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
990 |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
991 # ifdef SIGHASARG |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
992 // Caught signal number, 0 when no was signal caught; used for mch_libcall(). |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
993 // Volatile because it is used in signal handlers. |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
994 static volatile sig_atomic_t lc_signal; |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
995 # endif |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
996 |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
997 // TRUE when lc_jump_env is valid. |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
998 // Volatile because it is used in signal handler deathtrap(). |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
999 static volatile sig_atomic_t lc_active INIT(= FALSE); |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
1000 |
7 | 1001 /* |
1002 * A simplistic version of setjmp() that only allows one level of using. | |
15282
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
1003 * Used to protect areas where we could crash. |
7 | 1004 * Don't call twice before calling mch_endjmp()!. |
15282
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
1005 * |
7 | 1006 * Usage: |
1007 * mch_startjmp(); | |
1008 * if (SETJMP(lc_jump_env) != 0) | |
1009 * { | |
1010 * mch_didjmp(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
1011 * emsg("crash!"); |
7 | 1012 * } |
1013 * else | |
1014 * { | |
1015 * do_the_work; | |
1016 * mch_endjmp(); | |
1017 * } | |
1018 * Note: Can't move SETJMP() here, because a function calling setjmp() must | |
1019 * not return before the saved environment is used. | |
1020 * Returns OK for normal return, FAIL when the protected code caused a | |
1021 * problem and LONGJMP() was used. | |
1022 */ | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1023 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1024 mch_startjmp(void) |
7 | 1025 { |
1026 #ifdef SIGHASARG | |
1027 lc_signal = 0; | |
1028 #endif | |
1029 lc_active = TRUE; | |
1030 } | |
1031 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1032 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1033 mch_endjmp(void) |
7 | 1034 { |
1035 lc_active = FALSE; | |
1036 } | |
1037 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1038 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1039 mch_didjmp(void) |
7 | 1040 { |
1041 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
15282
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
1042 // On FreeBSD the signal stack has to be reset after using siglongjmp(), |
186eebc31ec0
patch 8.1.0649: setjmp() variables defined globally are used in one file
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
1043 // otherwise catching the signal only works once. |
7 | 1044 init_signal_stack(); |
1045 # endif | |
1046 } | |
1047 #endif | |
1048 | |
1049 /* | |
1050 * This function handles deadly signals. | |
5338 | 1051 * It tries to preserve any swap files and exit properly. |
7 | 1052 * (partly from Elvis). |
5338 | 1053 * NOTE: Avoid unsafe functions, such as allocating memory, they can result in |
1054 * a deadlock. | |
7 | 1055 */ |
1056 static RETSIGTYPE | |
1057 deathtrap SIGDEFARG(sigarg) | |
1058 { | |
1059 static int entered = 0; /* count the number of times we got here. | |
1060 Note: when memory has been corrupted | |
1061 this may get an arbitrary value! */ | |
1062 #ifdef SIGHASARG | |
1063 int i; | |
1064 #endif | |
1065 | |
1066 #if defined(HAVE_SETJMP_H) | |
1067 /* | |
1068 * Catch a crash in protected code. | |
1069 * Restores the environment saved in lc_jump_env, which looks like | |
1070 * SETJMP() returns 1. | |
1071 */ | |
1072 if (lc_active) | |
1073 { | |
1074 # if defined(SIGHASARG) | |
1075 lc_signal = sigarg; | |
1076 # endif | |
1077 lc_active = FALSE; /* don't jump again */ | |
1078 LONGJMP(lc_jump_env, 1); | |
1079 /* NOTREACHED */ | |
1080 } | |
1081 #endif | |
1082 | |
36 | 1083 #ifdef SIGHASARG |
1530 | 1084 # ifdef SIGQUIT |
1085 /* While in mch_delay() we go to cooked mode to allow a CTRL-C to | |
1086 * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when | |
1087 * pressing CTRL-\, but we don't want Vim to exit then. */ | |
1088 if (in_mch_delay && sigarg == SIGQUIT) | |
1089 SIGRETURN; | |
1090 # endif | |
1091 | |
37 | 1092 /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return |
1093 * here. This avoids that a non-reentrant function is interrupted, e.g., | |
1094 * free(). Calling free() again may then cause a crash. */ | |
1095 if (entered == 0 | |
1096 && (0 | |
1097 # ifdef SIGHUP | |
1098 || sigarg == SIGHUP | |
1099 # endif | |
1100 # ifdef SIGQUIT | |
1101 || sigarg == SIGQUIT | |
1102 # endif | |
1103 # ifdef SIGTERM | |
1104 || sigarg == SIGTERM | |
1105 # endif | |
1106 # ifdef SIGPWR | |
1107 || sigarg == SIGPWR | |
1108 # endif | |
1109 # ifdef SIGUSR1 | |
1110 || sigarg == SIGUSR1 | |
1111 # endif | |
1112 # ifdef SIGUSR2 | |
1113 || sigarg == SIGUSR2 | |
1114 # endif | |
1115 ) | |
413 | 1116 && !vim_handle_signal(sigarg)) |
36 | 1117 SIGRETURN; |
1118 #endif | |
1119 | |
7 | 1120 /* Remember how often we have been called. */ |
1121 ++entered; | |
1122 | |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1123 /* 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
|
1124 * available in the signal stack. */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1125 block_autocmds(); |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1126 |
7 | 1127 #ifdef FEAT_EVAL |
1128 /* Set the v:dying variable. */ | |
1129 set_vim_var_nr(VV_DYING, (long)entered); | |
1130 #endif | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13357
diff
changeset
|
1131 v_dying = entered; |
7 | 1132 |
180 | 1133 #ifdef HAVE_STACK_LIMIT |
7 | 1134 /* Since we are now using the signal stack, need to reset the stack |
1135 * limit. Otherwise using a regexp will fail. */ | |
1136 get_stack_limit(); | |
1137 #endif | |
1138 | |
758 | 1139 #if 0 |
1140 /* This is for opening gdb the moment Vim crashes. | |
1141 * You need to manually adjust the file name and Vim executable name. | |
1142 * Suggested by SungHyun Nam. */ | |
1143 { | |
1144 # define VI_GDB_FILE "/tmp/vimgdb" | |
1145 # define VIM_NAME "/usr/bin/vim" | |
1146 FILE *fp = fopen(VI_GDB_FILE, "w"); | |
1147 if (fp) | |
1148 { | |
1149 fprintf(fp, | |
1150 "file %s\n" | |
1151 "attach %d\n" | |
1152 "set height 1000\n" | |
1153 "bt full\n" | |
1154 , VIM_NAME, getpid()); | |
1155 fclose(fp); | |
1156 system("xterm -e gdb -x "VI_GDB_FILE); | |
1157 unlink(VI_GDB_FILE); | |
1158 } | |
1159 } | |
1160 #endif | |
1161 | |
7 | 1162 #ifdef SIGHASARG |
1163 /* try to find the name of this signal */ | |
1164 for (i = 0; signal_info[i].sig != -1; i++) | |
1165 if (sigarg == signal_info[i].sig) | |
1166 break; | |
1167 deadly_signal = sigarg; | |
1168 #endif | |
1169 | |
1170 full_screen = FALSE; /* don't write message to the GUI, it might be | |
1171 * part of the problem... */ | |
1172 /* | |
1173 * If something goes wrong after entering here, we may get here again. | |
1174 * When this happens, give a message and try to exit nicely (resetting the | |
1175 * terminal mode, etc.) | |
1176 * When this happens twice, just exit, don't even try to give a message, | |
1177 * stack may be corrupt or something weird. | |
1178 * When this still happens again (or memory was corrupted in such a way | |
1179 * that "entered" was clobbered) use _exit(), don't try freeing resources. | |
1180 */ | |
1181 if (entered >= 3) | |
1182 { | |
1183 reset_signals(); /* don't catch any signals anymore */ | |
1184 may_core_dump(); | |
1185 if (entered >= 4) | |
1186 _exit(8); | |
1187 exit(7); | |
1188 } | |
1189 if (entered == 2) | |
1190 { | |
5338 | 1191 /* No translation, it may call malloc(). */ |
1192 OUT_STR("Vim: Double signal, exiting\n"); | |
7 | 1193 out_flush(); |
1194 getout(1); | |
1195 } | |
1196 | |
5338 | 1197 /* No translation, it may call malloc(). */ |
7 | 1198 #ifdef SIGHASARG |
5338 | 1199 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", |
7 | 1200 signal_info[i].name); |
1201 #else | |
5338 | 1202 sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); |
1203 #endif | |
1204 | |
1205 /* Preserve files and exit. This sets the really_exiting flag to prevent | |
1206 * calling free(). */ | |
1207 preserve_exit(); | |
7 | 1208 |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1209 /* NOTREACHED */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1210 |
33 | 1211 #ifdef NBDEBUG |
1212 reset_signals(); | |
1213 may_core_dump(); | |
1214 abort(); | |
1215 #endif | |
1216 | |
7 | 1217 SIGRETURN; |
1218 } | |
1219 | |
1220 /* | |
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
|
1221 * 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
|
1222 * 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
|
1223 */ |
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
|
1224 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
|
1225 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
|
1226 { |
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
|
1227 # 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
|
1228 // 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
|
1229 // 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
|
1230 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
|
1231 # 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
|
1232 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
|
1233 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
|
1234 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
|
1235 } |
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 |
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 #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
|
1238 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
|
1239 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
|
1240 |
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 * 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
|
1243 * 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
|
1244 * has been done or not. |
1832 | 1245 * |
1246 * On Linux, signal is not always handled immediately either. | |
1247 * 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
|
1248 * Probably because the signal is handled in another thread. |
1832 | 1249 * |
2701 | 1250 * volatile because it is used in signal handler sigcont_handler(). |
7 | 1251 */ |
14597
27e814e21594
patch 8.1.0312: wrong type for flags used in signal handlers
Christian Brabandt <cb@256bit.org>
parents:
14581
diff
changeset
|
1252 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
|
1253 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
7 | 1254 |
1255 /* | |
1256 * signal handler for SIGCONT | |
1257 */ | |
1258 static RETSIGTYPE | |
1259 sigcont_handler SIGDEFARG(sigarg) | |
1260 { | |
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
|
1261 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
|
1262 { |
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 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
|
1264 } |
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
|
1265 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
|
1266 { |
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
|
1267 // 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
|
1268 // 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
|
1269 // 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
|
1270 // 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
|
1271 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
|
1272 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
|
1273 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
|
1274 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
|
1275 } |
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 |
7 | 1277 SIGRETURN; |
1278 } | |
1279 #endif | |
1280 | |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14828
diff
changeset
|
1281 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4230 | 1282 # ifdef USE_SYSTEM |
4209 | 1283 static void *clip_star_save = NULL; |
1284 static void *clip_plus_save = NULL; | |
4230 | 1285 # endif |
2586 | 1286 |
1287 /* | |
1288 * Called when Vim is going to sleep or execute a shell command. | |
1289 * We can't respond to requests for the X selections. Lose them, otherwise | |
1290 * other applications will hang. But first copy the text to cut buffer 0. | |
1291 */ | |
1292 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1293 loose_clipboard(void) |
2586 | 1294 { |
1295 if (clip_star.owned || clip_plus.owned) | |
1296 { | |
1297 x11_export_final_selection(); | |
1298 if (clip_star.owned) | |
1299 clip_lose_selection(&clip_star); | |
1300 if (clip_plus.owned) | |
1301 clip_lose_selection(&clip_plus); | |
1302 if (x11_display != NULL) | |
1303 XFlush(x11_display); | |
1304 } | |
1305 } | |
4209 | 1306 |
4230 | 1307 # ifdef USE_SYSTEM |
4209 | 1308 /* |
1309 * Save clipboard text to restore later. | |
1310 */ | |
1311 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1312 save_clipboard(void) |
4209 | 1313 { |
1314 if (clip_star.owned) | |
1315 clip_star_save = get_register('*', TRUE); | |
1316 if (clip_plus.owned) | |
1317 clip_plus_save = get_register('+', TRUE); | |
1318 } | |
1319 | |
1320 /* | |
1321 * Restore clipboard text if no one own the X selection. | |
1322 */ | |
1323 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1324 restore_clipboard(void) |
4209 | 1325 { |
1326 if (clip_star_save != NULL) | |
1327 { | |
1328 if (!clip_gen_owner_exists(&clip_star)) | |
1329 put_register('*', clip_star_save); | |
1330 else | |
1331 free_register(clip_star_save); | |
1332 clip_star_save = NULL; | |
1333 } | |
1334 if (clip_plus_save != NULL) | |
1335 { | |
1336 if (!clip_gen_owner_exists(&clip_plus)) | |
1337 put_register('+', clip_plus_save); | |
1338 else | |
1339 free_register(clip_plus_save); | |
1340 clip_plus_save = NULL; | |
1341 } | |
1342 } | |
4230 | 1343 # endif |
2586 | 1344 #endif |
1345 | |
7 | 1346 /* |
1347 * If the machine has job control, use it to suspend the program, | |
1348 * otherwise fake it by starting a new shell. | |
1349 */ | |
1350 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1351 mch_suspend(void) |
7 | 1352 { |
1353 /* BeOS does have SIGTSTP, but it doesn't work. */ | |
1354 #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
|
1355 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
|
1356 |
7 | 1357 out_flush(); /* needed to make cursor visible on some systems */ |
1358 settmode(TMODE_COOK); | |
1359 out_flush(); /* needed to disable mouse on some systems */ | |
1360 | |
1361 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2586 | 1362 loose_clipboard(); |
7 | 1363 # 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
|
1364 # if defined(SIGCONT) |
7 | 1365 sigcont_received = FALSE; |
1366 # 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
|
1367 |
7 | 1368 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
|
1369 |
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
|
1370 # if defined(SIGCONT) |
1832 | 1371 /* |
1372 * 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
|
1373 * 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
|
1374 * 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
|
1375 * 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
|
1376 * 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
|
1377 * 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
|
1378 * received after 1+2+3 ms (not expected to happen). |
1832 | 1379 */ |
1380 { | |
1932 | 1381 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
|
1382 |
1932 | 1383 for (wait_time = 0; !sigcont_received && wait_time <= 3L; wait_time++) |
1384 mch_delay(wait_time, FALSE); | |
1832 | 1385 } |
7 | 1386 # 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
|
1387 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
|
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 after_sigcont(); |
7 | 1390 #else |
1391 suspend_shell(); | |
1392 #endif | |
1393 } | |
1394 | |
1395 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1396 mch_init(void) |
7 | 1397 { |
1398 Columns = 80; | |
1399 Rows = 24; | |
1400 | |
1401 out_flush(); | |
1402 set_signals(); | |
167 | 1403 |
765 | 1404 #ifdef MACOS_CONVERT |
167 | 1405 mac_conv_init(); |
1406 #endif | |
4168 | 1407 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
1408 win_clip_init(); | |
1409 #endif | |
7 | 1410 } |
1411 | |
1412 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1413 set_signals(void) |
7 | 1414 { |
1415 #if defined(SIGWINCH) | |
1416 /* | |
1417 * WINDOW CHANGE signal is handled with sig_winch(). | |
1418 */ | |
1419 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
1420 #endif | |
1421 | |
1422 /* | |
1423 * We want the STOP signal to work, to make mch_suspend() work. | |
1424 * For "rvim" the STOP signal is ignored. | |
1425 */ | |
1426 #ifdef SIGTSTP | |
1427 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); | |
1428 #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
|
1429 #if defined(SIGCONT) |
7 | 1430 signal(SIGCONT, sigcont_handler); |
1431 #endif | |
1432 | |
1433 /* | |
1434 * We want to ignore breaking of PIPEs. | |
1435 */ | |
1436 #ifdef SIGPIPE | |
1437 signal(SIGPIPE, SIG_IGN); | |
1438 #endif | |
1439 | |
1440 #ifdef SIGINT | |
167 | 1441 catch_int_signal(); |
7 | 1442 #endif |
1443 | |
1444 /* | |
1445 * Ignore alarm signals (Perl's alarm() generates it). | |
1446 */ | |
1447 #ifdef SIGALRM | |
1448 signal(SIGALRM, SIG_IGN); | |
1449 #endif | |
1450 | |
1451 /* | |
1452 * Catch SIGPWR (power failure?) to preserve the swap files, so that no | |
1453 * work will be lost. | |
1454 */ | |
1455 #ifdef SIGPWR | |
1456 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
1457 #endif | |
1458 | |
1459 /* | |
1460 * Arrange for other signals to gracefully shutdown Vim. | |
1461 */ | |
1462 catch_signals(deathtrap, SIG_ERR); | |
1463 | |
1464 #if defined(FEAT_GUI) && defined(SIGHUP) | |
1465 /* | |
1466 * When the GUI is running, ignore the hangup signal. | |
1467 */ | |
1468 if (gui.in_use) | |
1469 signal(SIGHUP, SIG_IGN); | |
1470 #endif | |
1471 } | |
1472 | |
167 | 1473 #if defined(SIGINT) || defined(PROTO) |
1474 /* | |
1475 * Catch CTRL-C (only works while in Cooked mode). | |
1476 */ | |
1477 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1478 catch_int_signal(void) |
167 | 1479 { |
1480 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
1481 } | |
1482 #endif | |
1483 | |
7 | 1484 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1485 reset_signals(void) |
7 | 1486 { |
1487 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
|
1488 #if defined(SIGCONT) |
7 | 1489 /* SIGCONT isn't in the list, because its default action is ignore */ |
1490 signal(SIGCONT, SIG_DFL); | |
1491 #endif | |
1492 } | |
1493 | |
1494 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1495 catch_signals( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1496 RETSIGTYPE (*func_deadly)(), |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1497 RETSIGTYPE (*func_other)()) |
7 | 1498 { |
1499 int i; | |
1500 | |
1501 for (i = 0; signal_info[i].sig != -1; i++) | |
1502 if (signal_info[i].deadly) | |
1503 { | |
1504 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) | |
1505 struct sigaction sa; | |
1506 | |
1507 /* Setup to use the alternate stack for the signal function. */ | |
1508 sa.sa_handler = func_deadly; | |
1509 sigemptyset(&sa.sa_mask); | |
1510 # if defined(__linux__) && defined(_REENTRANT) | |
1511 /* On Linux, with glibc compiled for kernel 2.2, there is a bug in | |
1512 * thread handling in combination with using the alternate stack: | |
1513 * pthread library functions try to use the stack pointer to | |
1514 * identify the current thread, causing a SEGV signal, which | |
1515 * recursively calls deathtrap() and hangs. */ | |
1516 sa.sa_flags = 0; | |
1517 # else | |
1518 sa.sa_flags = SA_ONSTACK; | |
1519 # endif | |
1520 sigaction(signal_info[i].sig, &sa, NULL); | |
1521 #else | |
1522 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) | |
1523 struct sigvec sv; | |
1524 | |
1525 /* Setup to use the alternate stack for the signal function. */ | |
1526 sv.sv_handler = func_deadly; | |
1527 sv.sv_mask = 0; | |
1528 sv.sv_flags = SV_ONSTACK; | |
1529 sigvec(signal_info[i].sig, &sv, NULL); | |
1530 # else | |
1531 signal(signal_info[i].sig, func_deadly); | |
1532 # endif | |
1533 #endif | |
1534 } | |
1535 else if (func_other != SIG_ERR) | |
1536 signal(signal_info[i].sig, func_other); | |
1537 } | |
1538 | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1539 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1540 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1541 block_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1542 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1543 sigset_t newset; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1544 int i; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1545 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1546 sigemptyset(&newset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1547 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1548 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
|
1549 sigaddset(&newset, signal_info[i].sig); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1550 |
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
|
1551 # if defined(SIGCONT) |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1552 /* 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
|
1553 sigaddset(&newset, SIGCONT); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1554 # endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1555 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1556 sigprocmask(SIG_BLOCK, &newset, set); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1557 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1558 |
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 unblock_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 sigprocmask(SIG_SETMASK, set, NULL); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1563 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1564 #endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1565 |
7 | 1566 /* |
37 | 1567 * Handling of SIGHUP, SIGQUIT and SIGTERM: |
1146 | 1568 * "when" == a signal: when busy, postpone and return FALSE, otherwise |
1569 * return TRUE | |
1570 * "when" == SIGNAL_BLOCK: Going to be busy, block signals | |
1571 * "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
|
1572 * signal |
36 | 1573 * Returns TRUE when Vim should exit. |
1574 */ | |
1575 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1576 vim_handle_signal(int sig) |
36 | 1577 { |
37 | 1578 static int got_signal = 0; |
1579 static int blocked = TRUE; | |
1580 | |
1581 switch (sig) | |
36 | 1582 { |
37 | 1583 case SIGNAL_BLOCK: blocked = TRUE; |
1584 break; | |
1585 | |
1586 case SIGNAL_UNBLOCK: blocked = FALSE; | |
1587 if (got_signal != 0) | |
1588 { | |
1589 kill(getpid(), got_signal); | |
1590 got_signal = 0; | |
1591 } | |
1592 break; | |
1593 | |
1594 default: if (!blocked) | |
36 | 1595 return TRUE; /* exit! */ |
37 | 1596 got_signal = sig; |
1597 #ifdef SIGPWR | |
1598 if (sig != SIGPWR) | |
1599 #endif | |
1600 got_int = TRUE; /* break any loops */ | |
36 | 1601 break; |
1602 } | |
1603 return FALSE; | |
1604 } | |
1605 | |
1606 /* | |
7 | 1607 * Check_win checks whether we have an interactive stdout. |
1608 */ | |
1609 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1610 mch_check_win(int argc UNUSED, char **argv UNUSED) |
7 | 1611 { |
1612 if (isatty(1)) | |
1613 return OK; | |
1614 return FAIL; | |
1615 } | |
1616 | |
1617 /* | |
1618 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
1619 */ | |
1620 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1621 mch_input_isatty(void) |
7 | 1622 { |
1623 if (isatty(read_cmd_fd)) | |
1624 return TRUE; | |
1625 return FALSE; | |
1626 } | |
1627 | |
1628 #ifdef FEAT_X11 | |
1629 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1630 # if defined(ELAPSED_TIMEVAL) \ |
7 | 1631 && (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE)) |
1632 | |
1633 /* | |
1634 * Give a message about the elapsed time for opening the X window. | |
1635 */ | |
1636 static void | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1637 xopen_message(long elapsed_msec) |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1638 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
1639 smsg(_("Opening the X display took %ld msec"), elapsed_msec); |
7 | 1640 } |
1641 # endif | |
1642 #endif | |
1643 | |
1644 #if defined(FEAT_X11) && (defined(FEAT_TITLE) || defined(FEAT_XCLIPBOARD)) | |
1645 /* | |
1646 * A few functions shared by X11 title and clipboard code. | |
1647 */ | |
1648 | |
1649 static int got_x_error = FALSE; | |
1650 | |
1651 /* | |
1652 * X Error handler, otherwise X just exits! (very rude) -- webb | |
1653 */ | |
1654 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1655 x_error_handler(Display *dpy, XErrorEvent *error_event) |
7 | 1656 { |
42 | 1657 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); |
7 | 1658 STRCAT(IObuff, _("\nVim: Got X error\n")); |
1659 | |
1660 /* We cannot print a message and continue, because no X calls are allowed | |
1661 * here (causes my system to hang). Silently continuing might be an | |
1662 * alternative... */ | |
1663 preserve_exit(); /* preserve files and exit */ | |
1664 | |
1665 return 0; /* NOTREACHED */ | |
1666 } | |
1667 | |
1668 /* | |
1669 * Another X Error handler, just used to check for errors. | |
1670 */ | |
1671 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1672 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
7 | 1673 { |
1674 got_x_error = TRUE; | |
1675 return 0; | |
1676 } | |
1677 | |
15296
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1678 /* |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1679 * Return TRUE when connection to the X server is desired. |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1680 */ |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1681 static int |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1682 x_connect_to_server(void) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1683 { |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1684 // No point in connecting if we are exiting or dying. |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1685 if (exiting || v_dying) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1686 return FALSE; |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1687 |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1688 #if defined(FEAT_CLIENTSERVER) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1689 if (x_force_connect) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1690 return TRUE; |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1691 #endif |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1692 if (x_no_connect) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1693 return FALSE; |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1694 |
15306
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1695 // Check for a match with "exclude:" from 'clipboard'. |
15296
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1696 if (clip_exclude_prog != NULL) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1697 { |
15306
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1698 // Just in case we get called recursively, return FALSE. This could |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1699 // happen if vpeekc() is used while executing the prog and it causes a |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1700 // related callback to be invoked. |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1701 if (regprog_in_use(clip_exclude_prog)) |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1702 return FALSE; |
7fff2d18e191
patch 8.1.0661: clipboard regexp might be used recursively
Bram Moolenaar <Bram@vim.org>
parents:
15298
diff
changeset
|
1703 |
15296
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1704 if (vim_regexec_prog(&clip_exclude_prog, FALSE, T_NAME, (colnr_T)0)) |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1705 return FALSE; |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1706 } |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1707 return TRUE; |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1708 } |
60e962106f8a
patch 8.1.0656: trying to reconnect to X server may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
15282
diff
changeset
|
1709 |
7 | 1710 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
1711 # if defined(HAVE_SETJMP_H) | |
1712 /* | |
1713 * An X IO Error handler, used to catch error while opening the display. | |
1714 */ | |
1715 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1716 x_IOerror_check(Display *dpy UNUSED) |
7 | 1717 { |
1718 /* This function should not return, it causes exit(). Longjump instead. */ | |
1719 LONGJMP(lc_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1720 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1721 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
|
1722 # endif |
7 | 1723 } |
1724 # endif | |
1725 | |
1726 /* | |
1727 * An X IO Error handler, used to catch terminal errors. | |
1728 */ | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
1729 static int xterm_dpy_retry_count = 0; |
7 | 1730 |
1731 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1732 x_IOerror_handler(Display *dpy UNUSED) |
7 | 1733 { |
1734 xterm_dpy = NULL; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
1735 xterm_dpy_retry_count = 5; // Try reconnecting five times |
7 | 1736 x11_window = 0; |
1737 x11_display = NULL; | |
1738 xterm_Shell = (Widget)0; | |
1739 | |
1740 /* This function should not return, it causes exit(). Longjump instead. */ | |
1741 LONGJMP(x_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1742 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1743 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
|
1744 # endif |
7 | 1745 } |
6383 | 1746 |
1747 /* | |
1748 * If the X11 connection was lost try to restore it. | |
1749 * Helps when the X11 server was stopped and restarted while Vim was inactive | |
6448 | 1750 * (e.g. through tmux). |
6383 | 1751 */ |
1752 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1753 may_restore_clipboard(void) |
6383 | 1754 { |
15298
4aea6c2f56a8
patch 8.1.0657: get error for using regexp recursively
Bram Moolenaar <Bram@vim.org>
parents:
15296
diff
changeset
|
1755 // No point in restoring the connecting if we are exiting or dying. |
4aea6c2f56a8
patch 8.1.0657: get error for using regexp recursively
Bram Moolenaar <Bram@vim.org>
parents:
15296
diff
changeset
|
1756 if (!exiting && !v_dying && xterm_dpy_retry_count > 0) |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
1757 { |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
1758 --xterm_dpy_retry_count; |
6458 | 1759 |
1760 # ifndef LESSTIF_VERSION | |
1761 /* This has been reported to avoid Vim getting stuck. */ | |
1762 if (app_context != (XtAppContext)NULL) | |
1763 { | |
1764 XtDestroyApplicationContext(app_context); | |
1765 app_context = (XtAppContext)NULL; | |
1766 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
1767 } | |
1768 # endif | |
1769 | |
6383 | 1770 setup_term_clip(); |
1771 get_x11_title(FALSE); | |
1772 } | |
1773 } | |
7 | 1774 #endif |
1775 | |
1776 /* | |
1777 * Test if "dpy" and x11_window are valid by getting the window title. | |
1778 * I don't actually want it yet, so there may be a simpler call to use, but | |
1779 * this will cause the error handler x_error_check() to be called if anything | |
1780 * is wrong, such as the window pointer being invalid (as can happen when the | |
1781 * user changes his DISPLAY, but not his WINDOWID) -- webb | |
1782 */ | |
1783 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1784 test_x11_window(Display *dpy) |
7 | 1785 { |
1786 int (*old_handler)(); | |
1787 XTextProperty text_prop; | |
1788 | |
1789 old_handler = XSetErrorHandler(x_error_check); | |
1790 got_x_error = FALSE; | |
1791 if (XGetWMName(dpy, x11_window, &text_prop)) | |
1792 XFree((void *)text_prop.value); | |
1793 XSync(dpy, False); | |
1794 (void)XSetErrorHandler(old_handler); | |
1795 | |
1796 if (p_verbose > 0 && got_x_error) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1797 verb_msg(_("Testing the X display failed")); |
7 | 1798 |
1799 return (got_x_error ? FAIL : OK); | |
1800 } | |
1801 #endif | |
1802 | |
1803 #ifdef FEAT_TITLE | |
1804 | |
1805 #ifdef FEAT_X11 | |
1806 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1807 static int get_x11_thing(int get_title, int test_only); |
7 | 1808 |
1809 /* | |
1810 * try to get x11 window and display | |
1811 * | |
1812 * return FAIL for failure, OK otherwise | |
1813 */ | |
1814 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1815 get_x11_windis(void) |
7 | 1816 { |
1817 char *winid; | |
1818 static int result = -1; | |
1819 #define XD_NONE 0 /* x11_display not set here */ | |
1820 #define XD_HERE 1 /* x11_display opened here */ | |
1821 #define XD_GUI 2 /* x11_display used from gui.dpy */ | |
1822 #define XD_XTERM 3 /* x11_display used from xterm_dpy */ | |
1823 static int x11_display_from = XD_NONE; | |
1824 static int did_set_error_handler = FALSE; | |
1825 | |
1826 if (!did_set_error_handler) | |
1827 { | |
1828 /* X just exits if it finds an error otherwise! */ | |
1829 (void)XSetErrorHandler(x_error_handler); | |
1830 did_set_error_handler = TRUE; | |
1831 } | |
1832 | |
574 | 1833 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
7 | 1834 if (gui.in_use) |
1835 { | |
1836 /* | |
1837 * If the X11 display was opened here before, for the window where Vim | |
1838 * was started, close that one now to avoid a memory leak. | |
1839 */ | |
1840 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1841 { | |
1842 XCloseDisplay(x11_display); | |
1843 x11_display_from = XD_NONE; | |
1844 } | |
1845 if (gui_get_x11_windis(&x11_window, &x11_display) == OK) | |
1846 { | |
1847 x11_display_from = XD_GUI; | |
1848 return OK; | |
1849 } | |
1850 x11_display = NULL; | |
1851 return FAIL; | |
1852 } | |
1853 else if (x11_display_from == XD_GUI) | |
1854 { | |
1855 /* GUI must have stopped somehow, clear x11_display */ | |
1856 x11_window = 0; | |
1857 x11_display = NULL; | |
1858 x11_display_from = XD_NONE; | |
1859 } | |
1860 #endif | |
1861 | |
1862 /* When started with the "-X" argument, don't try connecting. */ | |
1863 if (!x_connect_to_server()) | |
1864 return FAIL; | |
1865 | |
1866 /* | |
1867 * If WINDOWID not set, should try another method to find out | |
1868 * what the current window number is. The only code I know for | |
1869 * this is very complicated. | |
1870 * We assume that zero is invalid for WINDOWID. | |
1871 */ | |
1872 if (x11_window == 0 && (winid = getenv("WINDOWID")) != NULL) | |
1873 x11_window = (Window)atol(winid); | |
1874 | |
1875 #ifdef FEAT_XCLIPBOARD | |
1876 if (xterm_dpy != NULL && x11_window != 0) | |
1877 { | |
1450 | 1878 /* We may have checked it already, but Gnome terminal can move us to |
1879 * another window, so we need to check every time. */ | |
1880 if (x11_display_from != XD_XTERM) | |
1881 { | |
1882 /* | |
1883 * If the X11 display was opened here before, for the window where | |
1884 * Vim was started, close that one now to avoid a memory leak. | |
1885 */ | |
1886 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1887 XCloseDisplay(x11_display); | |
1888 x11_display = xterm_dpy; | |
1889 x11_display_from = XD_XTERM; | |
1890 } | |
7 | 1891 if (test_x11_window(x11_display) == FAIL) |
1892 { | |
1893 /* probably bad $WINDOWID */ | |
1894 x11_window = 0; | |
1895 x11_display = NULL; | |
1896 x11_display_from = XD_NONE; | |
1897 return FAIL; | |
1898 } | |
1899 return OK; | |
1900 } | |
1901 #endif | |
1902 | |
1903 if (x11_window == 0 || x11_display == NULL) | |
1904 result = -1; | |
1905 | |
1906 if (result != -1) /* Have already been here and set this */ | |
1907 return result; /* Don't do all these X calls again */ | |
1908 | |
1909 if (x11_window != 0 && x11_display == NULL) | |
1910 { | |
1911 #ifdef SET_SIG_ALARM | |
1912 RETSIGTYPE (*sig_save)(); | |
1913 #endif | |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1914 #ifdef ELAPSED_FUNC |
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1915 elapsed_T start_tv; |
7 | 1916 |
1917 if (p_verbose > 0) | |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1918 ELAPSED_INIT(start_tv); |
7 | 1919 #endif |
1920 | |
1921 #ifdef SET_SIG_ALARM | |
1922 /* | |
1923 * Opening the Display may hang if the DISPLAY setting is wrong, or | |
1924 * the network connection is bad. Set an alarm timer to get out. | |
1925 */ | |
1926 sig_alarm_called = FALSE; | |
1927 sig_save = (RETSIGTYPE (*)())signal(SIGALRM, | |
1928 (RETSIGTYPE (*)())sig_alarm); | |
1929 alarm(2); | |
1930 #endif | |
1931 x11_display = XOpenDisplay(NULL); | |
1932 | |
1933 #ifdef SET_SIG_ALARM | |
1934 alarm(0); | |
1935 signal(SIGALRM, (RETSIGTYPE (*)())sig_save); | |
1936 if (p_verbose > 0 && sig_alarm_called) | |
292 | 1937 verb_msg((char_u *)_("Opening the X display timed out")); |
7 | 1938 #endif |
1939 if (x11_display != NULL) | |
1940 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1941 # ifdef ELAPSED_FUNC |
7 | 1942 if (p_verbose > 0) |
292 | 1943 { |
1944 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1945 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 1946 verbose_leave(); |
1947 } | |
7 | 1948 # endif |
1949 if (test_x11_window(x11_display) == FAIL) | |
1950 { | |
1951 /* Maybe window id is bad */ | |
1952 x11_window = 0; | |
1953 XCloseDisplay(x11_display); | |
1954 x11_display = NULL; | |
1955 } | |
1956 else | |
1957 x11_display_from = XD_HERE; | |
1958 } | |
1959 } | |
1960 if (x11_window == 0 || x11_display == NULL) | |
1961 return (result = FAIL); | |
2609 | 1962 |
1963 # ifdef FEAT_EVAL | |
1964 set_vim_var_nr(VV_WINDOWID, (long)x11_window); | |
1965 # endif | |
1966 | |
7 | 1967 return (result = OK); |
1968 } | |
1969 | |
1970 /* | |
1971 * Determine original x11 Window Title | |
1972 */ | |
1973 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1974 get_x11_title(int test_only) |
7 | 1975 { |
32 | 1976 return get_x11_thing(TRUE, test_only); |
7 | 1977 } |
1978 | |
1979 /* | |
1980 * Determine original x11 Window icon | |
1981 */ | |
1982 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1983 get_x11_icon(int test_only) |
7 | 1984 { |
1985 int retval = FALSE; | |
1986 | |
1987 retval = get_x11_thing(FALSE, test_only); | |
1988 | |
1989 /* could not get old icon, use terminal name */ | |
1990 if (oldicon == NULL && !test_only) | |
1991 { | |
1992 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 1993 oldicon = vim_strsave(T_NAME + 8); |
7 | 1994 else |
1940 | 1995 oldicon = vim_strsave(T_NAME); |
7 | 1996 } |
1997 | |
1998 return retval; | |
1999 } | |
2000 | |
2001 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2002 get_x11_thing( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2003 int get_title, /* get title string */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2004 int test_only) |
7 | 2005 { |
2006 XTextProperty text_prop; | |
2007 int retval = FALSE; | |
2008 Status status; | |
2009 | |
2010 if (get_x11_windis() == OK) | |
2011 { | |
2012 /* Get window/icon name if any */ | |
2013 if (get_title) | |
2014 status = XGetWMName(x11_display, x11_window, &text_prop); | |
2015 else | |
2016 status = XGetWMIconName(x11_display, x11_window, &text_prop); | |
2017 | |
2018 /* | |
2019 * If terminal is xterm, then x11_window may be a child window of the | |
2020 * outer xterm window that actually contains the window/icon name, so | |
2021 * keep traversing up the tree until a window with a title/icon is | |
2022 * found. | |
2023 */ | |
2024 /* Previously this was only done for xterm and alikes. I don't see a | |
2025 * reason why it would fail for other terminal emulators. | |
2026 * if (term_is_xterm) */ | |
2027 { | |
2028 Window root; | |
2029 Window parent; | |
2030 Window win = x11_window; | |
2031 Window *children; | |
2032 unsigned int num_children; | |
2033 | |
2034 while (!status || text_prop.value == NULL) | |
2035 { | |
2036 if (!XQueryTree(x11_display, win, &root, &parent, &children, | |
2037 &num_children)) | |
2038 break; | |
2039 if (children) | |
2040 XFree((void *)children); | |
2041 if (parent == root || parent == 0) | |
2042 break; | |
2043 | |
2044 win = parent; | |
2045 if (get_title) | |
2046 status = XGetWMName(x11_display, win, &text_prop); | |
2047 else | |
2048 status = XGetWMIconName(x11_display, win, &text_prop); | |
2049 } | |
2050 } | |
2051 if (status && text_prop.value != NULL) | |
2052 { | |
2053 retval = TRUE; | |
2054 if (!test_only) | |
2055 { | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2056 #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
|
2057 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
|
2058 # ifdef FEAT_MBYTE |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2059 && !has_mbyte |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2060 # endif |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2061 ) |
7 | 2062 { |
2063 #endif | |
2064 if (get_title) | |
2065 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2066 else | |
2067 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
|
2068 #if defined(FEAT_XFONTSET) || defined(FEAT_MBYTE) |
7 | 2069 } |
2070 else | |
2071 { | |
2072 char **cl; | |
2073 Status transform_status; | |
2074 int n = 0; | |
2075 | |
2076 transform_status = XmbTextPropertyToTextList(x11_display, | |
2077 &text_prop, | |
2078 &cl, &n); | |
2079 if (transform_status >= Success && n > 0 && cl[0]) | |
2080 { | |
2081 if (get_title) | |
2082 oldtitle = vim_strsave((char_u *) cl[0]); | |
2083 else | |
2084 oldicon = vim_strsave((char_u *) cl[0]); | |
2085 XFreeStringList(cl); | |
2086 } | |
2087 else | |
2088 { | |
2089 if (get_title) | |
2090 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2091 else | |
2092 oldicon = vim_strsave((char_u *)text_prop.value); | |
2093 } | |
2094 } | |
2095 #endif | |
2096 } | |
2097 XFree((void *)text_prop.value); | |
2098 } | |
2099 } | |
2100 return retval; | |
2101 } | |
2102 | |
6282 | 2103 /* Xutf8 functions are not avaialble on older systems. Note that on some |
2104 * systems X_HAVE_UTF8_STRING may be defined in a header file but | |
2105 * Xutf8SetWMProperties() is not in the X11 library. Configure checks for | |
2106 * that and defines HAVE_XUTF8SETWMPROPERTIES. */ | |
7 | 2107 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) |
6282 | 2108 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES |
7 | 2109 # define USE_UTF8_STRING |
2110 # endif | |
2111 #endif | |
2112 | |
2113 /* | |
2114 * Set x11 Window Title | |
2115 * | |
2116 * get_x11_windis() must be called before this and have returned OK | |
2117 */ | |
2118 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2119 set_x11_title(char_u *title) |
7 | 2120 { |
2121 /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING | |
2122 * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't | |
2123 * supported everywhere and STRING doesn't work for multi-byte titles. | |
2124 */ | |
2125 #ifdef USE_UTF8_STRING | |
2126 if (enc_utf8) | |
2127 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, | |
2128 NULL, NULL, 0, NULL, NULL, NULL); | |
2129 else | |
2130 #endif | |
2131 { | |
2132 #if XtSpecificationRelease >= 4 | |
2133 # ifdef FEAT_XFONTSET | |
2134 XmbSetWMProperties(x11_display, x11_window, (const char *)title, | |
2135 NULL, NULL, 0, NULL, NULL, NULL); | |
2136 # else | |
2137 XTextProperty text_prop; | |
129 | 2138 char *c_title = (char *)title; |
7 | 2139 |
2140 /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ | |
129 | 2141 (void)XStringListToTextProperty(&c_title, 1, &text_prop); |
7 | 2142 XSetWMProperties(x11_display, x11_window, &text_prop, |
2143 NULL, NULL, 0, NULL, NULL, NULL); | |
2144 # endif | |
2145 #else | |
2146 XStoreName(x11_display, x11_window, (char *)title); | |
2147 #endif | |
2148 } | |
2149 XFlush(x11_display); | |
2150 } | |
2151 | |
2152 /* | |
2153 * Set x11 Window icon | |
2154 * | |
2155 * get_x11_windis() must be called before this and have returned OK | |
2156 */ | |
2157 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2158 set_x11_icon(char_u *icon) |
7 | 2159 { |
2160 /* See above for comments about using X*SetWMProperties(). */ | |
2161 #ifdef USE_UTF8_STRING | |
2162 if (enc_utf8) | |
2163 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2164 NULL, 0, NULL, NULL, NULL); | |
2165 else | |
2166 #endif | |
2167 { | |
2168 #if XtSpecificationRelease >= 4 | |
2169 # ifdef FEAT_XFONTSET | |
2170 XmbSetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2171 NULL, 0, NULL, NULL, NULL); | |
2172 # else | |
2173 XTextProperty text_prop; | |
129 | 2174 char *c_icon = (char *)icon; |
2175 | |
2176 (void)XStringListToTextProperty(&c_icon, 1, &text_prop); | |
7 | 2177 XSetWMProperties(x11_display, x11_window, NULL, &text_prop, |
2178 NULL, 0, NULL, NULL, NULL); | |
2179 # endif | |
2180 #else | |
2181 XSetIconName(x11_display, x11_window, (char *)icon); | |
2182 #endif | |
2183 } | |
2184 XFlush(x11_display); | |
2185 } | |
2186 | |
2187 #else /* FEAT_X11 */ | |
2188 | |
2189 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2190 get_x11_title(int test_only UNUSED) |
7 | 2191 { |
2192 return FALSE; | |
2193 } | |
2194 | |
2195 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2196 get_x11_icon(int test_only) |
7 | 2197 { |
2198 if (!test_only) | |
2199 { | |
2200 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 2201 oldicon = vim_strsave(T_NAME + 8); |
7 | 2202 else |
1940 | 2203 oldicon = vim_strsave(T_NAME); |
7 | 2204 } |
2205 return FALSE; | |
2206 } | |
2207 | |
2208 #endif /* FEAT_X11 */ | |
2209 | |
2210 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2211 mch_can_restore_title(void) |
7 | 2212 { |
2213 return get_x11_title(TRUE); | |
2214 } | |
2215 | |
2216 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2217 mch_can_restore_icon(void) |
7 | 2218 { |
2219 return get_x11_icon(TRUE); | |
2220 } | |
2221 | |
2222 /* | |
2223 * Set the window title and icon. | |
2224 */ | |
2225 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2226 mch_settitle(char_u *title, char_u *icon) |
7 | 2227 { |
2228 int type = 0; | |
2229 static int recursive = 0; | |
2230 | |
2231 if (T_NAME == NULL) /* no terminal name (yet) */ | |
2232 return; | |
2233 if (title == NULL && icon == NULL) /* nothing to do */ | |
2234 return; | |
2235 | |
2236 /* When one of the X11 functions causes a deadly signal, we get here again | |
2237 * recursively. Avoid hanging then (something is probably locked). */ | |
2238 if (recursive) | |
2239 return; | |
2240 ++recursive; | |
2241 | |
2242 /* | |
2243 * if the window ID and the display is known, we may use X11 calls | |
2244 */ | |
2245 #ifdef FEAT_X11 | |
2246 if (get_x11_windis() == OK) | |
2247 type = 1; | |
2248 #else | |
2249 # if defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_GTK) | |
2250 if (gui.in_use) | |
2251 type = 1; | |
2252 # endif | |
2253 #endif | |
2254 | |
2255 /* | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2256 * Note: if "t_ts" is set, title is set with escape sequence rather |
7 | 2257 * than x11 calls, because the x11 calls don't always work |
2258 */ | |
2259 if ((type || *T_TS != NUL) && title != NULL) | |
2260 { | |
14573
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2261 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
|
2262 { |
738e9d1ac4d2
patch 8.1.0300: the old window title might be freed twice
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
2263 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
|
2264 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
|
2265 } |
7 | 2266 if (oldtitle == NULL |
2267 #ifdef FEAT_GUI | |
2268 && !gui.in_use | |
2269 #endif | |
2270 ) /* first call but not in GUI, save title */ | |
2271 (void)get_x11_title(FALSE); | |
2272 | |
2273 if (*T_TS != NUL) /* it's OK if t_fs is empty */ | |
2274 term_settitle(title); | |
2275 #ifdef FEAT_X11 | |
2276 else | |
2277 # ifdef FEAT_GUI_GTK | |
2278 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2279 # endif | |
2280 set_x11_title(title); /* x11 */ | |
2281 #endif | |
64 | 2282 #if defined(FEAT_GUI_GTK) \ |
7 | 2283 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
2284 else | |
2285 gui_mch_settitle(title, icon); | |
2286 #endif | |
2287 did_set_title = TRUE; | |
2288 } | |
2289 | |
2290 if ((type || *T_CIS != NUL) && icon != NULL) | |
2291 { | |
2292 if (oldicon == NULL | |
2293 #ifdef FEAT_GUI | |
2294 && !gui.in_use | |
2295 #endif | |
2296 ) /* first call, save icon */ | |
2297 get_x11_icon(FALSE); | |
2298 | |
2299 if (*T_CIS != NUL) | |
2300 { | |
2301 out_str(T_CIS); /* set icon start */ | |
2302 out_str_nf(icon); | |
2303 out_str(T_CIE); /* set icon end */ | |
2304 out_flush(); | |
2305 } | |
2306 #ifdef FEAT_X11 | |
2307 else | |
2308 # ifdef FEAT_GUI_GTK | |
2309 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2310 # endif | |
2311 set_x11_icon(icon); /* x11 */ | |
2312 #endif | |
2313 did_set_icon = TRUE; | |
2314 } | |
2315 --recursive; | |
2316 } | |
2317 | |
2318 /* | |
2319 * Restore the window/icon title. | |
2320 * "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
|
2321 * 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
|
2322 * 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
|
2323 * SAVE_RESTORE_BOTH restore title and icon |
7 | 2324 */ |
2325 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2326 mch_restore_title(int which) |
7 | 2327 { |
2328 /* 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
|
2329 mch_settitle(((which & SAVE_RESTORE_TITLE) && did_set_title) ? |
7 | 2330 (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
|
2331 ((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
|
2332 |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14461
diff
changeset
|
2333 // 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
|
2334 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
|
2335 term_push_title(which); |
7 | 2336 } |
2337 | |
2338 #endif /* FEAT_TITLE */ | |
2339 | |
2340 /* | |
2341 * Return TRUE if "name" looks like some xterm name. | |
158 | 2342 * Seiichi Sato mentioned that "mlterm" works like xterm. |
7 | 2343 */ |
2344 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2345 vim_is_xterm(char_u *name) |
7 | 2346 { |
2347 if (name == NULL) | |
2348 return FALSE; | |
2349 return (STRNICMP(name, "xterm", 5) == 0 | |
2350 || STRNICMP(name, "nxterm", 6) == 0 | |
2351 || STRNICMP(name, "kterm", 5) == 0 | |
158 | 2352 || STRNICMP(name, "mlterm", 6) == 0 |
7 | 2353 || 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
|
2354 || STRNICMP(name, "screen.xterm", 12) == 0 |
7 | 2355 || STRCMP(name, "builtin_xterm") == 0); |
2356 } | |
2357 | |
1620 | 2358 #if defined(FEAT_MOUSE_XTERM) || defined(PROTO) |
2359 /* | |
2360 * Return TRUE if "name" appears to be that of a terminal | |
2361 * known to support the xterm-style mouse protocol. | |
2362 * Relies on term_is_xterm having been set to its correct value. | |
2363 */ | |
2364 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2365 use_xterm_like_mouse(char_u *name) |
1620 | 2366 { |
2367 return (name != NULL | |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2368 && (term_is_xterm |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2369 || STRNICMP(name, "screen", 6) == 0 |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2370 || STRNICMP(name, "tmux", 4) == 0 |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2371 || STRICMP(name, "st") == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2372 || STRNICMP(name, "st-", 3) == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2373 || STRNICMP(name, "stterm", 6) == 0)); |
1620 | 2374 } |
2375 #endif | |
2376 | |
7 | 2377 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) |
2378 /* | |
2379 * Return non-zero when using an xterm mouse, according to 'ttymouse'. | |
2380 * Return 1 for "xterm". | |
2381 * Return 2 for "xterm2". | |
3145 | 2382 * Return 3 for "urxvt". |
3746 | 2383 * Return 4 for "sgr". |
7 | 2384 */ |
2385 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2386 use_xterm_mouse(void) |
7 | 2387 { |
3746 | 2388 if (ttym_flags == TTYM_SGR) |
2389 return 4; | |
3145 | 2390 if (ttym_flags == TTYM_URXVT) |
2391 return 3; | |
7 | 2392 if (ttym_flags == TTYM_XTERM2) |
2393 return 2; | |
2394 if (ttym_flags == TTYM_XTERM) | |
2395 return 1; | |
2396 return 0; | |
2397 } | |
2398 #endif | |
2399 | |
2400 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2401 vim_is_iris(char_u *name) |
7 | 2402 { |
2403 if (name == NULL) | |
2404 return FALSE; | |
2405 return (STRNICMP(name, "iris-ansi", 9) == 0 | |
2406 || STRCMP(name, "builtin_iris-ansi") == 0); | |
2407 } | |
2408 | |
2409 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2410 vim_is_vt300(char_u *name) |
7 | 2411 { |
2412 if (name == NULL) | |
2413 return FALSE; /* actually all ANSI comp. terminals should be here */ | |
22 | 2414 /* catch VT100 - VT5xx */ |
2415 return ((STRNICMP(name, "vt", 2) == 0 | |
2416 && vim_strchr((char_u *)"12345", name[2]) != NULL) | |
7 | 2417 || STRCMP(name, "builtin_vt320") == 0); |
2418 } | |
2419 | |
2420 /* | |
2421 * Return TRUE if "name" is a terminal for which 'ttyfast' should be set. | |
2422 * This should include all windowed terminal emulators. | |
2423 */ | |
2424 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2425 vim_is_fastterm(char_u *name) |
7 | 2426 { |
2427 if (name == NULL) | |
2428 return FALSE; | |
2429 if (vim_is_xterm(name) || vim_is_vt300(name) || vim_is_iris(name)) | |
2430 return TRUE; | |
2431 return ( STRNICMP(name, "hpterm", 6) == 0 | |
2432 || STRNICMP(name, "sun-cmd", 7) == 0 | |
2433 || STRNICMP(name, "screen", 6) == 0 | |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2434 || STRNICMP(name, "tmux", 4) == 0 |
7 | 2435 || STRNICMP(name, "dtterm", 6) == 0); |
2436 } | |
2437 | |
2438 /* | |
2439 * Insert user name in s[len]. | |
2440 * Return OK if a name found. | |
2441 */ | |
2442 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2443 mch_get_user_name(char_u *s, int len) |
7 | 2444 { |
2445 #ifdef VMS | |
509 | 2446 vim_strncpy(s, (char_u *)cuserid(NULL), len - 1); |
7 | 2447 return OK; |
2448 #else | |
2449 return mch_get_uname(getuid(), s, len); | |
2450 #endif | |
2451 } | |
2452 | |
2453 /* | |
2454 * Insert user name for "uid" in s[len]. | |
2455 * Return OK if a name found. | |
2456 */ | |
2457 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2458 mch_get_uname(uid_t uid, char_u *s, int len) |
7 | 2459 { |
2460 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) | |
2461 struct passwd *pw; | |
2462 | |
2463 if ((pw = getpwuid(uid)) != NULL | |
2464 && pw->pw_name != NULL && *(pw->pw_name) != NUL) | |
2465 { | |
418 | 2466 vim_strncpy(s, (char_u *)pw->pw_name, len - 1); |
7 | 2467 return OK; |
2468 } | |
2469 #endif | |
2470 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ | |
2471 return FAIL; /* a number is not a name */ | |
2472 } | |
2473 | |
2474 /* | |
2475 * Insert host name is s[len]. | |
2476 */ | |
2477 | |
2478 #ifdef HAVE_SYS_UTSNAME_H | |
2479 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2480 mch_get_host_name(char_u *s, int len) |
7 | 2481 { |
2482 struct utsname vutsname; | |
2483 | |
2484 if (uname(&vutsname) < 0) | |
2485 *s = NUL; | |
2486 else | |
418 | 2487 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); |
7 | 2488 } |
2489 #else /* HAVE_SYS_UTSNAME_H */ | |
2490 | |
2491 # ifdef HAVE_SYS_SYSTEMINFO_H | |
2492 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) | |
2493 # endif | |
2494 | |
2495 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2496 mch_get_host_name(char_u *s, int len) |
7 | 2497 { |
2498 # ifdef VAXC | |
2499 vaxc$gethostname((char *)s, len); | |
2500 # else | |
2501 gethostname((char *)s, len); | |
2502 # endif | |
2503 s[len - 1] = NUL; /* make sure it's terminated */ | |
2504 } | |
2505 #endif /* HAVE_SYS_UTSNAME_H */ | |
2506 | |
2507 /* | |
2508 * return process ID | |
2509 */ | |
2510 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2511 mch_get_pid(void) |
7 | 2512 { |
2513 return (long)getpid(); | |
2514 } | |
2515 | |
2516 #if !defined(HAVE_STRERROR) && defined(USE_GETCWD) | |
2517 static char * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2518 strerror(int err) |
7 | 2519 { |
2520 extern int sys_nerr; | |
2521 extern char *sys_errlist[]; | |
2522 static char er[20]; | |
2523 | |
2524 if (err > 0 && err < sys_nerr) | |
2525 return (sys_errlist[err]); | |
2526 sprintf(er, "Error %d", err); | |
2527 return er; | |
2528 } | |
2529 #endif | |
2530 | |
2531 /* | |
2532 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2533 * Return OK for success, FAIL for failure. | |
2534 */ | |
2535 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2536 mch_dirname(char_u *buf, int len) |
7 | 2537 { |
2538 #if defined(USE_GETCWD) | |
2539 if (getcwd((char *)buf, len) == NULL) | |
2540 { | |
2541 STRCPY(buf, strerror(errno)); | |
2542 return FAIL; | |
2543 } | |
2544 return OK; | |
2545 #else | |
2546 return (getwd((char *)buf) != NULL ? OK : FAIL); | |
2547 #endif | |
2548 } | |
2549 | |
2550 /* | |
1045 | 2551 * Get absolute file name into "buf[len]". |
7 | 2552 * |
2553 * return FAIL for failure, OK for success | |
2554 */ | |
2555 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2556 mch_FullName( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2557 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2558 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2559 int len, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2560 int force) /* also expand when already absolute path */ |
7 | 2561 { |
2562 int l; | |
1082 | 2563 #ifdef HAVE_FCHDIR |
7 | 2564 int fd = -1; |
2565 static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ | |
1082 | 2566 #endif |
7 | 2567 char_u olddir[MAXPATHL]; |
2568 char_u *p; | |
2569 int retval = OK; | |
1615 | 2570 #ifdef __CYGWIN__ |
1620 | 2571 char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but |
2572 it's not always defined */ | |
2573 #endif | |
7 | 2574 |
1082 | 2575 #ifdef VMS |
2576 fname = vms_fixfilename(fname); | |
2577 #endif | |
2578 | |
1102 | 2579 #ifdef __CYGWIN__ |
2580 /* | |
2581 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". | |
2582 */ | |
1657 | 2583 # 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
|
2584 /* 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
|
2585 * a forward slash. */ |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2586 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
|
2587 fname, posix_fname, MAXPATHL); |
1657 | 2588 # else |
1615 | 2589 cygwin_conv_to_posix_path(fname, posix_fname); |
1657 | 2590 # endif |
1615 | 2591 fname = posix_fname; |
1102 | 2592 #endif |
2593 | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2594 /* 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
|
2595 * 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
|
2596 if ((force || !mch_isFullName(fname)) |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2597 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) |
7 | 2598 { |
2599 /* | |
2600 * If the file name has a path, change to that directory for a moment, | |
2601 * and then do the getwd() (and get back to where we were). | |
2602 * This will get the correct path name with "../" things. | |
2603 */ | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2604 if (p != NULL) |
7 | 2605 { |
1082 | 2606 #ifdef HAVE_FCHDIR |
7 | 2607 /* |
2608 * Use fchdir() if possible, it's said to be faster and more | |
2609 * reliable. But on SunOS 4 it might not work. Check this by | |
2610 * doing a fchdir() right now. | |
2611 */ | |
2612 if (!dont_fchdir) | |
2613 { | |
2614 fd = open(".", O_RDONLY | O_EXTRA, 0); | |
2615 if (fd >= 0 && fchdir(fd) < 0) | |
2616 { | |
2617 close(fd); | |
2618 fd = -1; | |
2619 dont_fchdir = TRUE; /* don't try again */ | |
2620 } | |
2621 } | |
1082 | 2622 #endif |
7 | 2623 |
2624 /* Only change directory when we are sure we can return to where | |
2625 * we are now. After doing "su" chdir(".") might not work. */ | |
2626 if ( | |
1082 | 2627 #ifdef HAVE_FCHDIR |
7 | 2628 fd < 0 && |
1082 | 2629 #endif |
7 | 2630 (mch_dirname(olddir, MAXPATHL) == FAIL |
2631 || mch_chdir((char *)olddir) != 0)) | |
2632 { | |
2633 p = NULL; /* can't get current dir: don't chdir */ | |
2634 retval = FAIL; | |
2635 } | |
2636 else | |
2637 { | |
2638 /* The directory is copied into buf[], to be able to remove | |
2639 * the file name without changing it (could be a string in | |
2640 * read-only memory) */ | |
2641 if (p - fname >= len) | |
2642 retval = FAIL; | |
2643 else | |
2644 { | |
418 | 2645 vim_strncpy(buf, fname, p - fname); |
7 | 2646 if (mch_chdir((char *)buf)) |
2647 retval = FAIL; | |
2648 else | |
2649 fname = p + 1; | |
2650 *buf = NUL; | |
2651 } | |
2652 } | |
2653 } | |
2654 if (mch_dirname(buf, len) == FAIL) | |
2655 { | |
2656 retval = FAIL; | |
2657 *buf = NUL; | |
2658 } | |
2659 if (p != NULL) | |
2660 { | |
1082 | 2661 #ifdef HAVE_FCHDIR |
7 | 2662 if (fd >= 0) |
2663 { | |
1935 | 2664 if (p_verbose >= 5) |
2665 { | |
2666 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
2667 msg("fchdir() to previous dir"); |
1935 | 2668 verbose_leave(); |
2669 } | |
7 | 2670 l = fchdir(fd); |
2671 close(fd); | |
2672 } | |
2673 else | |
1082 | 2674 #endif |
7 | 2675 l = mch_chdir((char *)olddir); |
2676 if (l != 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
2677 emsg(_(e_prev_dir)); |
7 | 2678 } |
2679 | |
2680 l = STRLEN(buf); | |
3867 | 2681 if (l >= len - 1) |
2682 retval = FAIL; /* no space for trailing "/" */ | |
1082 | 2683 #ifndef VMS |
3867 | 2684 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL |
7 | 2685 && STRCMP(fname, ".") != 0) |
3867 | 2686 STRCAT(buf, "/"); |
1082 | 2687 #endif |
7 | 2688 } |
1045 | 2689 |
7 | 2690 /* Catch file names which are too long. */ |
1877 | 2691 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) |
7 | 2692 return FAIL; |
2693 | |
2694 /* Do not append ".", "/dir/." is equal to "/dir". */ | |
2695 if (STRCMP(fname, ".") != 0) | |
2696 STRCAT(buf, fname); | |
2697 | |
2698 return OK; | |
2699 } | |
2700 | |
2701 /* | |
2702 * Return TRUE if "fname" does not depend on the current directory. | |
2703 */ | |
2704 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2705 mch_isFullName(char_u *fname) |
7 | 2706 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
2707 #ifdef VMS |
7 | 2708 return ( fname[0] == '/' || fname[0] == '.' || |
2709 strchr((char *)fname,':') || strchr((char *)fname,'"') || | |
2710 (strchr((char *)fname,'[') && strchr((char *)fname,']'))|| | |
2711 (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
|
2712 #else |
7 | 2713 return (*fname == '/' || *fname == '~'); |
2714 #endif | |
2715 } | |
2716 | |
585 | 2717 #if defined(USE_FNAME_CASE) || defined(PROTO) |
2718 /* | |
2719 * Set the case of the file name, if it already exists. This will cause the | |
2720 * file name to remain exactly the same. | |
1450 | 2721 * Only required for file systems where case is ignored and preserved. |
585 | 2722 */ |
2723 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2724 fname_case( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2725 char_u *name, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2726 int len UNUSED) /* buffer size, only used when name gets longer */ |
585 | 2727 { |
2728 struct stat st; | |
2729 char_u *slash, *tail; | |
2730 DIR *dirp; | |
2731 struct dirent *dp; | |
2732 | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2733 if (mch_lstat((char *)name, &st) >= 0) |
585 | 2734 { |
2735 /* Open the directory where the file is located. */ | |
2736 slash = vim_strrchr(name, '/'); | |
2737 if (slash == NULL) | |
2738 { | |
2739 dirp = opendir("."); | |
2740 tail = name; | |
2741 } | |
2742 else | |
2743 { | |
2744 *slash = NUL; | |
2745 dirp = opendir((char *)name); | |
2746 *slash = '/'; | |
2747 tail = slash + 1; | |
2748 } | |
2749 | |
2750 if (dirp != NULL) | |
2751 { | |
2752 while ((dp = readdir(dirp)) != NULL) | |
2753 { | |
2754 /* Only accept names that differ in case and are the same byte | |
2755 * length. TODO: accept different length name. */ | |
2756 if (STRICMP(tail, dp->d_name) == 0 | |
2757 && STRLEN(tail) == STRLEN(dp->d_name)) | |
2758 { | |
2759 char_u newname[MAXPATHL + 1]; | |
2760 struct stat st2; | |
2761 | |
2762 /* Verify the inode is equal. */ | |
2763 vim_strncpy(newname, name, MAXPATHL); | |
2764 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, | |
2765 MAXPATHL - (tail - name)); | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2766 if (mch_lstat((char *)newname, &st2) >= 0 |
585 | 2767 && st.st_ino == st2.st_ino |
2768 && st.st_dev == st2.st_dev) | |
2769 { | |
2770 STRCPY(tail, dp->d_name); | |
2771 break; | |
2772 } | |
2773 } | |
2774 } | |
2775 | |
2776 closedir(dirp); | |
2777 } | |
2778 } | |
2779 } | |
2780 #endif | |
2781 | |
7 | 2782 /* |
2783 * Get file permissions for 'name'. | |
2784 * Returns -1 when it doesn't exist. | |
2785 */ | |
2786 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2787 mch_getperm(char_u *name) |
7 | 2788 { |
2789 struct stat statb; | |
2790 | |
2791 /* Keep the #ifdef outside of stat(), it may be a macro. */ | |
2792 #ifdef VMS | |
2793 if (stat((char *)vms_fixfilename(name), &statb)) | |
2794 #else | |
2795 if (stat((char *)name, &statb)) | |
2796 #endif | |
2797 return -1; | |
1350 | 2798 #ifdef __INTERIX |
2799 /* The top bit makes the value negative, which means the file doesn't | |
2800 * exist. Remove the bit, we don't use it. */ | |
2801 return statb.st_mode & ~S_ADDACE; | |
2802 #else | |
7 | 2803 return statb.st_mode; |
1350 | 2804 #endif |
7 | 2805 } |
2806 | |
2807 /* | |
12847
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2808 * 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
|
2809 * Return FAIL for failure, OK otherwise. |
7 | 2810 */ |
2811 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2812 mch_setperm(char_u *name, long perm) |
7 | 2813 { |
2814 return (chmod((char *) | |
2815 #ifdef VMS | |
2816 vms_fixfilename(name), | |
2817 #else | |
2818 name, | |
2819 #endif | |
2820 (mode_t)perm) == 0 ? OK : FAIL); | |
2821 } | |
2822 | |
12847
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2823 #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
|
2824 /* |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2825 * 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
|
2826 * 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
|
2827 */ |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2828 int |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2829 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
|
2830 { |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2831 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
|
2832 } |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2833 #endif |
14f287552218
patch 8.0.1300: file permissions may end up wrong when writing
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2834 |
7 | 2835 #if defined(HAVE_ACL) || defined(PROTO) |
2836 # ifdef HAVE_SYS_ACL_H | |
2837 # include <sys/acl.h> | |
2838 # endif | |
2839 # ifdef HAVE_SYS_ACCESS_H | |
2840 # include <sys/access.h> | |
2841 # endif | |
2842 | |
2843 # ifdef HAVE_SOLARIS_ACL | |
2844 typedef struct vim_acl_solaris_T { | |
2845 int acl_cnt; | |
2846 aclent_t *acl_entry; | |
2847 } vim_acl_solaris_T; | |
2848 # endif | |
2849 | |
1583 | 2850 #if defined(HAVE_SELINUX) || defined(PROTO) |
2851 /* | |
2852 * Copy security info from "from_file" to "to_file". | |
2853 */ | |
2854 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2855 mch_copy_sec(char_u *from_file, char_u *to_file) |
1583 | 2856 { |
2857 if (from_file == NULL) | |
2858 return; | |
2859 | |
2860 if (selinux_enabled == -1) | |
2861 selinux_enabled = is_selinux_enabled(); | |
2862 | |
2863 if (selinux_enabled > 0) | |
2864 { | |
2865 security_context_t from_context = NULL; | |
2866 security_context_t to_context = NULL; | |
2867 | |
2868 if (getfilecon((char *)from_file, &from_context) < 0) | |
2869 { | |
2870 /* If the filesystem doesn't support extended attributes, | |
2871 the original had no special security context and the | |
2872 target cannot have one either. */ | |
2873 if (errno == EOPNOTSUPP) | |
2874 return; | |
2875 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
2876 msg_puts(_("\nCould not get security context for ")); |
1583 | 2877 msg_outtrans(from_file); |
2878 msg_putchar('\n'); | |
2879 return; | |
2880 } | |
2881 if (getfilecon((char *)to_file, &to_context) < 0) | |
2882 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
2883 msg_puts(_("\nCould not get security context for ")); |
1583 | 2884 msg_outtrans(to_file); |
2885 msg_putchar('\n'); | |
2886 freecon (from_context); | |
2887 return ; | |
2888 } | |
2889 if (strcmp(from_context, to_context) != 0) | |
2890 { | |
2891 if (setfilecon((char *)to_file, from_context) < 0) | |
2892 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
2893 msg_puts(_("\nCould not set security context for ")); |
1583 | 2894 msg_outtrans(to_file); |
2895 msg_putchar('\n'); | |
2896 } | |
2897 } | |
2898 freecon(to_context); | |
2899 freecon(from_context); | |
2900 } | |
2901 } | |
2902 #endif /* HAVE_SELINUX */ | |
2903 | |
5788 | 2904 #if defined(HAVE_SMACK) && !defined(PROTO) |
2905 /* | |
2906 * Copy security info from "from_file" to "to_file". | |
2907 */ | |
2908 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2909 mch_copy_sec(char_u *from_file, char_u *to_file) |
5788 | 2910 { |
5832 | 2911 static const char * const smack_copied_attributes[] = |
5788 | 2912 { |
2913 XATTR_NAME_SMACK, | |
2914 XATTR_NAME_SMACKEXEC, | |
2915 XATTR_NAME_SMACKMMAP | |
2916 }; | |
2917 | |
2918 char buffer[SMACK_LABEL_LEN]; | |
2919 const char *name; | |
2920 int index; | |
2921 int ret; | |
2922 ssize_t size; | |
2923 | |
2924 if (from_file == NULL) | |
2925 return; | |
2926 | |
2927 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) | |
2928 / sizeof(smack_copied_attributes)[0]) ; index++) | |
2929 { | |
2930 /* get the name of the attribute to copy */ | |
2931 name = smack_copied_attributes[index]; | |
2932 | |
2933 /* get the value of the attribute in buffer */ | |
2934 size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); | |
2935 if (size >= 0) | |
2936 { | |
2937 /* copy the attribute value of buffer */ | |
2938 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); | |
2939 if (ret < 0) | |
2940 { | |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2941 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2942 _("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
|
2943 name, to_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2944 msg_outtrans(IObuff); |
5788 | 2945 msg_putchar('\n'); |
2946 } | |
2947 } | |
2948 else | |
2949 { | |
2950 /* what reason of not having the attribute value? */ | |
2951 switch (errno) | |
2952 { | |
2953 case ENOTSUP: | |
2954 /* extended attributes aren't supported or enabled */ | |
2955 /* should a message be echoed? not sure... */ | |
2956 return; /* leave because it isn't usefull to continue */ | |
2957 | |
2958 case ERANGE: | |
2959 default: | |
2960 /* 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
|
2961 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2962 _("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
|
2963 name, from_file); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
2964 msg_puts((char *)IObuff); |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2965 msg_putchar('\n'); |
5788 | 2966 /* FALLTHROUGH to remove the attribute */ |
2967 | |
2968 case ENODATA: | |
2969 /* no attribute of this name */ | |
2970 ret = removexattr((char*)to_file, name); | |
5800 | 2971 /* Silently ignore errors, apparently this happens when |
2972 * smack is not actually being used. */ | |
5788 | 2973 break; |
2974 } | |
2975 } | |
2976 } | |
2977 } | |
2978 #endif /* HAVE_SMACK */ | |
2979 | |
7 | 2980 /* |
2981 * Return a pointer to the ACL of file "fname" in allocated memory. | |
2982 * Return NULL if the ACL is not available for whatever reason. | |
2983 */ | |
2984 vim_acl_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2985 mch_get_acl(char_u *fname UNUSED) |
7 | 2986 { |
2987 vim_acl_T ret = NULL; | |
2988 #ifdef HAVE_POSIX_ACL | |
2989 ret = (vim_acl_T)acl_get_file((char *)fname, ACL_TYPE_ACCESS); | |
2990 #else | |
3330 | 2991 #ifdef HAVE_SOLARIS_ZFS_ACL |
2992 acl_t *aclent; | |
2993 | |
2994 if (acl_get((char *)fname, 0, &aclent) < 0) | |
2995 return NULL; | |
2996 ret = (vim_acl_T)aclent; | |
2997 #else | |
7 | 2998 #ifdef HAVE_SOLARIS_ACL |
2999 vim_acl_solaris_T *aclent; | |
3000 | |
3001 aclent = malloc(sizeof(vim_acl_solaris_T)); | |
3002 if ((aclent->acl_cnt = acl((char *)fname, GETACLCNT, 0, NULL)) < 0) | |
3003 { | |
3004 free(aclent); | |
3005 return NULL; | |
3006 } | |
3007 aclent->acl_entry = malloc(aclent->acl_cnt * sizeof(aclent_t)); | |
3008 if (acl((char *)fname, GETACL, aclent->acl_cnt, aclent->acl_entry) < 0) | |
3009 { | |
3010 free(aclent->acl_entry); | |
3011 free(aclent); | |
3012 return NULL; | |
3013 } | |
3014 ret = (vim_acl_T)aclent; | |
3015 #else | |
3016 #if defined(HAVE_AIX_ACL) | |
3017 int aclsize; | |
3018 struct acl *aclent; | |
3019 | |
3020 aclsize = sizeof(struct acl); | |
3021 aclent = malloc(aclsize); | |
3022 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
3023 { | |
3024 if (errno == ENOSPC) | |
3025 { | |
3026 aclsize = aclent->acl_len; | |
3027 aclent = realloc(aclent, aclsize); | |
3028 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
3029 { | |
3030 free(aclent); | |
3031 return NULL; | |
3032 } | |
3033 } | |
3034 else | |
3035 { | |
3036 free(aclent); | |
3037 return NULL; | |
3038 } | |
3039 } | |
3040 ret = (vim_acl_T)aclent; | |
3041 #endif /* HAVE_AIX_ACL */ | |
3042 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3043 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3044 #endif /* HAVE_POSIX_ACL */ |
3045 return ret; | |
3046 } | |
3047 | |
3048 /* | |
3049 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3050 */ | |
3051 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3052 mch_set_acl(char_u *fname UNUSED, vim_acl_T aclent) |
7 | 3053 { |
3054 if (aclent == NULL) | |
3055 return; | |
3056 #ifdef HAVE_POSIX_ACL | |
3057 acl_set_file((char *)fname, ACL_TYPE_ACCESS, (acl_t)aclent); | |
3058 #else | |
3330 | 3059 #ifdef HAVE_SOLARIS_ZFS_ACL |
3060 acl_set((char *)fname, (acl_t *)aclent); | |
3061 #else | |
7 | 3062 #ifdef HAVE_SOLARIS_ACL |
3063 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt, | |
3064 ((vim_acl_solaris_T *)aclent)->acl_entry); | |
3065 #else | |
3066 #ifdef HAVE_AIX_ACL | |
3067 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); | |
3068 #endif /* HAVE_AIX_ACL */ | |
3069 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3070 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3071 #endif /* HAVE_POSIX_ACL */ |
3072 } | |
3073 | |
3074 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3075 mch_free_acl(vim_acl_T aclent) |
7 | 3076 { |
3077 if (aclent == NULL) | |
3078 return; | |
3079 #ifdef HAVE_POSIX_ACL | |
3080 acl_free((acl_t)aclent); | |
3081 #else | |
3330 | 3082 #ifdef HAVE_SOLARIS_ZFS_ACL |
3083 acl_free((acl_t *)aclent); | |
3084 #else | |
7 | 3085 #ifdef HAVE_SOLARIS_ACL |
3086 free(((vim_acl_solaris_T *)aclent)->acl_entry); | |
3087 free(aclent); | |
3088 #else | |
3089 #ifdef HAVE_AIX_ACL | |
3090 free(aclent); | |
3091 #endif /* HAVE_AIX_ACL */ | |
3092 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3093 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3094 #endif /* HAVE_POSIX_ACL */ |
3095 } | |
3096 #endif | |
3097 | |
3098 /* | |
3099 * Set hidden flag for "name". | |
3100 */ | |
3101 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3102 mch_hide(char_u *name UNUSED) |
7 | 3103 { |
3104 /* can't hide a file */ | |
3105 } | |
3106 | |
3107 /* | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3108 * return TRUE if "name" is a directory or a symlink to a directory |
7 | 3109 * return FALSE if "name" is not a directory |
3110 * return FALSE for error | |
3111 */ | |
3112 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3113 mch_isdir(char_u *name) |
7 | 3114 { |
3115 struct stat statb; | |
3116 | |
3117 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ | |
3118 return FALSE; | |
3119 if (stat((char *)name, &statb)) | |
3120 return FALSE; | |
3121 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); | |
3122 } | |
3123 | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3124 /* |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3125 * 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
|
3126 * 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
|
3127 * return FALSE for error |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3128 */ |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3129 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3130 mch_isrealdir(char_u *name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3131 { |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3132 struct stat statb; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3133 |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3134 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
|
3135 return FALSE; |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
3136 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
|
3137 return FALSE; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3138 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
|
3139 } |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3140 |
7 | 3141 /* |
3142 * Return 1 if "name" is an executable file, 0 if not or it doesn't exist. | |
3143 */ | |
3144 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3145 executable_file(char_u *name) |
7 | 3146 { |
3147 struct stat st; | |
3148 | |
3149 if (stat((char *)name, &st)) | |
3150 return 0; | |
5704 | 3151 #ifdef VMS |
3152 /* Like on Unix system file can have executable rights but not necessarily | |
3153 * be an executable, but on Unix is not a default for an ordianry file to | |
3154 * have an executable flag - on VMS it is in most cases. | |
3155 * Therefore, this check does not have any sense - let keep us to the | |
3156 * conventions instead: | |
3157 * *.COM and *.EXE files are the executables - the rest are not. This is | |
3158 * not ideal but better then it was. | |
3159 */ | |
3160 int vms_executable = 0; | |
3161 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) | |
3162 { | |
3163 if (strstr(vms_tolower((char*)name),".exe") != NULL | |
3164 || strstr(vms_tolower((char*)name),".com")!= NULL) | |
3165 vms_executable = 1; | |
3166 } | |
3167 return vms_executable; | |
3168 #else | |
7 | 3169 return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0; |
5704 | 3170 #endif |
7 | 3171 } |
3172 | |
3173 /* | |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
3174 * Return TRUE if "name" can be found in $PATH and executed, FALSE if not. |
6695 | 3175 * If "use_path" is FALSE only check if "name" is executable. |
7 | 3176 * Return -1 if unknown. |
3177 */ | |
3178 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3179 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3180 { |
3181 char_u *buf; | |
3182 char_u *p, *e; | |
3183 int retval; | |
3184 | |
6695 | 3185 /* When "use_path" is false and if it's an absolute or relative path don't |
3186 * need to use $PATH. */ | |
3187 if (!use_path || mch_isFullName(name) || (name[0] == '.' | |
3188 && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) | |
5704 | 3189 { |
6695 | 3190 /* There must be a path separator, files in the current directory |
3191 * can't be executed. */ | |
3192 if (gettail(name) != name && executable_file(name)) | |
5782 | 3193 { |
3194 if (path != NULL) | |
3195 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3196 if (name[0] != '/') |
5782 | 3197 *path = FullName_save(name, TRUE); |
3198 else | |
3199 *path = vim_strsave(name); | |
3200 } | |
3201 return TRUE; | |
3202 } | |
3203 return FALSE; | |
5704 | 3204 } |
7 | 3205 |
3206 p = (char_u *)getenv("PATH"); | |
3207 if (p == NULL || *p == NUL) | |
3208 return -1; | |
3209 buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); | |
3210 if (buf == NULL) | |
3211 return -1; | |
3212 | |
3213 /* | |
3214 * Walk through all entries in $PATH to check if "name" exists there and | |
3215 * is an executable file. | |
3216 */ | |
3217 for (;;) | |
3218 { | |
3219 e = (char_u *)strchr((char *)p, ':'); | |
3220 if (e == NULL) | |
3221 e = p + STRLEN(p); | |
3222 if (e - p <= 1) /* empty entry means current dir */ | |
3223 STRCPY(buf, "./"); | |
3224 else | |
3225 { | |
418 | 3226 vim_strncpy(buf, p, e - p); |
7 | 3227 add_pathsep(buf); |
3228 } | |
3229 STRCAT(buf, name); | |
3230 retval = executable_file(buf); | |
3231 if (retval == 1) | |
5782 | 3232 { |
3233 if (path != NULL) | |
3234 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3235 if (buf[0] != '/') |
5782 | 3236 *path = FullName_save(buf, TRUE); |
3237 else | |
3238 *path = vim_strsave(buf); | |
3239 } | |
7 | 3240 break; |
5782 | 3241 } |
7 | 3242 |
3243 if (*e != ':') | |
3244 break; | |
3245 p = e + 1; | |
3246 } | |
3247 | |
3248 vim_free(buf); | |
3249 return retval; | |
3250 } | |
3251 | |
3252 /* | |
3253 * Check what "name" is: | |
3254 * NODE_NORMAL: file or directory (or doesn't exist) | |
3255 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3256 * NODE_OTHER: non-writable things | |
3257 */ | |
3258 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3259 mch_nodetype(char_u *name) |
7 | 3260 { |
3261 struct stat st; | |
3262 | |
3263 if (stat((char *)name, &st)) | |
3264 return NODE_NORMAL; | |
3265 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) | |
3266 return NODE_NORMAL; | |
3267 if (S_ISBLK(st.st_mode)) /* block device isn't writable */ | |
3268 return NODE_OTHER; | |
3269 /* Everything else is writable? */ | |
3270 return NODE_WRITABLE; | |
3271 } | |
3272 | |
3273 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3274 mch_early_init(void) |
7 | 3275 { |
3276 #ifdef HAVE_CHECK_STACK_GROWTH | |
3277 int i; | |
180 | 3278 |
7 | 3279 check_stack_growth((char *)&i); |
3280 | |
180 | 3281 # ifdef HAVE_STACK_LIMIT |
7 | 3282 get_stack_limit(); |
3283 # endif | |
3284 | |
3285 #endif | |
3286 | |
3287 /* | |
3288 * Setup an alternative stack for signals. Helps to catch signals when | |
3289 * running out of stack space. | |
3290 * Use of sigaltstack() is preferred, it's more portable. | |
3291 * Ignore any errors. | |
3292 */ | |
3293 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1737 | 3294 signal_stack = (char *)alloc(SIGSTKSZ); |
7 | 3295 init_signal_stack(); |
3296 #endif | |
3297 } | |
3298 | |
355 | 3299 #if defined(EXITFREE) || defined(PROTO) |
3300 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3301 mch_free_mem(void) |
355 | 3302 { |
359 | 3303 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
3304 if (clip_star.owned) | |
3305 clip_lose_selection(&clip_star); | |
3306 if (clip_plus.owned) | |
3307 clip_lose_selection(&clip_plus); | |
355 | 3308 # endif |
1605 | 3309 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
355 | 3310 if (xterm_Shell != (Widget)0) |
3311 XtDestroyWidget(xterm_Shell); | |
1605 | 3312 # ifndef LESSTIF_VERSION |
3313 /* Lesstif crashes here, lose some memory */ | |
355 | 3314 if (xterm_dpy != NULL) |
3315 XtCloseDisplay(xterm_dpy); | |
3316 if (app_context != (XtAppContext)NULL) | |
1605 | 3317 { |
355 | 3318 XtDestroyApplicationContext(app_context); |
1605 | 3319 # ifdef FEAT_X11 |
3320 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
3321 # endif | |
3322 } | |
3323 # endif | |
355 | 3324 # endif |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
3325 # if defined(FEAT_X11) |
1605 | 3326 if (x11_display != NULL |
3327 # ifdef FEAT_XCLIPBOARD | |
3328 && x11_display != xterm_dpy | |
3329 # endif | |
3330 ) | |
359 | 3331 XCloseDisplay(x11_display); |
3332 # endif | |
3333 # 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
|
3334 VIM_CLEAR(signal_stack); |
359 | 3335 # endif |
3336 # ifdef FEAT_TITLE | |
3337 vim_free(oldtitle); | |
3338 vim_free(oldicon); | |
3339 # endif | |
355 | 3340 } |
3341 #endif | |
3342 | |
7 | 3343 /* |
3344 * Output a newline when exiting. | |
3345 * Make sure the newline goes to the same stream as the text. | |
3346 */ | |
3347 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3348 exit_scroll(void) |
7 | 3349 { |
167 | 3350 if (silent_mode) |
3351 return; | |
7 | 3352 if (newline_on_exit || msg_didout) |
3353 { | |
3354 if (msg_use_printf()) | |
3355 { | |
3356 if (info_message) | |
3357 mch_msg("\n"); | |
3358 else | |
3359 mch_errmsg("\r\n"); | |
3360 } | |
3361 else | |
3362 out_char('\n'); | |
3363 } | |
3364 else | |
3365 { | |
3366 restore_cterm_colors(); /* get original colors back */ | |
3367 msg_clr_eos_force(); /* clear the rest of the display */ | |
3368 windgoto((int)Rows - 1, 0); /* may have moved the cursor */ | |
3369 } | |
3370 } | |
3371 | |
3372 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3373 mch_exit(int r) |
7 | 3374 { |
3375 exiting = TRUE; | |
3376 | |
3377 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
3378 x11_export_final_selection(); | |
3379 #endif | |
3380 | |
3381 #ifdef FEAT_GUI | |
3382 if (!gui.in_use) | |
3383 #endif | |
3384 { | |
3385 settmode(TMODE_COOK); | |
3386 #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
|
3387 // 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
|
3388 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
|
3389 term_pop_title(SAVE_RESTORE_BOTH); |
7 | 3390 #endif |
3391 /* | |
3392 * When t_ti is not empty but it doesn't cause swapping terminal | |
3393 * pages, need to output a newline when msg_didout is set. But when | |
3394 * t_ti does swap pages it should not go to the shell page. Do this | |
3395 * before stoptermcap(). | |
3396 */ | |
3397 if (swapping_screen() && !newline_on_exit) | |
3398 exit_scroll(); | |
3399 | |
3400 /* Stop termcap: May need to check for T_CRV response, which | |
3401 * requires RAW mode. */ | |
3402 stoptermcap(); | |
3403 | |
3404 /* | |
3405 * A newline is only required after a message in the alternate screen. | |
3406 * This is set to TRUE by wait_return(). | |
3407 */ | |
3408 if (!swapping_screen() || newline_on_exit) | |
3409 exit_scroll(); | |
3410 | |
3411 /* Cursor may have been switched off without calling starttermcap() | |
3412 * when doing "vim -u vimrc" and vimrc contains ":q". */ | |
3413 if (full_screen) | |
3414 cursor_on(); | |
3415 } | |
3416 out_flush(); | |
3417 ml_close_all(TRUE); /* remove all memfiles */ | |
3418 may_core_dump(); | |
3419 #ifdef FEAT_GUI | |
3420 if (gui.in_use) | |
3421 gui_exit(r); | |
3422 #endif | |
167 | 3423 |
765 | 3424 #ifdef MACOS_CONVERT |
167 | 3425 mac_conv_cleanup(); |
3426 #endif | |
3427 | |
7 | 3428 #ifdef __QNX__ |
3429 /* A core dump won't be created if the signal handler | |
3430 * doesn't return, so we can't call exit() */ | |
3431 if (deadly_signal != 0) | |
3432 return; | |
3433 #endif | |
3434 | |
33 | 3435 #ifdef FEAT_NETBEANS_INTG |
2210 | 3436 netbeans_send_disconnect(); |
33 | 3437 #endif |
355 | 3438 |
3439 #ifdef EXITFREE | |
3440 free_all_mem(); | |
3441 #endif | |
3442 | |
7 | 3443 exit(r); |
3444 } | |
3445 | |
3446 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3447 may_core_dump(void) |
7 | 3448 { |
3449 if (deadly_signal != 0) | |
3450 { | |
3451 signal(deadly_signal, SIG_DFL); | |
3452 kill(getpid(), deadly_signal); /* Die using the signal we caught */ | |
3453 } | |
3454 } | |
3455 | |
3456 #ifndef VMS | |
3457 | |
3458 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3459 mch_settmode(int tmode) |
7 | 3460 { |
3461 static int first = TRUE; | |
3462 | |
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
|
3463 #ifdef NEW_TTY_SYSTEM |
7 | 3464 # ifdef HAVE_TERMIOS_H |
3465 static struct termios told; | |
3466 struct termios tnew; | |
3467 # else | |
3468 static struct termio told; | |
3469 struct termio tnew; | |
3470 # endif | |
3471 | |
3472 if (first) | |
3473 { | |
3474 first = FALSE; | |
3475 # if defined(HAVE_TERMIOS_H) | |
3476 tcgetattr(read_cmd_fd, &told); | |
3477 # else | |
3478 ioctl(read_cmd_fd, TCGETA, &told); | |
3479 # endif | |
3480 } | |
3481 | |
3482 tnew = told; | |
3483 if (tmode == TMODE_RAW) | |
3484 { | |
3485 /* | |
3486 * ~ICRNL enables typing ^V^M | |
3487 */ | |
3488 tnew.c_iflag &= ~ICRNL; | |
3489 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE | |
3490 # if defined(IEXTEN) && !defined(__MINT__) | |
3491 | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ | |
3492 /* but it breaks function keys on MINT */ | |
3493 # endif | |
3494 ); | |
3495 # ifdef ONLCR /* don't map NL -> CR NL, we do it ourselves */ | |
3496 tnew.c_oflag &= ~ONLCR; | |
3497 # endif | |
3498 tnew.c_cc[VMIN] = 1; /* return after 1 char */ | |
3499 tnew.c_cc[VTIME] = 0; /* don't wait */ | |
3500 } | |
3501 else if (tmode == TMODE_SLEEP) | |
9381
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3502 { |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3503 /* 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
|
3504 * typeahead characters. */ |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3505 tnew.c_lflag &= ~(ICANON | ECHO); |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3506 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
|
3507 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
|
3508 } |
7 | 3509 |
3510 # if defined(HAVE_TERMIOS_H) | |
3511 { | |
3512 int n = 10; | |
3513 | |
3514 /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a | |
3515 * few times. */ | |
3516 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 | |
3517 && errno == EINTR && n > 0) | |
3518 --n; | |
3519 } | |
3520 # else | |
3521 ioctl(read_cmd_fd, TCSETA, &tnew); | |
3522 # endif | |
3523 | |
3524 #else | |
3525 /* | |
3526 * for "old" tty systems | |
3527 */ | |
3528 # ifndef TIOCSETN | |
3529 # define TIOCSETN TIOCSETP /* for hpux 9.0 */ | |
3530 # endif | |
3531 static struct sgttyb ttybold; | |
3532 struct sgttyb ttybnew; | |
3533 | |
3534 if (first) | |
3535 { | |
3536 first = FALSE; | |
3537 ioctl(read_cmd_fd, TIOCGETP, &ttybold); | |
3538 } | |
3539 | |
3540 ttybnew = ttybold; | |
3541 if (tmode == TMODE_RAW) | |
3542 { | |
3543 ttybnew.sg_flags &= ~(CRMOD | ECHO); | |
3544 ttybnew.sg_flags |= RAW; | |
3545 } | |
3546 else if (tmode == TMODE_SLEEP) | |
3547 ttybnew.sg_flags &= ~(ECHO); | |
3548 ioctl(read_cmd_fd, TIOCSETN, &ttybnew); | |
3549 #endif | |
3550 curr_tmode = tmode; | |
3551 } | |
3552 | |
3553 /* | |
3554 * Try to get the code for "t_kb" from the stty setting | |
3555 * | |
3556 * Even if termcap claims a backspace key, the user's setting *should* | |
3557 * prevail. stty knows more about reality than termcap does, and if | |
3558 * somebody's usual erase key is DEL (which, for most BSD users, it will | |
3559 * be), they're going to get really annoyed if their erase key starts | |
3560 * doing forward deletes for no reason. (Eric Fischer) | |
3561 */ | |
3562 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3563 get_stty(void) |
7 | 3564 { |
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
|
3565 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
|
3566 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
|
3567 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
|
3568 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3569 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
|
3570 { |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3571 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
|
3572 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
|
3573 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
|
3574 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
|
3575 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3576 /* 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
|
3577 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
|
3578 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
|
3579 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
|
3580 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3581 } |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3582 |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3583 /* |
3bf5fe164a9f
patch 8.0.0932: terminal may not use right characters for BS and Enter
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
3584 * 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
|
3585 * 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
|
3586 */ |
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 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
|
3588 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
|
3589 { |
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 #ifdef NEW_TTY_SYSTEM |
7 | 3591 # ifdef HAVE_TERMIOS_H |
3592 struct termios keys; | |
3593 # else | |
3594 struct termio keys; | |
3595 # endif | |
3596 | |
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
|
3597 if ( |
7 | 3598 # 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
|
3599 tcgetattr(fd, &keys) != -1 |
7 | 3600 # 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
|
3601 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
|
3602 # 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
|
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 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
|
3606 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
|
3607 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
|
3608 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
|
3609 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
|
3610 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
|
3611 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
|
3612 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
|
3613 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
|
3614 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
|
3615 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
|
3616 } |
7 | 3617 #else |
3618 /* for "old" tty systems */ | |
3619 struct sgttyb keys; | |
3620 | |
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 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
|
3622 { |
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 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
|
3624 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
|
3625 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
|
3626 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
|
3627 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
|
3628 } |
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 #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
|
3630 return FAIL; |
7 | 3631 } |
3632 | |
3633 #endif /* VMS */ | |
3634 | |
3635 #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
|
3636 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
|
3637 |
7 | 3638 /* |
3639 * Set mouse clicks on or off. | |
3640 */ | |
3641 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3642 mch_setmouse(int on) |
7 | 3643 { |
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
|
3644 # 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
|
3645 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
|
3646 # endif |
7 | 3647 int xterm_mouse_vers; |
3648 | |
14631
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3649 # 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
|
3650 if (!on) |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3651 // 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
|
3652 // 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
|
3653 stop_xterm_trace(); |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3654 # endif |
2c9a467c82fa
patch 8.1.0329: using inputlist() during startup results in garbage
Christian Brabandt <cb@256bit.org>
parents:
14597
diff
changeset
|
3655 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3656 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
|
3657 # 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
|
3658 && p_bevalterm == bevalterm_ison |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3659 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3660 ) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3661 /* return quickly if nothing to do */ |
7 | 3662 return; |
3663 | |
3664 xterm_mouse_vers = use_xterm_mouse(); | |
3145 | 3665 |
3666 # ifdef FEAT_MOUSE_URXVT | |
3746 | 3667 if (ttym_flags == TTYM_URXVT) |
3668 { | |
3145 | 3669 out_str_nf((char_u *) |
3670 (on | |
3671 ? IF_EB("\033[?1015h", ESC_STR "[?1015h") | |
3672 : 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
|
3673 mouse_ison = on; |
3145 | 3674 } |
3675 # endif | |
3676 | |
3746 | 3677 # ifdef FEAT_MOUSE_SGR |
3678 if (ttym_flags == TTYM_SGR) | |
3679 { | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3680 /* SGR mode supports columns above 223 */ |
3746 | 3681 out_str_nf((char_u *) |
3682 (on | |
3683 ? IF_EB("\033[?1006h", ESC_STR "[?1006h") | |
3684 : 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
|
3685 mouse_ison = on; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3686 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3687 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3688 |
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
|
3689 # 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
|
3690 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
|
3691 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3692 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
|
3693 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
|
3694 /* 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
|
3695 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
|
3696 (IF_EB("\033[?1003l", ESC_STR "[?1003l"))); |
3746 | 3697 } |
3698 # endif | |
3699 | |
7 | 3700 if (xterm_mouse_vers > 0) |
3701 { | |
3702 if (on) /* enable mouse events, use mouse tracking if available */ | |
3703 out_str_nf((char_u *) | |
3704 (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
|
3705 ? ( |
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
|
3706 # 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
|
3707 bevalterm_ison |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3708 ? 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
|
3709 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3710 IF_EB("\033[?1002h", ESC_STR "[?1002h")) |
7 | 3711 : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); |
3712 else /* disable mouse events, could probably always send the same */ | |
3713 out_str_nf((char_u *) | |
3714 (xterm_mouse_vers > 1 | |
3715 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") | |
3716 : 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
|
3717 mouse_ison = on; |
7 | 3718 } |
3719 | |
3720 # ifdef FEAT_MOUSE_DEC | |
3721 else if (ttym_flags == TTYM_DEC) | |
3722 { | |
3723 if (on) /* enable mouse events */ | |
3724 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); | |
3725 else /* disable mouse events */ | |
3726 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
|
3727 mouse_ison = on; |
7 | 3728 } |
3729 # endif | |
3730 | |
3731 # ifdef FEAT_MOUSE_GPM | |
3732 else | |
3733 { | |
3734 if (on) | |
3735 { | |
3736 if (gpm_open()) | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3737 mouse_ison = TRUE; |
7 | 3738 } |
3739 else | |
3740 { | |
3741 gpm_close(); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3742 mouse_ison = FALSE; |
7 | 3743 } |
3744 } | |
3745 # endif | |
3746 | |
1620 | 3747 # ifdef FEAT_SYSMOUSE |
3748 else | |
3749 { | |
3750 if (on) | |
3751 { | |
3752 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
|
3753 mouse_ison = TRUE; |
1620 | 3754 } |
3755 else | |
3756 { | |
3757 sysmouse_close(); | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3758 mouse_ison = FALSE; |
1620 | 3759 } |
3760 } | |
3761 # endif | |
3762 | |
7 | 3763 # ifdef FEAT_MOUSE_JSB |
3764 else | |
3765 { | |
3766 if (on) | |
3767 { | |
3768 /* D - Enable Mouse up/down messages | |
3769 * L - Enable Left Button Reporting | |
3770 * M - Enable Middle Button Reporting | |
3771 * R - Enable Right Button Reporting | |
3772 * K - Enable SHIFT and CTRL key Reporting | |
3773 * + - Enable Advanced messaging of mouse moves and up/down messages | |
3774 * Q - Quiet No Ack | |
3775 * # - Numeric value of mouse pointer required | |
3776 * 0 = Multiview 2000 cursor, used as standard | |
3777 * 1 = Windows Arrow | |
3778 * 2 = Windows I Beam | |
3779 * 3 = Windows Hour Glass | |
3780 * 4 = Windows Cross Hair | |
3781 * 5 = Windows UP Arrow | |
3782 */ | |
4299 | 3783 # ifdef JSBTERM_MOUSE_NONADVANCED |
3784 /* Disables full feedback of pointer movements */ | |
7 | 3785 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", |
3786 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); | |
4299 | 3787 # else |
7 | 3788 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\", |
3789 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\")); | |
4299 | 3790 # endif |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3791 mouse_ison = TRUE; |
7 | 3792 } |
3793 else | |
3794 { | |
3795 out_str_nf((char_u *)IF_EB("\033[0~ZwQ\033\\", | |
3796 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
|
3797 mouse_ison = FALSE; |
7 | 3798 } |
3799 } | |
3800 # endif | |
3801 # ifdef FEAT_MOUSE_PTERM | |
3802 else | |
3803 { | |
3804 /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ | |
3805 if (on) | |
3806 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); | |
3807 else | |
3808 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
|
3809 mouse_ison = on; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3810 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3811 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3812 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3813 |
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
|
3814 #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
|
3815 /* |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3816 * Called when 'balloonevalterm' changed. |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3817 */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3818 void |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3819 mch_bevalterm_changed(void) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3820 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3821 mch_setmouse(mouse_ison); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3822 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12847
diff
changeset
|
3823 #endif |
7 | 3824 |
3825 /* | |
3826 * Set the mouse termcode, depending on the 'term' and 'ttymouse' options. | |
3827 */ | |
3828 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3829 check_mouse_termcode(void) |
7 | 3830 { |
3831 # ifdef FEAT_MOUSE_XTERM | |
3832 if (use_xterm_mouse() | |
3145 | 3833 # ifdef FEAT_MOUSE_URXVT |
3834 && use_xterm_mouse() != 3 | |
3835 # endif | |
7 | 3836 # ifdef FEAT_GUI |
3837 && !gui.in_use | |
3838 # endif | |
3839 ) | |
3840 { | |
3841 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
180 | 3842 ? IF_EB("\233M", CSI_STR "M") |
3843 : IF_EB("\033[M", ESC_STR "[M"))); | |
7 | 3844 if (*p_mouse != NUL) |
3845 { | |
3846 /* force mouse off and maybe on to send possibly new mouse | |
3847 * activation sequence to the xterm, with(out) drag tracing. */ | |
3848 mch_setmouse(FALSE); | |
3849 setmouse(); | |
3850 } | |
3851 } | |
3852 else | |
3853 del_mouse_termcode(KS_MOUSE); | |
3854 # endif | |
3855 | |
3856 # ifdef FEAT_MOUSE_GPM | |
3857 if (!use_xterm_mouse() | |
3858 # ifdef FEAT_GUI | |
3859 && !gui.in_use | |
3860 # endif | |
3861 ) | |
3862 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MG", ESC_STR "MG")); | |
3863 # endif | |
3864 | |
1620 | 3865 # ifdef FEAT_SYSMOUSE |
3866 if (!use_xterm_mouse() | |
3867 # ifdef FEAT_GUI | |
3868 && !gui.in_use | |
3869 # endif | |
3870 ) | |
3871 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS")); | |
3872 # endif | |
3873 | |
7 | 3874 # ifdef FEAT_MOUSE_JSB |
6102 | 3875 /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ |
7 | 3876 if (!use_xterm_mouse() |
3877 # ifdef FEAT_GUI | |
3878 && !gui.in_use | |
3879 # endif | |
3880 ) | |
3881 set_mouse_termcode(KS_JSBTERM_MOUSE, | |
3882 (char_u *)IF_EB("\033[0~zw", ESC_STR "[0~zw")); | |
3883 else | |
3884 del_mouse_termcode(KS_JSBTERM_MOUSE); | |
3885 # endif | |
3886 | |
3887 # ifdef FEAT_MOUSE_NET | |
180 | 3888 /* There is no conflict, but one may type "ESC }" from Insert mode. Don't |
7 | 3889 * define it in the GUI or when using an xterm. */ |
3890 if (!use_xterm_mouse() | |
3891 # ifdef FEAT_GUI | |
3892 && !gui.in_use | |
3893 # endif | |
3894 ) | |
3895 set_mouse_termcode(KS_NETTERM_MOUSE, | |
3896 (char_u *)IF_EB("\033}", ESC_STR "}")); | |
3897 else | |
3898 del_mouse_termcode(KS_NETTERM_MOUSE); | |
3899 # endif | |
3900 | |
3901 # ifdef FEAT_MOUSE_DEC | |
6102 | 3902 /* Conflicts with xterm mouse: "\033[" and "\033[M" */ |
5932 | 3903 if (!use_xterm_mouse() |
7 | 3904 # ifdef FEAT_GUI |
3905 && !gui.in_use | |
3906 # endif | |
3907 ) | |
180 | 3908 set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME) |
3909 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); | |
7 | 3910 else |
3911 del_mouse_termcode(KS_DEC_MOUSE); | |
3912 # endif | |
3913 # ifdef FEAT_MOUSE_PTERM | |
6102 | 3914 /* same conflict as the dec mouse */ |
5932 | 3915 if (!use_xterm_mouse() |
7 | 3916 # ifdef FEAT_GUI |
3917 && !gui.in_use | |
3918 # endif | |
3919 ) | |
3920 set_mouse_termcode(KS_PTERM_MOUSE, | |
3921 (char_u *) IF_EB("\033[", ESC_STR "[")); | |
3922 else | |
3923 del_mouse_termcode(KS_PTERM_MOUSE); | |
3924 # endif | |
3145 | 3925 # ifdef FEAT_MOUSE_URXVT |
5932 | 3926 if (use_xterm_mouse() == 3 |
3145 | 3927 # ifdef FEAT_GUI |
3928 && !gui.in_use | |
3929 # endif | |
3930 ) | |
3931 { | |
3932 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
|
3933 ? 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
|
3934 : IF_EB("\033[*M", ESC_STR "[*M"))); |
3145 | 3935 |
3936 if (*p_mouse != NUL) | |
3937 { | |
3938 mch_setmouse(FALSE); | |
3939 setmouse(); | |
3940 } | |
3941 } | |
3942 else | |
3943 del_mouse_termcode(KS_URXVT_MOUSE); | |
3944 # endif | |
3746 | 3945 # ifdef FEAT_MOUSE_SGR |
3946 if (use_xterm_mouse() == 4 | |
3947 # ifdef FEAT_GUI | |
3948 && !gui.in_use | |
3949 # endif | |
3950 ) | |
3951 { | |
3952 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
|
3953 ? 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
|
3954 : 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
|
3955 |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3956 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
|
3957 ? 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
|
3958 : IF_EB("\033[<*m", ESC_STR "[<*m"))); |
3746 | 3959 |
3960 if (*p_mouse != NUL) | |
3961 { | |
3962 mch_setmouse(FALSE); | |
3963 setmouse(); | |
3964 } | |
3965 } | |
3966 else | |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3967 { |
3746 | 3968 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
|
3969 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
|
3970 } |
3746 | 3971 # endif |
7 | 3972 } |
3973 #endif | |
3974 | |
3975 /* | |
3976 * set screen mode, always fails. | |
3977 */ | |
3978 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3979 mch_screenmode(char_u *arg UNUSED) |
7 | 3980 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
3981 emsg(_(e_screenmode)); |
7 | 3982 return FAIL; |
3983 } | |
3984 | |
3985 #ifndef VMS | |
3986 | |
3987 /* | |
3988 * Try to get the current window size: | |
3989 * 1. with an ioctl(), most accurate method | |
3990 * 2. from the environment variables LINES and COLUMNS | |
3991 * 3. from the termcap | |
3992 * 4. keep using the old values | |
3993 * Return OK when size could be determined, FAIL otherwise. | |
3994 */ | |
3995 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3996 mch_get_shellsize(void) |
7 | 3997 { |
3998 long rows = 0; | |
3999 long columns = 0; | |
4000 char_u *p; | |
4001 | |
4002 /* | |
4003 * 1. try using an ioctl. It is the most accurate method. | |
4004 * | |
4005 * Try using TIOCGWINSZ first, some systems that have it also define | |
4006 * TIOCGSIZE but don't have a struct ttysize. | |
4007 */ | |
4008 # ifdef TIOCGWINSZ | |
4009 { | |
4010 struct winsize ws; | |
4011 int fd = 1; | |
4012 | |
4013 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
4014 if (!isatty(fd) && isatty(read_cmd_fd)) | |
4015 fd = read_cmd_fd; | |
4016 if (ioctl(fd, TIOCGWINSZ, &ws) == 0) | |
4017 { | |
4018 columns = ws.ws_col; | |
4019 rows = ws.ws_row; | |
4020 } | |
4021 } | |
4022 # else /* TIOCGWINSZ */ | |
4023 # ifdef TIOCGSIZE | |
4024 { | |
4025 struct ttysize ts; | |
4026 int fd = 1; | |
4027 | |
4028 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
4029 if (!isatty(fd) && isatty(read_cmd_fd)) | |
4030 fd = read_cmd_fd; | |
4031 if (ioctl(fd, TIOCGSIZE, &ts) == 0) | |
4032 { | |
4033 columns = ts.ts_cols; | |
4034 rows = ts.ts_lines; | |
4035 } | |
4036 } | |
4037 # endif /* TIOCGSIZE */ | |
4038 # endif /* TIOCGWINSZ */ | |
4039 | |
4040 /* | |
4041 * 2. get size from environment | |
164 | 4042 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules |
4043 * the ioctl() values! | |
7 | 4044 */ |
164 | 4045 if (columns == 0 || rows == 0 || vim_strchr(p_cpo, CPO_TSIZE) != NULL) |
7 | 4046 { |
4047 if ((p = (char_u *)getenv("LINES"))) | |
4048 rows = atoi((char *)p); | |
4049 if ((p = (char_u *)getenv("COLUMNS"))) | |
4050 columns = atoi((char *)p); | |
4051 } | |
4052 | |
4053 #ifdef HAVE_TGETENT | |
4054 /* | |
4055 * 3. try reading "co" and "li" entries from termcap | |
4056 */ | |
4057 if (columns == 0 || rows == 0) | |
4058 getlinecol(&columns, &rows); | |
4059 #endif | |
4060 | |
4061 /* | |
4062 * 4. If everything fails, use the old values | |
4063 */ | |
4064 if (columns <= 0 || rows <= 0) | |
4065 return FAIL; | |
4066 | |
4067 Rows = rows; | |
4068 Columns = columns; | |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
4069 limit_screen_size(); |
7 | 4070 return OK; |
4071 } | |
4072 | |
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
|
4073 #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
|
4074 /* |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4075 * 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
|
4076 */ |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4077 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
|
4078 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
|
4079 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4080 # 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
|
4081 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
|
4082 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4083 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
|
4084 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
|
4085 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
|
4086 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
|
4087 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
|
4088 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4089 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
|
4090 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
|
4091 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
4092 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
|
4093 # 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
|
4094 # 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
|
4095 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
|
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 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
|
4098 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
|
4099 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
|
4100 { |
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 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
|
4102 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
|
4103 } |
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 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
|
4105 # 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
|
4106 # 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
|
4107 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
|
4108 } |
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 #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
|
4110 |
7 | 4111 /* |
4112 * Try to set the window size to Rows and Columns. | |
4113 */ | |
4114 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4115 mch_set_shellsize(void) |
7 | 4116 { |
4117 if (*T_CWS) | |
4118 { | |
4119 /* | |
4120 * NOTE: if you get an error here that term_set_winsize() is | |
4121 * undefined, check the output of configure. It could probably not | |
4122 * find a ncurses, termcap or termlib library. | |
4123 */ | |
4124 term_set_winsize((int)Rows, (int)Columns); | |
4125 out_flush(); | |
4126 screen_start(); /* don't know where cursor is now */ | |
4127 } | |
4128 } | |
4129 | |
4130 #endif /* VMS */ | |
4131 | |
4132 /* | |
4133 * Rows and/or Columns has changed. | |
4134 */ | |
4135 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4136 mch_new_shellsize(void) |
7 | 4137 { |
4138 /* Nothing to do. */ | |
4139 } | |
4140 | |
3048 | 4141 /* |
4142 * Wait for process "child" to end. | |
4143 * Return "child" if it exited properly, <= 0 on error. | |
4144 */ | |
4145 static pid_t | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4146 wait4pid(pid_t child, waitstatus *status) |
3048 | 4147 { |
4148 pid_t wait_pid = 0; | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4149 long delay_msec = 1; |
3048 | 4150 |
4151 while (wait_pid != child) | |
4152 { | |
3470 | 4153 /* When compiled with Python threads are probably used, in which case |
4154 * wait() sometimes hangs for no obvious reason. Use waitpid() | |
4155 * instead and loop (like the GUI). Also needed for other interfaces, | |
4156 * they might call system(). */ | |
4157 # ifdef __NeXT__ | |
3048 | 4158 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); |
3470 | 4159 # else |
3048 | 4160 wait_pid = waitpid(child, status, WNOHANG); |
3470 | 4161 # endif |
3048 | 4162 if (wait_pid == 0) |
4163 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4164 /* 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
|
4165 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4166 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4167 delay_msec = 10; |
3048 | 4168 continue; |
4169 } | |
4170 if (wait_pid <= 0 | |
4171 # ifdef ECHILD | |
4172 && errno == ECHILD | |
4173 # endif | |
4174 ) | |
4175 break; | |
4176 } | |
4177 return wait_pid; | |
4178 } | |
4179 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4180 #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
|
4181 /* |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4182 * 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
|
4183 */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4184 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
|
4185 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
|
4186 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
|
4187 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
|
4188 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
|
4189 int is_terminal UNUSED) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4190 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4191 # ifdef HAVE_SETENV |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4192 char envbuf[50]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4193 # else |
11717
30247960c8a7
patch 8.0.0741: cannot build with HPUX
Christian Brabandt <cb@256bit.org>
parents:
11713
diff
changeset
|
4194 static char envbuf_Term[30]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4195 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
|
4196 static char envbuf_Lines[20]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4197 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
|
4198 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
|
4199 # 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
|
4200 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
|
4201 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4202 # 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
|
4203 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
|
4204 # 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
|
4205 # 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
|
4206 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
|
4207 # 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
|
4208 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
|
4209 # 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
|
4210 t_colors; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4211 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4212 # ifdef HAVE_SETENV |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4213 setenv("TERM", term, 1); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4214 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4215 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
|
4216 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4217 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
|
4218 sprintf((char *)envbuf, "%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4219 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
|
4220 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
|
4221 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
|
4222 # 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
|
4223 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
|
4224 { |
14073
a9b141cf99ff
patch 8.1.0054: compiler warning for using %ld for "long long"
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
4225 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
|
4226 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
|
4227 } |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
4228 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4229 # 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
|
4230 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
|
4231 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4232 # else |
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 * 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
|
4235 * 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
|
4236 * 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
|
4237 */ |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4238 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
|
4239 putenv(envbuf_Term); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4240 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
|
4241 putenv(envbuf_Rows); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4242 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
|
4243 putenv(envbuf_Lines); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4244 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
|
4245 "COLUMNS=%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4246 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
|
4247 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
|
4248 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
|
4249 # 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
|
4250 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
|
4251 { |
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
|
4252 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
|
4253 "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
|
4254 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
|
4255 } |
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
|
4256 # endif |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4257 # 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
|
4258 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
|
4259 "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
|
4260 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
|
4261 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4262 # endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4263 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4264 |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4265 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
|
4266 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
|
4267 { |
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
|
4268 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
|
4269 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4270 #endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4271 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4272 #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
|
4273 /* |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4274 * 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
|
4275 * 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
|
4276 * 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
|
4277 */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4278 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
|
4279 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
|
4280 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4281 char *tty_name; |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4282 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4283 *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
|
4284 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
|
4285 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4286 /* 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
|
4287 * 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
|
4288 * 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
|
4289 #ifdef O_NOCTTY |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4290 *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
|
4291 #else |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4292 *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
|
4293 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4294 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
|
4295 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4296 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
|
4297 *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
|
4298 } |
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
|
4299 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
|
4300 *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
|
4301 } |
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 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4304 |
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
|
4305 /* |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4306 * 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
|
4307 */ |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4308 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
|
4309 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
|
4310 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4311 # 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
|
4312 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
|
4313 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4314 # 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
|
4315 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
|
4316 # 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
|
4317 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
|
4318 # 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
|
4319 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
|
4320 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
|
4321 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4322 # 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
|
4323 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4324 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4325 #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
|
4326 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4327 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
|
4328 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
|
4329 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
|
4330 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
|
4331 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
|
4332 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
|
4333 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4334 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
|
4335 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
|
4336 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4337 *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
|
4338 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
|
4339 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
|
4340 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4341 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
|
4342 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
|
4343 *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
|
4344 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4345 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
|
4346 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4347 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
|
4348 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
|
4349 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4350 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
|
4351 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
|
4352 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4353 /* 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
|
4354 * 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
|
4355 *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
|
4356 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
|
4357 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
|
4358 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
|
4359 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
|
4360 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
|
4361 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4362 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
|
4363 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
|
4364 *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
|
4365 *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
|
4366 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
|
4367 } |
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 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
|
4370 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4371 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
|
4372 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
|
4373 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4374 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4375 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4376 #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
|
4377 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4378 * 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
|
4379 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4380 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
|
4381 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
|
4382 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
|
4383 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
|
4384 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4385 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
|
4386 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
|
4387 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
|
4388 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
|
4389 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
|
4390 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
|
4391 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
|
4392 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
|
4393 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
|
4394 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4395 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
|
4396 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
|
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 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
|
4399 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
|
4400 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
|
4401 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
|
4402 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
|
4403 |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14073
diff
changeset
|
4404 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
|
4405 ++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
|
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 /* 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
|
4408 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
|
4409 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4410 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
|
4411 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
|
4412 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4413 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
|
4414 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4415 /* 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
|
4416 * 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
|
4417 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
|
4418 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
|
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 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4421 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
|
4422 } |
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 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
|
4424 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
|
4425 |
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
|
4426 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
|
4427 |
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 /* 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
|
4429 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
|
4430 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4431 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
|
4432 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
|
4433 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4434 theend: |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4435 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
|
4436 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
|
4437 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
|
4438 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
|
4439 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4440 #endif |
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 #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
|
4443 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4444 * 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
|
4445 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4446 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
|
4447 mch_call_shell_system( |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4448 char_u *cmd, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4449 int options) /* SHELL_*, see vim.h */ |
7 | 4450 { |
4451 #ifdef VMS | |
4452 char *ifn = NULL; | |
4453 char *ofn = NULL; | |
4454 #endif | |
4455 int tmode = cur_tmode; | |
9552
49512aba8e32
commit https://github.com/vim/vim/commit/b2b050ab16565c117f0e7e411ffef3700d99203b
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
4456 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
|
4457 int x; |
7 | 4458 |
4459 out_flush(); | |
4460 | |
4461 if (options & SHELL_COOKED) | |
4462 settmode(TMODE_COOK); /* set to normal mode */ | |
4463 | |
2586 | 4464 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4209 | 4465 save_clipboard(); |
2586 | 4466 loose_clipboard(); |
4467 # endif | |
4468 | |
7 | 4469 if (cmd == NULL) |
4470 x = system((char *)p_sh); | |
4471 else | |
4472 { | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4473 # ifdef VMS |
7 | 4474 if (ofn = strchr((char *)cmd, '>')) |
4475 *ofn++ = '\0'; | |
4476 if (ifn = strchr((char *)cmd, '<')) | |
4477 { | |
4478 char *p; | |
4479 | |
4480 *ifn++ = '\0'; | |
4481 p = strchr(ifn,' '); /* chop off any trailing spaces */ | |
4482 if (p) | |
4483 *p = '\0'; | |
4484 } | |
4485 if (ofn) | |
4486 x = vms_sys((char *)cmd, ofn, ifn); | |
4487 else | |
4488 x = system((char *)cmd); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4489 # else |
7 | 4490 newcmd = lalloc(STRLEN(p_sh) |
4491 + (extra_shell_arg == NULL ? 0 : STRLEN(extra_shell_arg)) | |
4492 + STRLEN(p_shcf) + STRLEN(cmd) + 4, TRUE); | |
4493 if (newcmd == NULL) | |
4494 x = 0; | |
4495 else | |
4496 { | |
4497 sprintf((char *)newcmd, "%s %s %s %s", p_sh, | |
4498 extra_shell_arg == NULL ? "" : (char *)extra_shell_arg, | |
4499 (char *)p_shcf, | |
4500 (char *)cmd); | |
4501 x = system((char *)newcmd); | |
4502 vim_free(newcmd); | |
4503 } | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4504 # endif |
7 | 4505 } |
4506 # ifdef VMS | |
4507 x = vms_sys_status(x); | |
4508 # endif | |
4509 if (emsg_silent) | |
4510 ; | |
4511 else if (x == 127) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
4512 msg_puts(_("\nCannot execute shell sh\n")); |
7 | 4513 else if (x && !(options & SHELL_SILENT)) |
4514 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
4515 msg_puts(_("\nshell returned ")); |
7 | 4516 msg_outnum((long)x); |
4517 msg_putchar('\n'); | |
4518 } | |
4519 | |
4520 if (tmode == TMODE_RAW) | |
4521 settmode(TMODE_RAW); /* set to raw mode */ | |
4522 # ifdef FEAT_TITLE | |
4523 resettitle(); | |
4524 # endif | |
4209 | 4525 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4526 restore_clipboard(); | |
4527 # endif | |
7 | 4528 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
|
4529 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4530 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4531 #else /* USE_SYSTEM */ |
7 | 4532 |
167 | 4533 # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use |
4534 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
|
4535 # define OPEN_NULL_FAILED 123 /* Exit code if /dev/null can't be opened */ |
7 | 4536 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4537 /* |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4538 * 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
|
4539 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4540 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
|
4541 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
|
4542 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
|
4543 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
|
4544 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4545 int tmode = cur_tmode; |
7 | 4546 pid_t pid; |
167 | 4547 pid_t wpid = 0; |
7 | 4548 pid_t wait_pid = 0; |
4549 # ifdef HAVE_UNION_WAIT | |
4550 union wait status; | |
4551 # else | |
4552 int status = -1; | |
4553 # endif | |
4554 int retval = -1; | |
4555 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
|
4556 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
|
4557 char_u *tofree2 = NULL; |
7 | 4558 int i; |
167 | 4559 int pty_master_fd = -1; /* for pty's */ |
7 | 4560 # ifdef FEAT_GUI |
4561 int pty_slave_fd = -1; | |
167 | 4562 # endif |
602 | 4563 int fd_toshell[2]; /* for pipes */ |
7 | 4564 int fd_fromshell[2]; |
4565 int pipe_error = FALSE; | |
602 | 4566 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ |
7 | 4567 |
4568 out_flush(); | |
4569 if (options & SHELL_COOKED) | |
4570 settmode(TMODE_COOK); /* set to normal mode */ | |
4571 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
4572 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
|
4573 goto error; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4574 |
167 | 4575 /* |
4576 * For the GUI, when writing the output into the buffer and when reading | |
4577 * input from the buffer: Try using a pseudo-tty to get the stdin/stdout | |
4578 * of the executed command into the Vim window. Or use a pipe. | |
4579 */ | |
4580 if ((options & (SHELL_READ|SHELL_WRITE)) | |
7 | 4581 # ifdef FEAT_GUI |
167 | 4582 || (gui.in_use && show_shell_mess) |
4583 # endif | |
4584 ) | |
7 | 4585 { |
167 | 4586 # ifdef FEAT_GUI |
7 | 4587 /* |
4588 * Try to open a master pty. | |
4589 * If this works, open the slave pty. | |
4590 * If the slave can't be opened, close the master pty. | |
4591 */ | |
167 | 4592 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
|
4593 open_pty(&pty_master_fd, &pty_slave_fd, NULL); |
7 | 4594 /* |
4595 * If not opening a pty or it didn't work, try using pipes. | |
4596 */ | |
4597 if (pty_master_fd < 0) | |
167 | 4598 # endif |
7 | 4599 { |
4600 pipe_error = (pipe(fd_toshell) < 0); | |
4601 if (!pipe_error) /* pipe create OK */ | |
4602 { | |
4603 pipe_error = (pipe(fd_fromshell) < 0); | |
4604 if (pipe_error) /* pipe create failed */ | |
4605 { | |
4606 close(fd_toshell[0]); | |
4607 close(fd_toshell[1]); | |
4608 } | |
4609 } | |
4610 if (pipe_error) | |
4611 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
4612 msg_puts(_("\nCannot create pipes\n")); |
7 | 4613 out_flush(); |
4614 } | |
4615 } | |
4616 } | |
4617 | |
4618 if (!pipe_error) /* pty or pipe opened or not used */ | |
4619 { | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4620 SIGSET_DECL(curset) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4621 |
7 | 4622 # ifdef __BEOS__ |
4623 beos_cleanup_read_thread(); | |
4624 # endif | |
602 | 4625 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4626 BLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4627 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
|
4628 if (pid == -1) |
7 | 4629 { |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4630 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4631 |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
4632 msg_puts(_("\nCannot fork\n")); |
167 | 4633 if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4634 # ifdef FEAT_GUI |
167 | 4635 || (gui.in_use && show_shell_mess) |
4636 # endif | |
4637 ) | |
7 | 4638 { |
167 | 4639 # ifdef FEAT_GUI |
7 | 4640 if (pty_master_fd >= 0) /* close the pseudo tty */ |
4641 { | |
4642 close(pty_master_fd); | |
4643 close(pty_slave_fd); | |
4644 } | |
4645 else /* close the pipes */ | |
167 | 4646 # endif |
7 | 4647 { |
4648 close(fd_toshell[0]); | |
4649 close(fd_toshell[1]); | |
4650 close(fd_fromshell[0]); | |
4651 close(fd_fromshell[1]); | |
4652 } | |
4653 } | |
4654 } | |
4655 else if (pid == 0) /* child */ | |
4656 { | |
4657 reset_signals(); /* handle signals normally */ | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4658 UNBLOCK_SIGNALS(&curset); |
7 | 4659 |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4660 # 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
|
4661 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
|
4662 /* 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
|
4663 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
|
4664 # endif |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
4665 |
7 | 4666 if (!show_shell_mess || (options & SHELL_EXPAND)) |
4667 { | |
4668 int fd; | |
4669 | |
4670 /* | |
4671 * Don't want to show any message from the shell. Can't just | |
4672 * close stdout and stderr though, because some systems will | |
4673 * break if you try to write to them after that, so we must | |
4674 * use dup() to replace them with something else -- webb | |
4675 * Connect stdin to /dev/null too, so ":n `cat`" doesn't hang, | |
4676 * waiting for input. | |
4677 */ | |
4678 fd = open("/dev/null", O_RDWR | O_EXTRA, 0); | |
4679 fclose(stdin); | |
4680 fclose(stdout); | |
4681 fclose(stderr); | |
4682 | |
4683 /* | |
4684 * If any of these open()'s and dup()'s fail, we just continue | |
4685 * anyway. It's not fatal, and on most systems it will make | |
4686 * no difference at all. On a few it will cause the execvp() | |
4687 * to exit with a non-zero status even when the completion | |
4688 * could be done, which is nothing too serious. If the open() | |
4689 * or dup() failed we'd just do the same thing ourselves | |
4690 * anyway -- webb | |
4691 */ | |
4692 if (fd >= 0) | |
4693 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4694 vim_ignored = dup(fd); /* To replace stdin (fd 0) */ |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4695 vim_ignored = dup(fd); /* To replace stdout (fd 1) */ |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4696 vim_ignored = dup(fd); /* To replace stderr (fd 2) */ |
7 | 4697 |
4698 /* Don't need this now that we've duplicated it */ | |
4699 close(fd); | |
4700 } | |
4701 } | |
167 | 4702 else if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4703 # ifdef FEAT_GUI |
167 | 4704 || gui.in_use |
4705 # endif | |
4706 ) | |
7 | 4707 { |
4708 | |
167 | 4709 # ifdef HAVE_SETSID |
602 | 4710 /* Create our own process group, so that the child and all its |
4711 * children can be kill()ed. Don't do this when using pipes, | |
1698 | 4712 * because stdin is not a tty, we would lose /dev/tty. */ |
602 | 4713 if (p_stmp) |
1799 | 4714 { |
602 | 4715 (void)setsid(); |
1799 | 4716 # if defined(SIGHUP) |
4717 /* When doing "!xterm&" and 'shell' is bash: the shell | |
4718 * will exit and send SIGHUP to all processes in its | |
4719 * group, killing the just started process. Ignore SIGHUP | |
4720 * to avoid that. (suggested by Simon Schubert) | |
4721 */ | |
4722 signal(SIGHUP, SIG_IGN); | |
4723 # endif | |
4724 } | |
167 | 4725 # endif |
4726 # ifdef FEAT_GUI | |
602 | 4727 if (pty_slave_fd >= 0) |
4728 { | |
4729 /* push stream discipline modules */ | |
4730 if (options & SHELL_COOKED) | |
4731 SetupSlavePTY(pty_slave_fd); | |
7 | 4732 # ifdef TIOCSCTTY |
602 | 4733 /* Try to become controlling tty (probably doesn't work, |
4734 * unless run by root) */ | |
4735 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); | |
7 | 4736 # endif |
602 | 4737 } |
167 | 4738 # 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
|
4739 set_default_child_environment(FALSE); |
167 | 4740 |
557 | 4741 /* |
4742 * stderr is only redirected when using the GUI, so that a | |
4743 * program like gpg can still access the terminal to get a | |
4744 * passphrase using stderr. | |
4745 */ | |
167 | 4746 # ifdef FEAT_GUI |
7 | 4747 if (pty_master_fd >= 0) |
4748 { | |
4749 close(pty_master_fd); /* close master side of pty */ | |
4750 | |
4751 /* set up stdin/stdout/stderr for the child */ | |
4752 close(0); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4753 vim_ignored = dup(pty_slave_fd); |
7 | 4754 close(1); |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4755 vim_ignored = dup(pty_slave_fd); |
557 | 4756 if (gui.in_use) |
4757 { | |
4758 close(2); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4759 vim_ignored = dup(pty_slave_fd); |
557 | 4760 } |
7 | 4761 |
4762 close(pty_slave_fd); /* has been dupped, close it now */ | |
4763 } | |
4764 else | |
167 | 4765 # endif |
7 | 4766 { |
4767 /* set up stdin for the child */ | |
4768 close(fd_toshell[1]); | |
4769 close(0); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4770 vim_ignored = dup(fd_toshell[0]); |
7 | 4771 close(fd_toshell[0]); |
4772 | |
4773 /* set up stdout for the child */ | |
4774 close(fd_fromshell[0]); | |
4775 close(1); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4776 vim_ignored = dup(fd_fromshell[1]); |
7 | 4777 close(fd_fromshell[1]); |
4778 | |
557 | 4779 # ifdef FEAT_GUI |
4780 if (gui.in_use) | |
4781 { | |
4782 /* set up stderr for the child */ | |
4783 close(2); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4784 vim_ignored = dup(1); |
557 | 4785 } |
4786 # endif | |
7 | 4787 } |
4788 } | |
167 | 4789 |
7 | 4790 /* |
4791 * There is no type cast for the argv, because the type may be | |
4792 * different on different machines. This may cause a warning | |
4793 * message with strict compilers, don't worry about it. | |
4794 * Call _exit() instead of exit() to avoid closing the connection | |
4795 * to the X server (esp. with GTK, which uses atexit()). | |
4796 */ | |
4797 execvp(argv[0], argv); | |
4798 _exit(EXEC_FAILED); /* exec failed, return failure code */ | |
4799 } | |
4800 else /* parent */ | |
4801 { | |
4802 /* | |
4803 * While child is running, ignore terminating signals. | |
167 | 4804 * Do catch CTRL-C, so that "got_int" is set. |
7 | 4805 */ |
4806 catch_signals(SIG_IGN, SIG_ERR); | |
167 | 4807 catch_int_signal(); |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4808 UNBLOCK_SIGNALS(&curset); |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4809 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4810 ++dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4811 # endif |
7 | 4812 /* |
4813 * For the GUI we redirect stdin, stdout and stderr to our window. | |
167 | 4814 * This is also used to pipe stdin/stdout to/from the external |
4815 * command. | |
7 | 4816 */ |
167 | 4817 if ((options & (SHELL_READ|SHELL_WRITE)) |
4818 # ifdef FEAT_GUI | |
4819 || (gui.in_use && show_shell_mess) | |
4820 # endif | |
4821 ) | |
7 | 4822 { |
167 | 4823 # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ |
7 | 4824 char_u buffer[BUFLEN + 1]; |
167 | 4825 # ifdef FEAT_MBYTE |
7 | 4826 int buffer_off = 0; /* valid bytes in buffer[] */ |
167 | 4827 # endif |
7 | 4828 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ |
4829 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4830 int len; | |
4831 int p_more_save; | |
4832 int old_State; | |
4833 int c; | |
4834 int toshell_fd; | |
4835 int fromshell_fd; | |
167 | 4836 garray_T ga; |
4837 int noread_cnt; | |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4838 # ifdef ELAPSED_FUNC |
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4839 elapsed_T start_tv; |
1823 | 4840 # endif |
167 | 4841 |
4842 # ifdef FEAT_GUI | |
7 | 4843 if (pty_master_fd >= 0) |
4844 { | |
4845 fromshell_fd = pty_master_fd; | |
4846 toshell_fd = dup(pty_master_fd); | |
4847 } | |
4848 else | |
167 | 4849 # endif |
7 | 4850 { |
4851 close(fd_toshell[0]); | |
4852 close(fd_fromshell[1]); | |
4853 toshell_fd = fd_toshell[1]; | |
4854 fromshell_fd = fd_fromshell[0]; | |
4855 } | |
4856 | |
4857 /* | |
4858 * Write to the child if there are typed characters. | |
4859 * Read from the child if there are characters available. | |
4860 * Repeat the reading a few times if more characters are | |
4861 * available. Need to check for typed keys now and then, but | |
4862 * not too often (delays when no chars are available). | |
4863 * This loop is quit if no characters can be read from the pty | |
4864 * (WaitForChar detected special condition), or there are no | |
4865 * characters available and the child has exited. | |
4866 * Only check if the child has exited when there is no more | |
4867 * output. The child may exit before all the output has | |
4868 * been printed. | |
4869 * | |
4870 * Currently this busy loops! | |
4871 * This can probably dead-lock when the write blocks! | |
4872 */ | |
4873 p_more_save = p_more; | |
4874 p_more = FALSE; | |
4875 old_State = State; | |
4876 State = EXTERNCMD; /* don't redraw at window resize */ | |
4877 | |
602 | 4878 if ((options & SHELL_WRITE) && toshell_fd >= 0) |
167 | 4879 { |
4880 /* Fork a process that will write the lines to the | |
4881 * external program. */ | |
4882 if ((wpid = fork()) == -1) | |
4883 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
4884 msg_puts(_("\nCannot fork\n")); |
167 | 4885 } |
3048 | 4886 else if (wpid == 0) /* child */ |
167 | 4887 { |
4888 linenr_T lnum = curbuf->b_op_start.lnum; | |
4889 int written = 0; | |
944 | 4890 char_u *lp = ml_get(lnum); |
167 | 4891 size_t l; |
4892 | |
177 | 4893 close(fromshell_fd); |
167 | 4894 for (;;) |
4895 { | |
944 | 4896 l = STRLEN(lp + written); |
167 | 4897 if (l == 0) |
4898 len = 0; | |
944 | 4899 else if (lp[written] == NL) |
167 | 4900 /* NL -> NUL translation */ |
4901 len = write(toshell_fd, "", (size_t)1); | |
4902 else | |
4903 { | |
3263 | 4904 char_u *s = vim_strchr(lp + written, NL); |
4905 | |
944 | 4906 len = write(toshell_fd, (char *)lp + written, |
1877 | 4907 s == NULL ? l |
4908 : (size_t)(s - (lp + written))); | |
167 | 4909 } |
1877 | 4910 if (len == (int)l) |
167 | 4911 { |
4912 /* Finished a line, add a NL, unless this line | |
4913 * should not have one. */ | |
4914 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4915 || (!curbuf->b_p_bin |
4916 && curbuf->b_p_fixeol) | |
2707 | 4917 || (lnum != curbuf->b_no_eol_lnum |
167 | 4918 && (lnum != |
4919 curbuf->b_ml.ml_line_count | |
4920 || curbuf->b_p_eol))) | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
4921 vim_ignored = write(toshell_fd, "\n", |
1757 | 4922 (size_t)1); |
167 | 4923 ++lnum; |
4924 if (lnum > curbuf->b_op_end.lnum) | |
4925 { | |
4926 /* finished all the lines, close pipe */ | |
4927 close(toshell_fd); | |
4928 toshell_fd = -1; | |
4929 break; | |
4930 } | |
944 | 4931 lp = ml_get(lnum); |
167 | 4932 written = 0; |
4933 } | |
4934 else if (len > 0) | |
4935 written += len; | |
4936 } | |
4937 _exit(0); | |
4938 } | |
3048 | 4939 else /* parent */ |
167 | 4940 { |
4941 close(toshell_fd); | |
4942 toshell_fd = -1; | |
4943 } | |
4944 } | |
4945 | |
4946 if (options & SHELL_READ) | |
4947 ga_init2(&ga, 1, BUFLEN); | |
4948 | |
4949 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4950 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4951 ELAPSED_INIT(start_tv); |
1823 | 4952 # endif |
7 | 4953 for (;;) |
4954 { | |
4955 /* | |
4956 * Check if keys have been typed, write them to the child | |
592 | 4957 * if there are any. |
4958 * Don't do this if we are expanding wild cards (would eat | |
4959 * typeahead). | |
4960 * Don't do this when filtering and terminal is in cooked | |
4961 * mode, the shell command will handle the I/O. Avoids | |
4962 * that a typed password is echoed for ssh or gpg command. | |
602 | 4963 * Don't get characters when the child has already |
4964 * finished (wait_pid == 0). | |
167 | 4965 * Don't read characters unless we didn't get output for a |
1823 | 4966 * while (noread_cnt > 4), avoids that ":r !ls" eats |
4967 * typeahead. | |
7 | 4968 */ |
4969 len = 0; | |
4970 if (!(options & SHELL_EXPAND) | |
592 | 4971 && ((options & |
4972 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4973 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
1823 | 4974 # ifdef FEAT_GUI |
592 | 4975 || gui.in_use |
1823 | 4976 # endif |
592 | 4977 ) |
602 | 4978 && wait_pid == 0 |
1823 | 4979 && (ta_len > 0 || noread_cnt > 4)) |
7 | 4980 { |
1823 | 4981 if (ta_len == 0) |
4982 { | |
4983 /* Get extra characters when we don't have any. | |
4984 * Reset the counter and timer. */ | |
4985 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4986 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4987 ELAPSED_INIT(start_tv); |
1823 | 4988 # endif |
4989 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4990 } | |
4991 if (ta_len > 0 || len > 0) | |
4992 { | |
7 | 4993 /* |
4994 * For pipes: | |
4995 * Check for CTRL-C: send interrupt signal to child. | |
4996 * Check for CTRL-D: EOF, close pipe to child. | |
4997 */ | |
4998 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) | |
4999 { | |
5000 /* | |
5001 * Send SIGINT to the child's group or all | |
5002 * processes in our group. | |
5003 */ | |
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
|
5004 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
|
5005 |
7 | 5006 if (pty_master_fd < 0 && toshell_fd >= 0 |
5007 && ta_buf[ta_len] == Ctrl_D) | |
5008 { | |
5009 close(toshell_fd); | |
5010 toshell_fd = -1; | |
5011 } | |
5012 } | |
5013 | |
5014 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
5015 for (i = ta_len; i < ta_len + len; ++i) | |
5016 { | |
5017 if (ta_buf[i] == CSI && len - i > 2) | |
5018 { | |
5019 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
5020 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
5021 { | |
5022 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
5023 (size_t)(len - i - 2)); | |
5024 if (c == K_DEL || c == K_KDEL) | |
5025 ta_buf[i] = DEL; | |
5026 else | |
5027 ta_buf[i] = Ctrl_H; | |
5028 len -= 2; | |
5029 } | |
5030 } | |
5031 else if (ta_buf[i] == '\r') | |
5032 ta_buf[i] = '\n'; | |
167 | 5033 # ifdef FEAT_MBYTE |
7 | 5034 if (has_mbyte) |
1903 | 5035 i += (*mb_ptr2len_len)(ta_buf + i, |
5036 ta_len + len - i) - 1; | |
167 | 5037 # endif |
7 | 5038 } |
5039 | |
5040 /* | |
5041 * For pipes: echo the typed characters. | |
5042 * For a pty this does not seem to work. | |
5043 */ | |
5044 if (pty_master_fd < 0) | |
5045 { | |
5046 for (i = ta_len; i < ta_len + len; ++i) | |
5047 { | |
5048 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
5049 msg_putchar(ta_buf[i]); | |
167 | 5050 # ifdef FEAT_MBYTE |
7 | 5051 else if (has_mbyte) |
5052 { | |
474 | 5053 int l = (*mb_ptr2len)(ta_buf + i); |
7 | 5054 |
5055 msg_outtrans_len(ta_buf + i, l); | |
5056 i += l - 1; | |
5057 } | |
167 | 5058 # endif |
7 | 5059 else |
5060 msg_outtrans_len(ta_buf + i, 1); | |
5061 } | |
5062 windgoto(msg_row, msg_col); | |
5063 out_flush(); | |
5064 } | |
5065 | |
5066 ta_len += len; | |
5067 | |
5068 /* | |
5069 * Write the characters to the child, unless EOF has | |
5070 * been typed for pipes. Write one character at a | |
1698 | 5071 * time, to avoid losing too much typeahead. |
167 | 5072 * When writing buffer lines, drop the typed |
5073 * characters (only check for CTRL-C). | |
7 | 5074 */ |
167 | 5075 if (options & SHELL_WRITE) |
5076 ta_len = 0; | |
5077 else if (toshell_fd >= 0) | |
7 | 5078 { |
5079 len = write(toshell_fd, (char *)ta_buf, (size_t)1); | |
5080 if (len > 0) | |
5081 { | |
5082 ta_len -= len; | |
5083 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
5084 } | |
5085 } | |
1823 | 5086 } |
7 | 5087 } |
5088 | |
167 | 5089 if (got_int) |
5090 { | |
5091 /* CTRL-C sends a signal to the child, we ignore it | |
5092 * ourselves */ | |
5093 # ifdef HAVE_SETSID | |
5094 kill(-pid, SIGINT); | |
5095 # else | |
5096 kill(0, SIGINT); | |
5097 # endif | |
5098 if (wpid > 0) | |
5099 kill(wpid, SIGINT); | |
5100 got_int = FALSE; | |
5101 } | |
5102 | |
7 | 5103 /* |
5104 * Check if the child has any characters to be printed. | |
5105 * Read them and write them to our window. Repeat this as | |
5106 * long as there is something to do, avoid the 10ms wait | |
5107 * for mch_inchar(), or sending typeahead characters to | |
5108 * the external process. | |
5109 * TODO: This should handle escape sequences, compatible | |
5110 * to some terminal (vt52?). | |
5111 */ | |
167 | 5112 ++noread_cnt; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5113 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL)) |
7 | 5114 { |
2664 | 5115 len = read_eintr(fromshell_fd, buffer |
167 | 5116 # ifdef FEAT_MBYTE |
7 | 5117 + buffer_off, (size_t)(BUFLEN - buffer_off) |
167 | 5118 # else |
7 | 5119 , (size_t)BUFLEN |
167 | 5120 # endif |
7 | 5121 ); |
5122 if (len <= 0) /* end of file or error */ | |
5123 goto finished; | |
167 | 5124 |
5125 noread_cnt = 0; | |
5126 if (options & SHELL_READ) | |
5127 { | |
5128 /* Do NUL -> NL translation, append NL separated | |
5129 * lines to the current buffer. */ | |
5130 for (i = 0; i < len; ++i) | |
5131 { | |
5132 if (buffer[i] == NL) | |
5133 append_ga_line(&ga); | |
5134 else if (buffer[i] == NUL) | |
5135 ga_append(&ga, NL); | |
5136 else | |
5137 ga_append(&ga, buffer[i]); | |
5138 } | |
5139 } | |
5140 # ifdef FEAT_MBYTE | |
5141 else if (has_mbyte) | |
7 | 5142 { |
5143 int l; | |
13478
601d797cca88
patch 8.0.1613: warning for unused variable in tiny build
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
5144 char_u *p; |
7 | 5145 |
167 | 5146 len += buffer_off; |
5147 buffer[len] = NUL; | |
5148 | |
7 | 5149 /* Check if the last character in buffer[] is |
5150 * incomplete, keep these bytes for the next | |
5151 * round. */ | |
5152 for (p = buffer; p < buffer + len; p += l) | |
5153 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9873
diff
changeset
|
5154 l = MB_CPTR2LEN(p); |
7 | 5155 if (l == 0) |
5156 l = 1; /* NUL byte? */ | |
5157 else if (MB_BYTE2LEN(*p) != l) | |
5158 break; | |
5159 } | |
5160 if (p == buffer) /* no complete character */ | |
5161 { | |
5162 /* avoid getting stuck at an illegal byte */ | |
5163 if (len >= 12) | |
5164 ++p; | |
5165 else | |
5166 { | |
5167 buffer_off = len; | |
5168 continue; | |
5169 } | |
5170 } | |
5171 c = *p; | |
5172 *p = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
5173 msg_puts((char *)buffer); |
7 | 5174 if (p < buffer + len) |
5175 { | |
5176 *p = c; | |
5177 buffer_off = (buffer + len) - p; | |
5178 mch_memmove(buffer, p, buffer_off); | |
5179 continue; | |
5180 } | |
5181 buffer_off = 0; | |
5182 } | |
167 | 5183 # endif /* FEAT_MBYTE */ |
7 | 5184 else |
5185 { | |
5186 buffer[len] = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
5187 msg_puts((char *)buffer); |
7 | 5188 } |
5189 | |
5190 windgoto(msg_row, msg_col); | |
5191 cursor_on(); | |
5192 out_flush(); | |
5193 if (got_int) | |
5194 break; | |
1823 | 5195 |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5196 # ifdef ELAPSED_FUNC |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5197 if (wait_pid == 0) |
1823 | 5198 { |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5199 long msec = ELAPSED_FUNC(start_tv); |
1823 | 5200 |
5201 /* Avoid that we keep looping here without | |
5202 * checking for a CTRL-C for a long time. Don't | |
5203 * break out too often to avoid losing typeahead. */ | |
5204 if (msec > 2000) | |
5205 { | |
5206 noread_cnt = 5; | |
5207 break; | |
5208 } | |
5209 } | |
5210 # endif | |
7 | 5211 } |
5212 | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5213 /* 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
|
5214 * 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
|
5215 * buffered. */ |
602 | 5216 if (wait_pid == pid) |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5217 { |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5218 if (noread_cnt < 5) |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5219 continue; |
602 | 5220 break; |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5221 } |
602 | 5222 |
7 | 5223 /* |
5224 * Check if the child still exists, before checking for | |
1698 | 5225 * typed characters (otherwise we would lose typeahead). |
7 | 5226 */ |
167 | 5227 # ifdef __NeXT__ |
3048 | 5228 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); |
167 | 5229 # else |
7 | 5230 wait_pid = waitpid(pid, &status, WNOHANG); |
167 | 5231 # endif |
7 | 5232 if ((wait_pid == (pid_t)-1 && errno == ECHILD) |
5233 || (wait_pid == pid && WIFEXITED(status))) | |
5234 { | |
602 | 5235 /* Don't break the loop yet, try reading more |
5236 * characters from "fromshell_fd" first. When using | |
5237 * pipes there might still be something to read and | |
5238 * then we'll break the loop at the "break" above. */ | |
7 | 5239 wait_pid = pid; |
5240 } | |
602 | 5241 else |
5242 wait_pid = 0; | |
4230 | 5243 |
4248 | 5244 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5245 /* Handle any X events, e.g. serving the clipboard. */ |
5246 clip_update(); | |
5247 # endif | |
7 | 5248 } |
5249 finished: | |
5250 p_more = p_more_save; | |
167 | 5251 if (options & SHELL_READ) |
5252 { | |
5253 if (ga.ga_len > 0) | |
5254 { | |
5255 append_ga_line(&ga); | |
5256 /* remember that the NL was missing */ | |
2707 | 5257 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
167 | 5258 } |
5259 else | |
2707 | 5260 curbuf->b_no_eol_lnum = 0; |
167 | 5261 ga_clear(&ga); |
5262 } | |
5263 | |
7 | 5264 /* |
5265 * Give all typeahead that wasn't used back to ui_inchar(). | |
5266 */ | |
5267 if (ta_len) | |
5268 ui_inchar_undo(ta_buf, ta_len); | |
5269 State = old_State; | |
5270 if (toshell_fd >= 0) | |
5271 close(toshell_fd); | |
5272 close(fromshell_fd); | |
5273 } | |
4248 | 5274 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5275 else |
5276 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5277 long delay_msec = 1; |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5278 |
4230 | 5279 /* |
5280 * Similar to the loop above, but only handle X events, no | |
5281 * I/O. | |
5282 */ | |
5283 for (;;) | |
5284 { | |
5285 if (got_int) | |
5286 { | |
5287 /* CTRL-C sends a signal to the child, we ignore it | |
5288 * ourselves */ | |
5289 # ifdef HAVE_SETSID | |
5290 kill(-pid, SIGINT); | |
5291 # else | |
5292 kill(0, SIGINT); | |
5293 # endif | |
5294 got_int = FALSE; | |
5295 } | |
5296 # ifdef __NeXT__ | |
5297 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); | |
5298 # else | |
5299 wait_pid = waitpid(pid, &status, WNOHANG); | |
5300 # endif | |
5301 if ((wait_pid == (pid_t)-1 && errno == ECHILD) | |
5302 || (wait_pid == pid && WIFEXITED(status))) | |
5303 { | |
5304 wait_pid = pid; | |
5305 break; | |
5306 } | |
5307 | |
5308 /* Handle any X events, e.g. serving the clipboard. */ | |
5309 clip_update(); | |
5310 | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5311 /* 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
|
5312 * less time. */ |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5313 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5314 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5315 delay_msec = 10; |
4230 | 5316 } |
5317 } | |
5318 # endif | |
7 | 5319 |
5320 /* | |
5321 * Wait until our child has exited. | |
5322 * Ignore wait() returning pids of other children and returning | |
5323 * because of some signal like SIGWINCH. | |
5324 * Don't wait if wait_pid was already set above, indicating the | |
5325 * child already exited. | |
5326 */ | |
3048 | 5327 if (wait_pid != pid) |
5328 wait_pid = wait4pid(pid, &status); | |
7 | 5329 |
2600 | 5330 # ifdef FEAT_GUI |
5331 /* Close slave side of pty. Only do this after the child has | |
5332 * exited, otherwise the child may hang when it tries to write on | |
5333 * the pty. */ | |
5334 if (pty_master_fd >= 0) | |
5335 close(pty_slave_fd); | |
5336 # endif | |
5337 | |
167 | 5338 /* Make sure the child that writes to the external program is |
5339 * dead. */ | |
5340 if (wpid > 0) | |
3048 | 5341 { |
167 | 5342 kill(wpid, SIGKILL); |
3048 | 5343 wait4pid(wpid, NULL); |
5344 } | |
167 | 5345 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5346 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5347 --dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5348 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5349 |
7 | 5350 /* |
5351 * Set to raw mode right now, otherwise a CTRL-C after | |
5352 * catch_signals() will kill Vim. | |
5353 */ | |
5354 if (tmode == TMODE_RAW) | |
5355 settmode(TMODE_RAW); | |
5356 did_settmode = TRUE; | |
5357 set_signals(); | |
5358 | |
5359 if (WIFEXITED(status)) | |
5360 { | |
129 | 5361 /* LINTED avoid "bitwise operation on signed value" */ |
7 | 5362 retval = WEXITSTATUS(status); |
4074 | 5363 if (retval != 0 && !emsg_silent) |
7 | 5364 { |
5365 if (retval == EXEC_FAILED) | |
5366 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
5367 msg_puts(_("\nCannot execute shell ")); |
7 | 5368 msg_outtrans(p_sh); |
5369 msg_putchar('\n'); | |
5370 } | |
5371 else if (!(options & SHELL_SILENT)) | |
5372 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
5373 msg_puts(_("\nshell returned ")); |
7 | 5374 msg_outnum((long)retval); |
5375 msg_putchar('\n'); | |
5376 } | |
5377 } | |
5378 } | |
5379 else | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
5380 msg_puts(_("\nCommand terminated\n")); |
7 | 5381 } |
5382 } | |
5383 | |
5384 error: | |
5385 if (!did_settmode) | |
5386 if (tmode == TMODE_RAW) | |
5387 settmode(TMODE_RAW); /* set to raw mode */ | |
5388 # ifdef FEAT_TITLE | |
5389 resettitle(); | |
5390 # 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
|
5391 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
|
5392 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
|
5393 vim_free(tofree2); |
7 | 5394 |
5395 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
|
5396 } |
7 | 5397 #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
|
5398 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5399 int |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5400 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
|
5401 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
|
5402 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
|
5403 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5404 #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
|
5405 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
|
5406 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
|
5407 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5408 #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
|
5409 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
|
5410 #else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13396
diff
changeset
|
5411 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
|
5412 #endif |
7 | 5413 } |
5414 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5415 #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
|
5416 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
|
5417 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
|
5418 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5419 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
|
5420 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
|
5421 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
|
5422 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
|
5423 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
|
5424 int pty_slave_fd = -1; |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
5425 channel_T *channel = NULL; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5426 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
|
5427 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
|
5428 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
|
5429 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
|
5430 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
|
5431 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
|
5432 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
|
5433 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
|
5434 SIGSET_DECL(curset) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5435 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5436 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
|
5437 use_null_for_err = TRUE; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5438 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5439 /* default is to fail */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5440 job->jv_status = JOB_FAILED; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5441 |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5442 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
|
5443 && (!(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
|
5444 || !(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
|
5445 || !(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
|
5446 { |
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5447 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
|
5448 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
|
5449 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
|
5450 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5451 |
8068
9c6740f2204f
commit https://github.com/vim/vim/commit/12dcf024e90ab511f04a08b20fe7eedbe92096d2
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5452 /* 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
|
5453 /* 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
|
5454 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5455 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5456 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
|
5457 |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5458 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
|
5459 if (fd_in[0] < 0) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5460 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
5461 semsg(_(e_notopen), fname); |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5462 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5463 } |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5464 } |
12192
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5465 else |
6947d5bcf57f
patch 8.0.0976: cannot send lines to a terminal job
Christian Brabandt <cb@256bit.org>
parents:
12104
diff
changeset
|
5466 /* 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
|
5467 * 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
|
5468 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
|
5469 && 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
|
5470 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5471 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5472 if (use_file_for_out) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5473 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5474 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
|
5475 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5476 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
|
5477 if (fd_out[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5478 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
5479 semsg(_(e_notopen), fname); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5480 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5481 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5482 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5483 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
|
5484 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5485 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5486 if (use_file_for_err) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5487 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5488 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
|
5489 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5490 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
|
5491 if (fd_err[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5492 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
5493 semsg(_(e_notopen), fname); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5494 goto failed; |
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 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5497 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
|
5498 && 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
|
5499 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5500 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5501 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
|
5502 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5503 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5504 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5505 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5506 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5507 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5508 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5509 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5510 channel = add_channel(); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5511 if (channel == NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5512 goto failed; |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5513 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
|
5514 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
|
5515 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
|
5516 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5517 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5518 BLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5519 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
|
5520 if (pid == -1) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5521 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5522 /* failed to fork */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5523 UNBLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5524 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5525 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5526 if (pid == 0) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5527 { |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5528 int null_fd = -1; |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5529 int stderr_works = TRUE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5530 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5531 /* child */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5532 reset_signals(); /* handle signals normally */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5533 UNBLOCK_SIGNALS(&curset); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5534 |
13357
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5535 # 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
|
5536 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
|
5537 /* 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
|
5538 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
|
5539 # endif |
179586a64f53
patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents:
13355
diff
changeset
|
5540 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5541 # ifdef HAVE_SETSID |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5542 /* 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
|
5543 * 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
|
5544 * 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
|
5545 (void)setsid(); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5546 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5547 |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5548 # ifdef FEAT_TERMINAL |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5549 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
|
5550 { |
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
|
5551 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
|
5552 |
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
|
5553 #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
|
5554 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
|
5555 /* 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
|
5556 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
|
5557 #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
|
5558 /* 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
|
5559 * 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
|
5560 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
|
5561 term = "xterm"; |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5562 set_child_environment( |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5563 (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
|
5564 (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
|
5565 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
|
5566 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
|
5567 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5568 else |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5569 # 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
|
5570 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
|
5571 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5572 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
|
5573 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5574 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
|
5575 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
|
5576 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
|
5577 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5578 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
|
5579 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
|
5580 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5581 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
|
5582 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
5583 vim_setenv((char_u*)hi->hi_key, tv_get_string(item)); |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5584 --todo; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5585 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5586 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5587 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5588 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
|
5589 { |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5590 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
|
5591 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
|
5592 { |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5593 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
|
5594 _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
|
5595 } |
52eea5b73b2a
patch 8.0.0980: Coverity warning for failing to open /dev/null
Christian Brabandt <cb@256bit.org>
parents:
12192
diff
changeset
|
5596 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5597 |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5598 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
|
5599 { |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5600 /* push stream discipline modules */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5601 SetupSlavePTY(pty_slave_fd); |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5602 # ifdef TIOCSCTTY |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5603 /* 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
|
5604 * unless run by root) */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5605 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
|
5606 # endif |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5607 } |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5608 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5609 /* set up 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
|
5610 close(0); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5611 if (use_null_for_in && null_fd >= 0) |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5612 vim_ignored = dup(null_fd); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5613 else if (fd_in[0] < 0) |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5614 vim_ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5615 else |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5616 vim_ignored = dup(fd_in[0]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5617 |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5618 /* 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
|
5619 close(2); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5620 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
|
5621 { |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5622 vim_ignored = dup(null_fd); |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5623 stderr_works = FALSE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5624 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5625 else if (use_out_for_err) |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5626 vim_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
|
5627 else if (fd_err[1] < 0) |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5628 vim_ignored = dup(pty_slave_fd); |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5629 else |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5630 vim_ignored = dup(fd_err[1]); |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5631 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5632 /* 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
|
5633 close(1); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5634 if (use_null_for_out && null_fd >= 0) |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5635 vim_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
|
5636 else if (fd_out[1] < 0) |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5637 vim_ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5638 else |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14718
diff
changeset
|
5639 vim_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
|
5640 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5641 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
|
5642 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
|
5643 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
|
5644 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
|
5645 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
|
5646 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
|
5647 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
|
5648 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
|
5649 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
|
5650 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
|
5651 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
|
5652 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
|
5653 if (pty_master_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5654 { |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5655 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
|
5656 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
|
5657 } |
9074
3aab62b76363
commit https://github.com/vim/vim/commit/ea83bf06b92baeb6d68a10d8e8ffad289d31dae2
Christian Brabandt <cb@256bit.org>
parents:
9009
diff
changeset
|
5658 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5659 if (null_fd >= 0) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5660 close(null_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5661 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5662 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
|
5663 _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
|
5664 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5665 /* See above for type of argv. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5666 execvp(argv[0], argv); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5667 |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5668 if (stderr_works) |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5669 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
|
5670 # ifdef EXITFREE |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5671 /* 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
|
5672 * 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
|
5673 # endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5674 _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
|
5675 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5676 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5677 /* parent */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5678 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5679 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5680 job->jv_pid = pid; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5681 job->jv_status = JOB_STARTED; |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5682 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
|
5683 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5684 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
|
5685 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
|
5686 /* 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
|
5687 if (fd_in[0] >= 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5688 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
|
5689 if (fd_out[1] >= 0) |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5690 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
|
5691 if (fd_err[1] >= 0) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5692 close(fd_err[1]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5693 if (channel != NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5694 { |
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
|
5695 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
|
5696 ? 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
|
5697 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
|
5698 ? 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
|
5699 /* 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
|
5700 * 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
|
5701 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
|
5702 ? INVALID_FD |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5703 : 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
|
5704 ? 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
|
5705 : (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
|
5706 ? INVALID_FD |
ea0e6c71ba51
patch 8.0.1820: terminal window redirecting stdout does not show stderr
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5707 : 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
|
5708 |
5f6c61a71c02
patch 8.0.1761: job in terminal window with no output channel is killed
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
5709 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
|
5710 channel_set_job(channel, job, options); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5711 } |
11894
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5712 else |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5713 { |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5714 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
|
5715 close(fd_in[1]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5716 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
|
5717 close(fd_out[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5718 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
|
5719 close(fd_err[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5720 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
|
5721 close(pty_master_fd); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5722 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5723 |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5724 /* success! */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5725 return; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5726 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5727 failed: |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5728 channel_unref(channel); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5729 if (fd_in[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5730 close(fd_in[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5731 if (fd_in[1] >= 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5732 close(fd_in[1]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5733 if (fd_out[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5734 close(fd_out[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5735 if (fd_out[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5736 close(fd_out[1]); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5737 if (fd_err[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5738 close(fd_err[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5739 if (fd_err[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5740 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
|
5741 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
|
5742 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
|
5743 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
|
5744 close(pty_slave_fd); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5745 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5746 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5747 char * |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5748 mch_job_status(job_T *job) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5749 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5750 # ifdef HAVE_UNION_WAIT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5751 union wait status; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5752 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5753 int status = -1; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5754 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5755 pid_t wait_pid = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5756 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5757 # ifdef __NeXT__ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5758 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
|
5759 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5760 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
|
5761 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5762 if (wait_pid == -1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5763 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5764 /* 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
|
5765 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
|
5766 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
|
5767 strerror(errno)); |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5768 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5769 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5770 if (wait_pid == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5771 return "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5772 if (WIFEXITED(status)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5773 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5774 /* 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
|
5775 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
|
5776 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
|
5777 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
|
5778 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5779 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5780 if (WIFSIGNALED(status)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5781 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5782 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
|
5783 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
|
5784 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
|
5785 goto return_dead; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5786 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5787 return "run"; |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5788 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5789 return_dead: |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5790 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
|
5791 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5792 return "dead"; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5793 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5794 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5795 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5796 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
|
5797 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5798 # ifdef HAVE_UNION_WAIT |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5799 union wait status; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5800 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5801 int status = -1; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5802 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5803 pid_t wait_pid = 0; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5804 job_T *job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5805 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5806 # ifndef USE_SYSTEM |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5807 /* 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
|
5808 * 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
|
5809 * would then be wrong. */ |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5810 if (dont_check_job_ended > 0) |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5811 return NULL; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5812 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5813 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5814 # ifdef __NeXT__ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5815 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
|
5816 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5817 wait_pid = waitpid(-1, &status, WNOHANG); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5818 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5819 if (wait_pid <= 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5820 /* no process ended */ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5821 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5822 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
|
5823 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5824 if (job->jv_pid == wait_pid) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5825 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5826 if (WIFEXITED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5827 /* 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
|
5828 job->jv_exitval = WEXITSTATUS(status); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5829 else if (WIFSIGNALED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5830 job->jv_exitval = -1; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5831 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
|
5832 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5833 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
|
5834 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5835 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5836 return job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5837 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5838 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5839 return NULL; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5840 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5841 |
10320
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5842 /* |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5843 * Send a (deadly) signal to "job". |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5844 * 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
|
5845 */ |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5846 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
5847 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
|
5848 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5849 int sig = -1; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5850 |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5851 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
|
5852 sig = SIGTERM; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5853 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
|
5854 sig = SIGHUP; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5855 else if (STRCMP(how, "quit") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5856 sig = SIGQUIT; |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5857 else if (STRCMP(how, "int") == 0) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5858 sig = SIGINT; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5859 else if (STRCMP(how, "kill") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5860 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
|
5861 #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
|
5862 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
|
5863 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
|
5864 #endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5865 else if (isdigit(*how)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5866 sig = atoi((char *)how); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5867 else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5868 return FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5869 |
15123
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5870 // Never kill ourselves! |
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5871 if (job->jv_pid != 0) |
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5872 { |
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5873 // TODO: have an option to only kill the process, not the group? |
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5874 kill(-job->jv_pid, sig); |
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5875 kill(job->jv_pid, sig); |
7d2ed364a8a0
patch 8.1.0572: stopping a job does not work properly on OpenBSD
Bram Moolenaar <Bram@vim.org>
parents:
15029
diff
changeset
|
5876 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5877 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5878 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5879 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5880 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5881 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5882 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5883 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5884 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5885 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5886 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5887 /* 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
|
5888 # ifdef __NeXT__ |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5889 (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
|
5890 # else |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5891 (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
|
5892 # endif |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5893 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5894 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5895 |
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
|
5896 #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
|
5897 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
|
5898 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
|
5899 { |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5900 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
|
5901 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
|
5902 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
|
5903 |
12389
d0cf7f71b95b
patch 8.0.1074: ":term NONE" does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12369
diff
changeset
|
5904 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
|
5905 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
|
5906 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
|
5907 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
|
5908 |
24abce52ad20
patch 8.0.1000: cannot open a terminal without running a job in it
Christian Brabandt <cb@256bit.org>
parents:
12200
diff
changeset
|
5909 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
|
5910 if (channel == NULL) |
12369
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5911 { |
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5912 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
|
5913 return FAIL; |
12369
d7f087d1b0e5
patch 8.0.1064: Coverity warns for leaking resource
Christian Brabandt <cb@256bit.org>
parents:
12343
diff
changeset
|
5914 } |
12584
f28067b83dec
patch 8.0.1170: using termdebug results in 100% CPU time
Christian Brabandt <cb@256bit.org>
parents:
12389
diff
changeset
|
5915 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
|
5916 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
|
5917 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
|
5918 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
|
5919 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
|
5920 |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13778
diff
changeset
|
5921 /* 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
|
5922 * 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
|
5923 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
|
5924 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
|
5925 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
|
5926 } |
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 #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
|
5928 |
7 | 5929 /* |
5930 * Check for CTRL-C typed by reading all available characters. | |
5931 * In cooked mode we should get SIGINT, no need to check. | |
5932 */ | |
5933 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5934 mch_breakcheck(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5935 { |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5936 if ((curr_tmode == TMODE_RAW || force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5937 && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL)) |
7 | 5938 fill_input_buf(FALSE); |
5939 } | |
5940 | |
5941 /* | |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5942 * 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
|
5943 * from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5944 * "msec" == -1 will block forever. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5945 * 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
|
5946 * 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
|
5947 * already available. |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5948 * "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
|
5949 * 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
|
5950 * Returns TRUE when a character is available. |
7 | 5951 * When a GUI is being used, this will never get called -- webb |
5952 */ | |
5953 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5954 WaitForChar(long msec, int *interrupted, int ignore_input) |
7 | 5955 { |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5956 #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
|
5957 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
|
5958 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
|
5959 #else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5960 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
|
5961 #endif |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5962 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5963 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5964 /* |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5965 * 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
|
5966 * or from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5967 * "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
|
5968 * for "ignore_input" see WaitForCharOr(). |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5969 * "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
|
5970 * 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
|
5971 * 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
|
5972 */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5973 static int |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5974 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
|
5975 { |
7 | 5976 #ifdef FEAT_MOUSE_GPM |
5977 int gpm_process_wanted; | |
5978 #endif | |
5979 #ifdef FEAT_XCLIPBOARD | |
5980 int rest; | |
5981 #endif | |
5982 int avail; | |
5983 | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5984 if (!ignore_input && input_available()) /* something in inbuf[] */ |
7 | 5985 return 1; |
5986 | |
5987 #if defined(FEAT_MOUSE_DEC) | |
5988 /* May need to query the mouse position. */ | |
5989 if (WantQueryMouse) | |
5990 { | |
227 | 5991 WantQueryMouse = FALSE; |
7 | 5992 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5); |
5993 } | |
5994 #endif | |
5995 | |
5996 /* | |
5997 * For FEAT_MOUSE_GPM and FEAT_XCLIPBOARD we loop here to process mouse | |
5998 * events. This is a bit complicated, because they might both be defined. | |
5999 */ | |
6000 #if defined(FEAT_MOUSE_GPM) || defined(FEAT_XCLIPBOARD) | |
6001 # ifdef FEAT_XCLIPBOARD | |
6002 rest = 0; | |
6003 if (do_xterm_trace()) | |
6004 rest = msec; | |
6005 # endif | |
6006 do | |
6007 { | |
6008 # ifdef FEAT_XCLIPBOARD | |
6009 if (rest != 0) | |
6010 { | |
6011 msec = XT_TRACE_DELAY; | |
6012 if (rest >= 0 && rest < XT_TRACE_DELAY) | |
6013 msec = rest; | |
6014 if (rest >= 0) | |
6015 rest -= msec; | |
6016 } | |
6017 # endif | |
6018 # ifdef FEAT_MOUSE_GPM | |
6019 gpm_process_wanted = 0; | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6020 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
|
6021 &gpm_process_wanted, interrupted); |
7 | 6022 # else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6023 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 6024 # endif |
6025 if (!avail) | |
6026 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
6027 if (!ignore_input && input_available()) |
7 | 6028 return 1; |
6029 # ifdef FEAT_XCLIPBOARD | |
6030 if (rest == 0 || !do_xterm_trace()) | |
6031 # endif | |
6032 break; | |
6033 } | |
6034 } | |
6035 while (FALSE | |
6036 # ifdef FEAT_MOUSE_GPM | |
6037 || (gpm_process_wanted && mch_gpm_process() == 0) | |
6038 # endif | |
6039 # ifdef FEAT_XCLIPBOARD | |
6040 || (!avail && rest != 0) | |
6041 # endif | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6042 ) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
6043 ; |
7 | 6044 |
6045 #else | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6046 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 6047 #endif |
6048 return avail; | |
6049 } | |
6050 | |
5541 | 6051 #ifndef VMS |
7 | 6052 /* |
6053 * Wait "msec" msec until a character is available from file descriptor "fd". | |
3046 | 6054 * "msec" == 0 will check for characters once. |
6055 * "msec" == -1 will block until a character is available. | |
7 | 6056 * When a GUI is being used, this will not be used for input -- webb |
6057 * 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
|
6058 * 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
|
6059 * "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
|
6060 * but something else needs to be done. |
7 | 6061 */ |
6062 #if defined(__BEOS__) | |
6063 int | |
6064 #else | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6065 static int |
7 | 6066 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6067 RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted) |
7 | 6068 { |
6069 int ret; | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6070 int result; |
14 | 6071 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) |
7 | 6072 static int busy = FALSE; |
6073 | |
6074 /* May retry getting characters after an event was handled. */ | |
6075 # define MAY_LOOP | |
6076 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6077 # ifdef ELAPSED_FUNC |
7 | 6078 /* Remember at what time we started, so that we know how much longer we |
6079 * should wait after being interrupted. */ | |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6080 long start_msec = msec; |
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6081 elapsed_T start_tv; |
7 | 6082 |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
6083 if (msec > 0) |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6084 ELAPSED_INIT(start_tv); |
7 | 6085 # endif |
6086 | |
6087 /* Handle being called recursively. This may happen for the session | |
6088 * manager stuff, it may save the file, which does a breakcheck. */ | |
6089 if (busy) | |
6090 return 0; | |
6091 #endif | |
6092 | |
6093 #ifdef MAY_LOOP | |
407 | 6094 for (;;) |
7 | 6095 #endif |
6096 { | |
6097 #ifdef MAY_LOOP | |
6098 int finished = TRUE; /* default is to 'loop' just once */ | |
14 | 6099 # ifdef FEAT_MZSCHEME |
6100 int mzquantum_used = FALSE; | |
6101 # endif | |
7 | 6102 #endif |
6103 #ifndef HAVE_SELECT | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6104 /* 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
|
6105 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; |
7 | 6106 int nfd; |
6107 # ifdef FEAT_XCLIPBOARD | |
6108 int xterm_idx = -1; | |
6109 # endif | |
6110 # ifdef FEAT_MOUSE_GPM | |
6111 int gpm_idx = -1; | |
6112 # endif | |
6113 # ifdef USE_XSMP | |
6114 int xsmp_idx = -1; | |
6115 # endif | |
14 | 6116 int towait = (int)msec; |
6117 | |
6118 # ifdef FEAT_MZSCHEME | |
6119 mzvim_check_threads(); | |
6120 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
6121 { | |
6122 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ | |
6123 mzquantum_used = TRUE; | |
6124 } | |
6125 # endif | |
7 | 6126 fds[0].fd = fd; |
6127 fds[0].events = POLLIN; | |
6128 nfd = 1; | |
6129 | |
6130 # ifdef FEAT_XCLIPBOARD | |
6383 | 6131 may_restore_clipboard(); |
7 | 6132 if (xterm_Shell != (Widget)0) |
6133 { | |
6134 xterm_idx = nfd; | |
6135 fds[nfd].fd = ConnectionNumber(xterm_dpy); | |
6136 fds[nfd].events = POLLIN; | |
6137 nfd++; | |
6138 } | |
6139 # endif | |
6140 # ifdef FEAT_MOUSE_GPM | |
6141 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
6142 { | |
6143 gpm_idx = nfd; | |
6144 fds[nfd].fd = gpm_fd; | |
6145 fds[nfd].events = POLLIN; | |
6146 nfd++; | |
6147 } | |
6148 # endif | |
6149 # ifdef USE_XSMP | |
6150 if (xsmp_icefd != -1) | |
6151 { | |
6152 xsmp_idx = nfd; | |
6153 fds[nfd].fd = xsmp_icefd; | |
6154 fds[nfd].events = POLLIN; | |
6155 nfd++; | |
6156 } | |
6157 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6158 #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
|
6159 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
|
6160 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6161 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6162 *interrupted = FALSE; |
7 | 6163 |
14 | 6164 ret = poll(fds, nfd, towait); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6165 |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6166 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
|
6167 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
|
6168 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6169 |
14 | 6170 # ifdef FEAT_MZSCHEME |
6171 if (ret == 0 && mzquantum_used) | |
1450 | 6172 /* MzThreads scheduling is required and timeout occurred */ |
14 | 6173 finished = FALSE; |
6174 # endif | |
7 | 6175 |
6176 # ifdef FEAT_XCLIPBOARD | |
6177 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) | |
6178 { | |
6179 xterm_update(); /* Maybe we should hand out clipboard */ | |
6180 if (--ret == 0 && !input_available()) | |
6181 /* Try again */ | |
6182 finished = FALSE; | |
6183 } | |
6184 # endif | |
6185 # ifdef FEAT_MOUSE_GPM | |
6186 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN)) | |
6187 { | |
6188 *check_for_gpm = 1; | |
6189 } | |
6190 # endif | |
6191 # ifdef USE_XSMP | |
6192 if (xsmp_idx >= 0 && (fds[xsmp_idx].revents & (POLLIN | POLLHUP))) | |
6193 { | |
6194 if (fds[xsmp_idx].revents & POLLIN) | |
6195 { | |
6196 busy = TRUE; | |
6197 xsmp_handle_requests(); | |
6198 busy = FALSE; | |
6199 } | |
6200 else if (fds[xsmp_idx].revents & POLLHUP) | |
6201 { | |
6202 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
6203 verb_msg(_("XSMP lost ICE connection")); |
7 | 6204 xsmp_close(); |
6205 } | |
6206 if (--ret == 0) | |
14 | 6207 finished = FALSE; /* Try again */ |
7 | 6208 } |
6209 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6210 #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
|
6211 /* 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
|
6212 if (ret >= 0) |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
6213 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
|
6214 #endif |
7 | 6215 |
6216 #else /* HAVE_SELECT */ | |
6217 | |
6218 struct timeval tv; | |
14 | 6219 struct timeval *tvp; |
15029
588a5fafbb61
patch 8.1.0526: running out of signal stack in RealWaitForChar
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
6220 // These are static because they can take 8 Kbyte each and cause the |
588a5fafbb61
patch 8.1.0526: running out of signal stack in RealWaitForChar
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
6221 // signal stack to run out with -O3. |
588a5fafbb61
patch 8.1.0526: running out of signal stack in RealWaitForChar
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
6222 static fd_set rfds, wfds, efds; |
7 | 6223 int maxfd; |
14 | 6224 long towait = msec; |
6225 | |
6226 # ifdef FEAT_MZSCHEME | |
6227 mzvim_check_threads(); | |
6228 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
6229 { | |
6230 towait = p_mzq; /* don't wait longer than 'mzquantum' */ | |
6231 mzquantum_used = TRUE; | |
6232 } | |
6233 # endif | |
7 | 6234 |
14 | 6235 if (towait >= 0) |
7 | 6236 { |
14 | 6237 tv.tv_sec = towait / 1000; |
6238 tv.tv_usec = (towait % 1000) * (1000000/1000); | |
6239 tvp = &tv; | |
7 | 6240 } |
14 | 6241 else |
6242 tvp = NULL; | |
7 | 6243 |
6244 /* | |
6245 * Select on ready for reading and exceptional condition (end of file). | |
6246 */ | |
3046 | 6247 select_eintr: |
6248 FD_ZERO(&rfds); | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6249 FD_ZERO(&wfds); |
7 | 6250 FD_ZERO(&efds); |
6251 FD_SET(fd, &rfds); | |
6252 # if !defined(__QNX__) && !defined(__CYGWIN32__) | |
6253 /* For QNX select() always returns 1 if this is set. Why? */ | |
6254 FD_SET(fd, &efds); | |
6255 # endif | |
6256 maxfd = fd; | |
6257 | |
6258 # ifdef FEAT_XCLIPBOARD | |
6383 | 6259 may_restore_clipboard(); |
7 | 6260 if (xterm_Shell != (Widget)0) |
6261 { | |
6262 FD_SET(ConnectionNumber(xterm_dpy), &rfds); | |
6263 if (maxfd < ConnectionNumber(xterm_dpy)) | |
6264 maxfd = ConnectionNumber(xterm_dpy); | |
3748 | 6265 |
6266 /* An event may have already been read but not handled. In | |
6267 * particulary, XFlush may cause this. */ | |
6268 xterm_update(); | |
7 | 6269 } |
6270 # endif | |
6271 # ifdef FEAT_MOUSE_GPM | |
6272 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
6273 { | |
6274 FD_SET(gpm_fd, &rfds); | |
6275 FD_SET(gpm_fd, &efds); | |
6276 if (maxfd < gpm_fd) | |
6277 maxfd = gpm_fd; | |
6278 } | |
6279 # endif | |
6280 # ifdef USE_XSMP | |
6281 if (xsmp_icefd != -1) | |
6282 { | |
6283 FD_SET(xsmp_icefd, &rfds); | |
6284 FD_SET(xsmp_icefd, &efds); | |
6285 if (maxfd < xsmp_icefd) | |
6286 maxfd = xsmp_icefd; | |
6287 } | |
6288 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6289 # 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
|
6290 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
|
6291 # endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6292 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6293 *interrupted = FALSE; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6294 |
14718
cf33c47d66aa
patch 8.1.0371: argument types for select() may be wrong
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
6295 ret = select(maxfd + 1, SELECT_TYPE_ARG234 &rfds, |
cf33c47d66aa
patch 8.1.0371: argument types for select() may be wrong
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
6296 SELECT_TYPE_ARG234 &wfds, SELECT_TYPE_ARG234 &efds, tvp); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6297 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
|
6298 if (result) |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6299 --ret; |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6300 else if (interrupted != NULL && ret > 0) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6301 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6302 |
3046 | 6303 # ifdef EINTR |
6304 if (ret == -1 && errno == EINTR) | |
3133 | 6305 { |
6306 /* Check whether window has been resized, EINTR may be caused by | |
6307 * SIGWINCH. */ | |
6308 if (do_resize) | |
6309 handle_resize(); | |
6310 | |
3046 | 6311 /* Interrupted by a signal, need to try again. We ignore msec |
6312 * here, because we do want to check even after a timeout if | |
6313 * characters are available. Needed for reading output of an | |
6314 * external command after the process has finished. */ | |
6315 goto select_eintr; | |
3133 | 6316 } |
3046 | 6317 # endif |
1076 | 6318 # ifdef __TANDEM |
6319 if (ret == -1 && errno == ENOTSUP) | |
6320 { | |
6321 FD_ZERO(&rfds); | |
6322 FD_ZERO(&efds); | |
6323 ret = 0; | |
6324 } | |
3046 | 6325 # endif |
14 | 6326 # ifdef FEAT_MZSCHEME |
6327 if (ret == 0 && mzquantum_used) | |
1450 | 6328 /* loop if MzThreads must be scheduled and timeout occurred */ |
14 | 6329 finished = FALSE; |
7 | 6330 # endif |
6331 | |
6332 # ifdef FEAT_XCLIPBOARD | |
6333 if (ret > 0 && xterm_Shell != (Widget)0 | |
6334 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) | |
6335 { | |
6336 xterm_update(); /* Maybe we should hand out clipboard */ | |
6337 /* continue looping when we only got the X event and the input | |
6338 * buffer is empty */ | |
6339 if (--ret == 0 && !input_available()) | |
6340 { | |
6341 /* Try again */ | |
6342 finished = FALSE; | |
6343 } | |
6344 } | |
6345 # endif | |
6346 # ifdef FEAT_MOUSE_GPM | |
6347 if (ret > 0 && gpm_flag && check_for_gpm != NULL && gpm_fd >= 0) | |
6348 { | |
6349 if (FD_ISSET(gpm_fd, &efds)) | |
6350 gpm_close(); | |
6351 else if (FD_ISSET(gpm_fd, &rfds)) | |
6352 *check_for_gpm = 1; | |
6353 } | |
6354 # endif | |
6355 # ifdef USE_XSMP | |
6356 if (ret > 0 && xsmp_icefd != -1) | |
6357 { | |
6358 if (FD_ISSET(xsmp_icefd, &efds)) | |
6359 { | |
6360 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
6361 verb_msg(_("XSMP lost ICE connection")); |
7 | 6362 xsmp_close(); |
6363 if (--ret == 0) | |
6364 finished = FALSE; /* keep going if event was only one */ | |
6365 } | |
6366 else if (FD_ISSET(xsmp_icefd, &rfds)) | |
6367 { | |
6368 busy = TRUE; | |
6369 xsmp_handle_requests(); | |
6370 busy = FALSE; | |
6371 if (--ret == 0) | |
6372 finished = FALSE; /* keep going if event was only one */ | |
6373 } | |
6374 } | |
6375 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6376 #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
|
6377 /* 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
|
6378 if (ret >= 0) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6379 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
|
6380 #endif |
7 | 6381 |
6382 #endif /* HAVE_SELECT */ | |
6383 | |
6384 #ifdef MAY_LOOP | |
6385 if (finished || msec == 0) | |
6386 break; | |
6387 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6388 # ifdef FEAT_CLIENTSERVER |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6389 if (server_waiting()) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6390 break; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6391 # endif |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6392 |
7 | 6393 /* We're going to loop around again, find out for how long */ |
6394 if (msec > 0) | |
6395 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6396 # ifdef ELAPSED_FUNC |
7 | 6397 /* Compute remaining wait time. */ |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6398 msec = start_msec - ELAPSED_FUNC(start_tv); |
7 | 6399 # else |
6400 /* Guess we got interrupted halfway. */ | |
6401 msec = msec / 2; | |
6402 # endif | |
6403 if (msec <= 0) | |
6404 break; /* waited long enough */ | |
6405 } | |
6406 #endif | |
6407 } | |
6408 | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6409 return result; |
7 | 6410 } |
6411 | |
6412 #ifndef NO_EXPANDPATH | |
6413 /* | |
444 | 6414 * Expand a path into all matching files and/or directories. Handles "*", |
6415 * "?", "[a-z]", "**", etc. | |
6416 * "path" has backslashes before chars that are not to be expanded. | |
6417 * Returns the number of matches found. | |
7 | 6418 */ |
6419 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6420 mch_expandpath( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6421 garray_T *gap, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6422 char_u *path, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6423 int flags) /* EW_* flags */ |
7 | 6424 { |
444 | 6425 return unix_expandpath(gap, path, 0, flags, FALSE); |
7 | 6426 } |
6427 #endif | |
6428 | |
6429 /* | |
6430 * mch_expand_wildcards() - this code does wild-card pattern matching using | |
6431 * the shell | |
6432 * | |
6433 * return OK for success, FAIL for error (you may lose some memory) and put | |
6434 * an error message in *file. | |
6435 * | |
6436 * num_pat is number of input patterns | |
6437 * pat is array of pointers to input patterns | |
6438 * num_file is pointer to number of matched file names | |
6439 * file is pointer to array of pointers to matched file names | |
6440 */ | |
6441 | |
6442 #ifndef SEEK_SET | |
6443 # define SEEK_SET 0 | |
6444 #endif | |
6445 #ifndef SEEK_END | |
6446 # define SEEK_END 2 | |
6447 #endif | |
6448 | |
822 | 6449 #define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
628 | 6450 |
7 | 6451 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6452 mch_expand_wildcards( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6453 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6454 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6455 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6456 char_u ***file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6457 int flags) /* EW_* flags */ |
7 | 6458 { |
6459 int i; | |
6460 size_t len; | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6461 long llen; |
7 | 6462 char_u *p; |
6463 int dir; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
6464 |
1508 | 6465 /* |
6466 * This is the non-OS/2 implementation (really Unix). | |
6467 */ | |
7 | 6468 int j; |
6469 char_u *tempname; | |
6470 char_u *command; | |
6471 FILE *fd; | |
6472 char_u *buffer; | |
1508 | 6473 #define STYLE_ECHO 0 /* use "echo", the default */ |
6474 #define STYLE_GLOB 1 /* use "glob", for csh */ | |
6475 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
6476 #define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
6477 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
6478 * directly */ | |
7 | 6479 int shell_style = STYLE_ECHO; |
6480 int check_spaces; | |
6481 static int did_find_nul = FALSE; | |
6482 int ampersent = FALSE; | |
1508 | 6483 /* vimglob() function to define for Posix shell */ |
1620 | 6484 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; |
7 | 6485 |
6486 *num_file = 0; /* default: no files found */ | |
6487 *file = NULL; | |
6488 | |
6489 /* | |
6490 * If there are no wildcards, just copy the names to allocated memory. | |
6491 * Saves a lot of time, because we don't have to start a new shell. | |
6492 */ | |
6493 if (!have_wildcard(num_pat, pat)) | |
6494 return save_patterns(num_pat, pat, num_file, file); | |
6495 | |
428 | 6496 # ifdef HAVE_SANDBOX |
6497 /* Don't allow any shell command in the sandbox. */ | |
6498 if (sandbox != 0 && check_secure()) | |
6499 return FAIL; | |
6500 # endif | |
6501 | |
7 | 6502 /* |
6503 * Don't allow the use of backticks in secure and restricted mode. | |
6504 */ | |
428 | 6505 if (secure || restricted) |
7 | 6506 for (i = 0; i < num_pat; ++i) |
6507 if (vim_strchr(pat[i], '`') != NULL | |
6508 && (check_restricted() || check_secure())) | |
6509 return FAIL; | |
6510 | |
6511 /* | |
6512 * get a name for the temp file | |
6513 */ | |
6721 | 6514 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 6515 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
6516 emsg(_(e_notmp)); |
7 | 6517 return FAIL; |
6518 } | |
6519 | |
6520 /* | |
6521 * Let the shell expand the patterns and write the result into the temp | |
1508 | 6522 * file. |
6523 * STYLE_BT: NL separated | |
6524 * If expanding `cmd` execute it directly. | |
6525 * STYLE_GLOB: NUL separated | |
6526 * If we use *csh, "glob" will work better than "echo". | |
6527 * STYLE_PRINT: NL or NUL separated | |
6528 * If we use *zsh, "print -N" will work better than "glob". | |
6529 * STYLE_VIMGLOB: NL separated | |
6530 * If we use *sh*, we define "vimglob()". | |
6531 * STYLE_ECHO: space separated. | |
6532 * A shell we don't know, stay safe and use "echo". | |
7 | 6533 */ |
6534 if (num_pat == 1 && *pat[0] == '`' | |
6535 && (len = STRLEN(pat[0])) > 2 | |
6536 && *(pat[0] + len - 1) == '`') | |
6537 shell_style = STYLE_BT; | |
6538 else if ((len = STRLEN(p_sh)) >= 3) | |
6539 { | |
6540 if (STRCMP(p_sh + len - 3, "csh") == 0) | |
6541 shell_style = STYLE_GLOB; | |
6542 else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
6543 shell_style = STYLE_PRINT; | |
6544 } | |
1508 | 6545 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), |
6546 "sh") != NULL) | |
6547 shell_style = STYLE_VIMGLOB; | |
6548 | |
6549 /* Compute the length of the command. We need 2 extra bytes: for the | |
6550 * optional '&' and for the NUL. | |
6551 * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
7 | 6552 len = STRLEN(tempname) + 29; |
1508 | 6553 if (shell_style == STYLE_VIMGLOB) |
6554 len += STRLEN(sh_vimglob_func); | |
6555 | |
147 | 6556 for (i = 0; i < num_pat; ++i) |
6557 { | |
6558 /* Count the length of the patterns in the same way as they are put in | |
6559 * "command" below. */ | |
6560 #ifdef USE_SYSTEM | |
7 | 6561 len += STRLEN(pat[i]) + 3; /* add space and two quotes */ |
147 | 6562 #else |
6563 ++len; /* add space */ | |
628 | 6564 for (j = 0; pat[i][j] != NUL; ++j) |
6565 { | |
6566 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
6567 ++len; /* may add a backslash */ | |
6568 ++len; | |
6569 } | |
147 | 6570 #endif |
6571 } | |
7 | 6572 command = alloc(len); |
6573 if (command == NULL) | |
6574 { | |
6575 /* out of memory */ | |
6576 vim_free(tempname); | |
6577 return FAIL; | |
6578 } | |
6579 | |
6580 /* | |
6581 * Build the shell command: | |
6582 * - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell | |
6583 * recognizes this). | |
6584 * - Add the shell command to print the expanded names. | |
6585 * - Add the temp file name. | |
6586 * - Add the file name patterns. | |
6587 */ | |
6588 if (shell_style == STYLE_BT) | |
6589 { | |
628 | 6590 /* change `command; command& ` to (command; command ) */ |
6591 STRCPY(command, "("); | |
6592 STRCAT(command, pat[0] + 1); /* exclude first backtick */ | |
7 | 6593 p = command + STRLEN(command) - 1; |
628 | 6594 *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
|
6595 while (p > command && VIM_ISWHITE(*p)) |
7 | 6596 --p; |
6597 if (*p == '&') /* remove trailing '&' */ | |
6598 { | |
6599 ampersent = TRUE; | |
6600 *p = ' '; | |
6601 } | |
6602 STRCAT(command, ">"); | |
6603 } | |
6604 else | |
6605 { | |
6606 if (flags & EW_NOTFOUND) | |
6607 STRCPY(command, "set nonomatch; "); | |
6608 else | |
6609 STRCPY(command, "unset nonomatch; "); | |
6610 if (shell_style == STYLE_GLOB) | |
6611 STRCAT(command, "glob >"); | |
6612 else if (shell_style == STYLE_PRINT) | |
6613 STRCAT(command, "print -N >"); | |
1508 | 6614 else if (shell_style == STYLE_VIMGLOB) |
6615 STRCAT(command, sh_vimglob_func); | |
7 | 6616 else |
6617 STRCAT(command, "echo >"); | |
6618 } | |
1508 | 6619 |
7 | 6620 STRCAT(command, tempname); |
1508 | 6621 |
7 | 6622 if (shell_style != STYLE_BT) |
6623 for (i = 0; i < num_pat; ++i) | |
6624 { | |
6625 /* When using system() always add extra quotes, because the shell | |
628 | 6626 * is started twice. Otherwise put a backslash before special |
1450 | 6627 * characters, except inside ``. */ |
7 | 6628 #ifdef USE_SYSTEM |
6629 STRCAT(command, " \""); | |
6630 STRCAT(command, pat[i]); | |
6631 STRCAT(command, "\""); | |
6632 #else | |
233 | 6633 int intick = FALSE; |
6634 | |
7 | 6635 p = command + STRLEN(command); |
6636 *p++ = ' '; | |
628 | 6637 for (j = 0; pat[i][j] != NUL; ++j) |
233 | 6638 { |
6639 if (pat[i][j] == '`') | |
6640 intick = !intick; | |
628 | 6641 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) |
6642 { | |
644 | 6643 /* Remove a backslash, take char literally. But keep |
652 | 6644 * backslash inside backticks, before a special character |
6645 * and before a backtick. */ | |
644 | 6646 if (intick |
652 | 6647 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL |
6648 || pat[i][j + 1] == '`') | |
644 | 6649 *p++ = '\\'; |
648 | 6650 ++j; |
628 | 6651 } |
6174 | 6652 else if (!intick |
6653 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') | |
6654 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
628 | 6655 /* Put a backslash before a special character, but not |
6174 | 6656 * when inside ``. And not for $var when EW_KEEPDOLLAR is |
6657 * set. */ | |
628 | 6658 *p++ = '\\'; |
648 | 6659 |
6660 /* Copy one character. */ | |
6661 *p++ = pat[i][j]; | |
233 | 6662 } |
7 | 6663 *p = NUL; |
6664 #endif | |
6665 } | |
6666 if (flags & EW_SILENT) | |
6667 show_shell_mess = FALSE; | |
6668 if (ampersent) | |
1508 | 6669 STRCAT(command, "&"); /* put the '&' after the redirection */ |
7 | 6670 |
6671 /* | |
6672 * Using zsh -G: If a pattern has no matches, it is just deleted from | |
6673 * the argument list, otherwise zsh gives an error message and doesn't | |
6674 * expand any other pattern. | |
6675 */ | |
6676 if (shell_style == STYLE_PRINT) | |
6677 extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ | |
6678 | |
6679 /* | |
6680 * If we use -f then shell variables set in .cshrc won't get expanded. | |
6681 * vi can do it, so we will too, but it is only necessary if there is a "$" | |
6682 * in one of the patterns, otherwise we can still use the fast option. | |
6683 */ | |
6684 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) | |
6685 extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ | |
6686 | |
6687 /* | |
6688 * execute the shell command | |
6689 */ | |
6690 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); | |
6691 | |
6692 /* When running in the background, give it some time to create the temp | |
6693 * file, but don't wait for it to finish. */ | |
6694 if (ampersent) | |
6695 mch_delay(10L, TRUE); | |
6696 | |
6697 extra_shell_arg = NULL; /* cleanup */ | |
6698 show_shell_mess = TRUE; | |
6699 vim_free(command); | |
6700 | |
1508 | 6701 if (i != 0) /* mch_call_shell() failed */ |
7 | 6702 { |
6703 mch_remove(tempname); | |
6704 vim_free(tempname); | |
6705 /* | |
6706 * With interactive completion, the error message is not printed. | |
6707 * However with USE_SYSTEM, I don't know how to turn off error messages | |
6708 * from the shell, so screen may still get messed up -- webb. | |
6709 */ | |
6710 #ifndef USE_SYSTEM | |
6711 if (!(flags & EW_SILENT)) | |
6712 #endif | |
6713 { | |
6714 redraw_later_clear(); /* probably messed up screen */ | |
6715 msg_putchar('\n'); /* clear bottom line quickly */ | |
6716 cmdline_row = Rows - 1; /* continue on last line */ | |
6717 #ifdef USE_SYSTEM | |
6718 if (!(flags & EW_SILENT)) | |
6719 #endif | |
6720 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
6721 msg(_(e_wildexpand)); |
7 | 6722 msg_start(); /* don't overwrite this message */ |
6723 } | |
6724 } | |
6725 /* If a `cmd` expansion failed, don't list `cmd` as a match, even when | |
6726 * EW_NOTFOUND is given */ | |
6727 if (shell_style == STYLE_BT) | |
6728 return FAIL; | |
6729 goto notfound; | |
6730 } | |
6731 | |
6732 /* | |
6733 * read the names from the file into memory | |
6734 */ | |
6735 fd = fopen((char *)tempname, READBIN); | |
6736 if (fd == NULL) | |
6737 { | |
6738 /* Something went wrong, perhaps a file name with a special char. */ | |
6739 if (!(flags & EW_SILENT)) | |
6740 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
6741 msg(_(e_wildexpand)); |
7 | 6742 msg_start(); /* don't overwrite this message */ |
6743 } | |
6744 vim_free(tempname); | |
6745 goto notfound; | |
6746 } | |
6747 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
|
6748 llen = ftell(fd); /* get size of temp file */ |
7 | 6749 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
|
6750 if (llen < 0) |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6751 /* 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
|
6752 buffer = NULL; |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6753 else |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6754 buffer = alloc(llen + 1); |
7 | 6755 if (buffer == NULL) |
6756 { | |
6757 /* out of memory */ | |
6758 mch_remove(tempname); | |
6759 vim_free(tempname); | |
6760 fclose(fd); | |
6761 return FAIL; | |
6762 } | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6763 len = llen; |
7 | 6764 i = fread((char *)buffer, 1, len, fd); |
6765 fclose(fd); | |
6766 mch_remove(tempname); | |
1877 | 6767 if (i != (int)len) |
7 | 6768 { |
6769 /* unexpected read error */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
6770 semsg(_(e_notread), tempname); |
7 | 6771 vim_free(tempname); |
6772 vim_free(buffer); | |
6773 return FAIL; | |
6774 } | |
6775 vim_free(tempname); | |
6776 | |
1508 | 6777 # if defined(__CYGWIN__) || defined(__CYGWIN32__) |
7 | 6778 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ |
6779 p = buffer; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
6780 for (i = 0; i < (int)len; ++i) |
7 | 6781 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) |
6782 *p++ = buffer[i]; | |
6783 len = p - buffer; | |
6784 # endif | |
6785 | |
6786 | |
6787 /* file names are separated with Space */ | |
6788 if (shell_style == STYLE_ECHO) | |
6789 { | |
6790 buffer[len] = '\n'; /* make sure the buffer ends in NL */ | |
6791 p = buffer; | |
6792 for (i = 0; *p != '\n'; ++i) /* count number of entries */ | |
6793 { | |
6794 while (*p != ' ' && *p != '\n') | |
6795 ++p; | |
6796 p = skipwhite(p); /* skip to next entry */ | |
6797 } | |
6798 } | |
6799 /* file names are separated with NL */ | |
1508 | 6800 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) |
7 | 6801 { |
6802 buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
6803 p = buffer; | |
6804 for (i = 0; *p != NUL; ++i) /* count number of entries */ | |
6805 { | |
6806 while (*p != '\n' && *p != NUL) | |
6807 ++p; | |
6808 if (*p != NUL) | |
6809 ++p; | |
6810 p = skipwhite(p); /* skip leading white space */ | |
6811 } | |
6812 } | |
6813 /* file names are separated with NUL */ | |
6814 else | |
6815 { | |
6816 /* | |
6817 * Some versions of zsh use spaces instead of NULs to separate | |
6818 * results. Only do this when there is no NUL before the end of the | |
6819 * buffer, otherwise we would never be able to use file names with | |
6820 * embedded spaces when zsh does use NULs. | |
6821 * When we found a NUL once, we know zsh is OK, set did_find_nul and | |
6822 * don't check for spaces again. | |
6823 */ | |
6824 check_spaces = FALSE; | |
6825 if (shell_style == STYLE_PRINT && !did_find_nul) | |
6826 { | |
6827 /* If there is a NUL, set did_find_nul, else set check_spaces */ | |
2768 | 6828 buffer[len] = NUL; |
5533 | 6829 if (len && (int)STRLEN(buffer) < (int)len) |
7 | 6830 did_find_nul = TRUE; |
6831 else | |
6832 check_spaces = TRUE; | |
6833 } | |
6834 | |
6835 /* | |
6836 * Make sure the buffer ends with a NUL. For STYLE_PRINT there | |
6837 * already is one, for STYLE_GLOB it needs to be added. | |
6838 */ | |
6839 if (len && buffer[len - 1] == NUL) | |
6840 --len; | |
6841 else | |
6842 buffer[len] = NUL; | |
6843 i = 0; | |
6844 for (p = buffer; p < buffer + len; ++p) | |
6845 if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ | |
6846 { | |
6847 ++i; | |
6848 *p = NUL; | |
6849 } | |
6850 if (len) | |
6851 ++i; /* count last entry */ | |
6852 } | |
6853 if (i == 0) | |
6854 { | |
6855 /* | |
6856 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I". | |
6857 * /bin/sh will happily expand it to nothing rather than returning an | |
6858 * error; and hey, it's good to check anyway -- webb. | |
6859 */ | |
6860 vim_free(buffer); | |
6861 goto notfound; | |
6862 } | |
6863 *num_file = i; | |
6864 *file = (char_u **)alloc(sizeof(char_u *) * i); | |
6865 if (*file == NULL) | |
6866 { | |
6867 /* out of memory */ | |
6868 vim_free(buffer); | |
6869 return FAIL; | |
6870 } | |
6871 | |
6872 /* | |
6873 * Isolate the individual file names. | |
6874 */ | |
6875 p = buffer; | |
6876 for (i = 0; i < *num_file; ++i) | |
6877 { | |
6878 (*file)[i] = p; | |
6879 /* Space or NL separates */ | |
1508 | 6880 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT |
6881 || shell_style == STYLE_VIMGLOB) | |
7 | 6882 { |
652 | 6883 while (!(shell_style == STYLE_ECHO && *p == ' ') |
6884 && *p != '\n' && *p != NUL) | |
7 | 6885 ++p; |
6886 if (p == buffer + len) /* last entry */ | |
6887 *p = NUL; | |
6888 else | |
6889 { | |
6890 *p++ = NUL; | |
6891 p = skipwhite(p); /* skip to next entry */ | |
6892 } | |
6893 } | |
6894 else /* NUL separates */ | |
6895 { | |
6896 while (*p && p < buffer + len) /* skip entry */ | |
6897 ++p; | |
6898 ++p; /* skip NUL */ | |
6899 } | |
6900 } | |
6901 | |
6902 /* | |
6903 * Move the file names to allocated memory. | |
6904 */ | |
6905 for (j = 0, i = 0; i < *num_file; ++i) | |
6906 { | |
6907 /* Require the files to exist. Helps when using /bin/sh */ | |
6908 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) | |
6909 continue; | |
6910 | |
6911 /* check if this entry should be included */ | |
6912 dir = (mch_isdir((*file)[i])); | |
6913 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) | |
6914 continue; | |
6915 | |
715 | 6916 /* Skip files that are not executable if we check for that. */ |
6695 | 6917 if (!dir && (flags & EW_EXEC) |
6918 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) | |
715 | 6919 continue; |
6920 | |
7 | 6921 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); |
6922 if (p) | |
6923 { | |
6924 STRCPY(p, (*file)[i]); | |
6925 if (dir) | |
1479 | 6926 add_pathsep(p); /* add '/' to a directory name */ |
7 | 6927 (*file)[j++] = p; |
6928 } | |
6929 } | |
6930 vim_free(buffer); | |
6931 *num_file = j; | |
6932 | |
6933 if (*num_file == 0) /* rejected all entries */ | |
6934 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
6935 VIM_CLEAR(*file); |
7 | 6936 goto notfound; |
6937 } | |
6938 | |
6939 return OK; | |
6940 | |
6941 notfound: | |
6942 if (flags & EW_NOTFOUND) | |
6943 return save_patterns(num_pat, pat, num_file, file); | |
6944 return FAIL; | |
6945 } | |
6946 | |
6947 #endif /* VMS */ | |
6948 | |
6949 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6950 save_patterns( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6951 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6952 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6953 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6954 char_u ***file) |
7 | 6955 { |
6956 int i; | |
99 | 6957 char_u *s; |
7 | 6958 |
6959 *file = (char_u **)alloc(num_pat * sizeof(char_u *)); | |
6960 if (*file == NULL) | |
6961 return FAIL; | |
6962 for (i = 0; i < num_pat; i++) | |
99 | 6963 { |
6964 s = vim_strsave(pat[i]); | |
6965 if (s != NULL) | |
6966 /* Be compatible with expand_filename(): halve the number of | |
6967 * backslashes. */ | |
6968 backslash_halve(s); | |
6969 (*file)[i] = s; | |
6970 } | |
7 | 6971 *num_file = num_pat; |
6972 return OK; | |
6973 } | |
6974 | |
6975 /* | |
6976 * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can | |
6977 * expand. | |
6978 */ | |
6979 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6980 mch_has_exp_wildcard(char_u *p) |
7 | 6981 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
6982 for ( ; *p; MB_PTR_ADV(p)) |
7 | 6983 { |
6984 if (*p == '\\' && p[1] != NUL) | |
6985 ++p; | |
6986 else | |
6987 if (vim_strchr((char_u *) | |
6988 #ifdef VMS | |
6989 "*?%" | |
6990 #else | |
6991 "*?[{'" | |
6992 #endif | |
6993 , *p) != NULL) | |
6994 return TRUE; | |
6995 } | |
6996 return FALSE; | |
6997 } | |
6998 | |
6999 /* | |
7000 * Return TRUE if the string "p" contains a wildcard. | |
7001 * Don't recognize '~' at the end as a wildcard. | |
7002 */ | |
7003 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7004 mch_has_wildcard(char_u *p) |
7 | 7005 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
7006 for ( ; *p; MB_PTR_ADV(p)) |
7 | 7007 { |
7008 if (*p == '\\' && p[1] != NUL) | |
7009 ++p; | |
7010 else | |
7011 if (vim_strchr((char_u *) | |
7012 #ifdef VMS | |
7013 "*?%$" | |
7014 #else | |
7015 "*?[{`'$" | |
7016 #endif | |
7017 , *p) != NULL | |
7018 || (*p == '~' && p[1] != NUL)) | |
7019 return TRUE; | |
7020 } | |
7021 return FALSE; | |
7022 } | |
7023 | |
7024 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7025 have_wildcard(int num, char_u **file) |
7 | 7026 { |
7027 int i; | |
7028 | |
7029 for (i = 0; i < num; i++) | |
7030 if (mch_has_wildcard(file[i])) | |
7031 return 1; | |
7032 return 0; | |
7033 } | |
7034 | |
7035 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7036 have_dollars(int num, char_u **file) |
7 | 7037 { |
7038 int i; | |
7039 | |
7040 for (i = 0; i < num; i++) | |
7041 if (vim_strchr(file[i], '$') != NULL) | |
7042 return TRUE; | |
7043 return FALSE; | |
7044 } | |
7045 | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7046 #if !defined(HAVE_RENAME) || defined(PROTO) |
7 | 7047 /* |
7048 * Scaled-down version of rename(), which is missing in Xenix. | |
7049 * This version can only move regular files and will fail if the | |
7050 * destination exists. | |
7051 */ | |
7052 int | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7053 mch_rename(const char *src, const char *dest) |
7 | 7054 { |
7055 struct stat st; | |
7056 | |
7057 if (stat(dest, &st) >= 0) /* fail if destination exists */ | |
7058 return -1; | |
7059 if (link(src, dest) != 0) /* link file to new name */ | |
7060 return -1; | |
7061 if (mch_remove(src) == 0) /* delete link to old name */ | |
7062 return 0; | |
7063 return -1; | |
7064 } | |
7065 #endif /* !HAVE_RENAME */ | |
7066 | |
7067 #ifdef FEAT_MOUSE_GPM | |
7068 /* | |
7069 * Initializes connection with gpm (if it isn't already opened) | |
7070 * Return 1 if succeeded (or connection already opened), 0 if failed | |
7071 */ | |
7072 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7073 gpm_open(void) |
7 | 7074 { |
7075 static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ | |
7076 | |
7077 if (!gpm_flag) | |
7078 { | |
7079 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); | |
7080 gpm_connect.defaultMask = ~GPM_HARD; | |
7081 /* Default handling for mouse move*/ | |
7082 gpm_connect.minMod = 0; /* Handle any modifier keys */ | |
7083 gpm_connect.maxMod = 0xffff; | |
7084 if (Gpm_Open(&gpm_connect, 0) > 0) | |
7085 { | |
7086 /* gpm library tries to handling TSTP causes | |
7087 * problems. Anyways, we close connection to Gpm whenever | |
7088 * we are going to suspend or starting an external process | |
1450 | 7089 * so we shouldn't have problem with this |
7 | 7090 */ |
1832 | 7091 # ifdef SIGTSTP |
7 | 7092 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); |
1832 | 7093 # endif |
7 | 7094 return 1; /* succeed */ |
7095 } | |
7096 if (gpm_fd == -2) | |
7097 Gpm_Close(); /* We don't want to talk to xterm via gpm */ | |
7098 return 0; | |
7099 } | |
7100 return 1; /* already open */ | |
7101 } | |
7102 | |
7103 /* | |
7104 * Closes connection to gpm | |
7105 */ | |
7106 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7107 gpm_close(void) |
7 | 7108 { |
7109 if (gpm_flag && gpm_fd >= 0) /* if Open */ | |
7110 Gpm_Close(); | |
7111 } | |
7112 | |
7113 /* Reads gpm event and adds special keys to input buf. Returns length of | |
7114 * generated key sequence. | |
5782 | 7115 * This function is styled after gui_send_mouse_event(). |
7 | 7116 */ |
7117 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7118 mch_gpm_process(void) |
7 | 7119 { |
7120 int button; | |
7121 static Gpm_Event gpm_event; | |
7122 char_u string[6]; | |
7123 int_u vim_modifiers; | |
7124 int row,col; | |
7125 unsigned char buttons_mask; | |
7126 unsigned char gpm_modifiers; | |
7127 static unsigned char old_buttons = 0; | |
7128 | |
7129 Gpm_GetEvent(&gpm_event); | |
7130 | |
7131 #ifdef FEAT_GUI | |
7132 /* Don't put events in the input queue now. */ | |
7133 if (hold_gui_events) | |
7134 return 0; | |
7135 #endif | |
7136 | |
7137 row = gpm_event.y - 1; | |
7138 col = gpm_event.x - 1; | |
7139 | |
7140 string[0] = ESC; /* Our termcode */ | |
7141 string[1] = 'M'; | |
7142 string[2] = 'G'; | |
7143 switch (GPM_BARE_EVENTS(gpm_event.type)) | |
7144 { | |
7145 case GPM_DRAG: | |
7146 string[3] = MOUSE_DRAG; | |
7147 break; | |
7148 case GPM_DOWN: | |
7149 buttons_mask = gpm_event.buttons & ~old_buttons; | |
7150 old_buttons = gpm_event.buttons; | |
7151 switch (buttons_mask) | |
7152 { | |
7153 case GPM_B_LEFT: | |
7154 button = MOUSE_LEFT; | |
7155 break; | |
7156 case GPM_B_MIDDLE: | |
7157 button = MOUSE_MIDDLE; | |
7158 break; | |
7159 case GPM_B_RIGHT: | |
7160 button = MOUSE_RIGHT; | |
7161 break; | |
7162 default: | |
7163 return 0; | |
7164 /*Don't know what to do. Can more than one button be | |
7165 * reported in one event? */ | |
7166 } | |
7167 string[3] = (char_u)(button | 0x20); | |
7168 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); | |
7169 break; | |
7170 case GPM_UP: | |
7171 string[3] = MOUSE_RELEASE; | |
7172 old_buttons &= ~gpm_event.buttons; | |
7173 break; | |
7174 default: | |
7175 return 0; | |
7176 } | |
7177 /*This code is based on gui_x11_mouse_cb in gui_x11.c */ | |
7178 gpm_modifiers = gpm_event.modifiers; | |
7179 vim_modifiers = 0x0; | |
7180 /* I ignore capslock stats. Aren't we all just hate capslock mixing with | |
7181 * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and | |
7182 * K_CAPSSHIFT is defined 8, so it probably isn't even reported | |
7183 */ | |
7184 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) | |
7185 vim_modifiers |= MOUSE_SHIFT; | |
7186 | |
7187 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL))) | |
7188 vim_modifiers |= MOUSE_CTRL; | |
7189 if (gpm_modifiers & ((1 << KG_ALT) | (1 << KG_ALTGR))) | |
7190 vim_modifiers |= MOUSE_ALT; | |
7191 string[3] |= vim_modifiers; | |
7192 string[4] = (char_u)(col + ' ' + 1); | |
7193 string[5] = (char_u)(row + ' ' + 1); | |
7194 add_to_input_buf(string, 6); | |
7195 return 6; | |
7196 } | |
7197 #endif /* FEAT_MOUSE_GPM */ | |
7198 | |
1620 | 7199 #ifdef FEAT_SYSMOUSE |
7200 /* | |
7201 * Initialize connection with sysmouse. | |
7202 * Let virtual console inform us with SIGUSR2 for pending sysmouse | |
7203 * output, any sysmouse output than will be processed via sig_sysmouse(). | |
7204 * Return OK if succeeded, FAIL if failed. | |
7205 */ | |
7206 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7207 sysmouse_open(void) |
1620 | 7208 { |
7209 struct mouse_info mouse; | |
7210 | |
7211 mouse.operation = MOUSE_MODE; | |
7212 mouse.u.mode.mode = 0; | |
7213 mouse.u.mode.signal = SIGUSR2; | |
7214 if (ioctl(1, CONS_MOUSECTL, &mouse) != -1) | |
7215 { | |
7216 signal(SIGUSR2, (RETSIGTYPE (*)())sig_sysmouse); | |
7217 mouse.operation = MOUSE_SHOW; | |
7218 ioctl(1, CONS_MOUSECTL, &mouse); | |
7219 return OK; | |
7220 } | |
7221 return FAIL; | |
7222 } | |
7223 | |
7224 /* | |
7225 * Stop processing SIGUSR2 signals, and also make sure that | |
7226 * virtual console do not send us any sysmouse related signal. | |
7227 */ | |
7228 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7229 sysmouse_close(void) |
1620 | 7230 { |
7231 struct mouse_info mouse; | |
7232 | |
7233 signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL); | |
7234 mouse.operation = MOUSE_MODE; | |
7235 mouse.u.mode.mode = 0; | |
7236 mouse.u.mode.signal = 0; | |
7237 ioctl(1, CONS_MOUSECTL, &mouse); | |
7238 } | |
7239 | |
7240 /* | |
7241 * Gets info from sysmouse and adds special keys to input buf. | |
7242 */ | |
7243 static RETSIGTYPE | |
7244 sig_sysmouse SIGDEFARG(sigarg) | |
7245 { | |
7246 struct mouse_info mouse; | |
7247 struct video_info video; | |
7248 char_u string[6]; | |
7249 int row, col; | |
7250 int button; | |
7251 int buttons; | |
7252 static int oldbuttons = 0; | |
7253 | |
7254 #ifdef FEAT_GUI | |
7255 /* Don't put events in the input queue now. */ | |
7256 if (hold_gui_events) | |
7257 return; | |
7258 #endif | |
7259 | |
7260 mouse.operation = MOUSE_GETINFO; | |
7261 if (ioctl(1, FBIO_GETMODE, &video.vi_mode) != -1 | |
7262 && ioctl(1, FBIO_MODEINFO, &video) != -1 | |
7263 && ioctl(1, CONS_MOUSECTL, &mouse) != -1 | |
7264 && video.vi_cheight > 0 && video.vi_cwidth > 0) | |
7265 { | |
7266 row = mouse.u.data.y / video.vi_cheight; | |
7267 col = mouse.u.data.x / video.vi_cwidth; | |
7268 buttons = mouse.u.data.buttons; | |
7269 string[0] = ESC; /* Our termcode */ | |
7270 string[1] = 'M'; | |
7271 string[2] = 'S'; | |
7272 if (oldbuttons == buttons && buttons != 0) | |
7273 { | |
7274 button = MOUSE_DRAG; | |
7275 } | |
7276 else | |
7277 { | |
7278 switch (buttons) | |
7279 { | |
7280 case 0: | |
7281 button = MOUSE_RELEASE; | |
7282 break; | |
7283 case 1: | |
7284 button = MOUSE_LEFT; | |
7285 break; | |
7286 case 2: | |
7287 button = MOUSE_MIDDLE; | |
7288 break; | |
7289 case 4: | |
7290 button = MOUSE_RIGHT; | |
7291 break; | |
7292 default: | |
7293 return; | |
7294 } | |
7295 oldbuttons = buttons; | |
7296 } | |
7297 string[3] = (char_u)(button); | |
7298 string[4] = (char_u)(col + ' ' + 1); | |
7299 string[5] = (char_u)(row + ' ' + 1); | |
7300 add_to_input_buf(string, 6); | |
7301 } | |
7302 return; | |
7303 } | |
7304 #endif /* FEAT_SYSMOUSE */ | |
7305 | |
7 | 7306 #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
|
7307 typedef char_u * (*STRPROCSTR)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7308 typedef char_u * (*INTPROCSTR)(int); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7309 typedef int (*STRPROCINT)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7310 typedef int (*INTPROCINT)(int); |
7 | 7311 |
7312 /* | |
7313 * Call a DLL routine which takes either a string or int param | |
7314 * and returns an allocated string. | |
7315 */ | |
7316 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7317 mch_libcall( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7318 char_u *libname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7319 char_u *funcname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7320 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
|
7321 int argint, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7322 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
|
7323 int *number_result) |
7 | 7324 { |
7325 # if defined(USE_DLOPEN) | |
7326 void *hinstLib; | |
12 | 7327 char *dlerr = NULL; |
7 | 7328 # else |
7329 shl_t hinstLib; | |
7330 # endif | |
7331 STRPROCSTR ProcAdd; | |
7332 INTPROCSTR ProcAddI; | |
7333 char_u *retval_str = NULL; | |
7334 int retval_int = 0; | |
7335 int success = FALSE; | |
7336 | |
900 | 7337 /* |
7338 * Get a handle to the DLL module. | |
7339 */ | |
7 | 7340 # if defined(USE_DLOPEN) |
900 | 7341 /* First clear any error, it's not cleared by the dlopen() call. */ |
7342 (void)dlerror(); | |
7343 | |
7 | 7344 hinstLib = dlopen((char *)libname, RTLD_LAZY |
7345 # ifdef RTLD_LOCAL | |
7346 | RTLD_LOCAL | |
7347 # endif | |
7348 ); | |
12 | 7349 if (hinstLib == NULL) |
7350 { | |
7351 /* "dlerr" must be used before dlclose() */ | |
7352 dlerr = (char *)dlerror(); | |
7353 if (dlerr != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
7354 semsg(_("dlerror = \"%s\""), dlerr); |
12 | 7355 } |
7 | 7356 # else |
7357 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); | |
7358 # endif | |
7359 | |
7360 /* If the handle is valid, try to get the function address. */ | |
7361 if (hinstLib != NULL) | |
7362 { | |
7363 # ifdef HAVE_SETJMP_H | |
7364 /* | |
7365 * Catch a crash when calling the library function. For example when | |
7366 * using a number where a string pointer is expected. | |
7367 */ | |
7368 mch_startjmp(); | |
7369 if (SETJMP(lc_jump_env) != 0) | |
7370 { | |
7371 success = FALSE; | |
857 | 7372 # if defined(USE_DLOPEN) |
12 | 7373 dlerr = NULL; |
857 | 7374 # endif |
7 | 7375 mch_didjmp(); |
7376 } | |
7377 else | |
7378 # endif | |
7379 { | |
7380 retval_str = NULL; | |
7381 retval_int = 0; | |
7382 | |
7383 if (argstring != NULL) | |
7384 { | |
7385 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7386 *(void **)(&ProcAdd) = dlsym(hinstLib, (const char *)funcname); |
12 | 7387 dlerr = (char *)dlerror(); |
7 | 7388 # else |
7389 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7390 TYPE_PROCEDURE, (void *)&ProcAdd) < 0) | |
7391 ProcAdd = NULL; | |
7392 # endif | |
12 | 7393 if ((success = (ProcAdd != NULL |
7394 # if defined(USE_DLOPEN) | |
7395 && dlerr == NULL | |
7396 # endif | |
7397 ))) | |
7 | 7398 { |
7399 if (string_result == NULL) | |
7400 retval_int = ((STRPROCINT)ProcAdd)(argstring); | |
7401 else | |
7402 retval_str = (ProcAdd)(argstring); | |
7403 } | |
7404 } | |
7405 else | |
7406 { | |
7407 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7408 *(void **)(&ProcAddI) = dlsym(hinstLib, (const char *)funcname); |
12 | 7409 dlerr = (char *)dlerror(); |
7 | 7410 # else |
7411 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7412 TYPE_PROCEDURE, (void *)&ProcAddI) < 0) | |
7413 ProcAddI = NULL; | |
7414 # endif | |
12 | 7415 if ((success = (ProcAddI != NULL |
7416 # if defined(USE_DLOPEN) | |
7417 && dlerr == NULL | |
7418 # endif | |
7419 ))) | |
7 | 7420 { |
7421 if (string_result == NULL) | |
7422 retval_int = ((INTPROCINT)ProcAddI)(argint); | |
7423 else | |
7424 retval_str = (ProcAddI)(argint); | |
7425 } | |
7426 } | |
7427 | |
7428 /* Save the string before we free the library. */ | |
7429 /* Assume that a "1" or "-1" result is an illegal pointer. */ | |
7430 if (string_result == NULL) | |
7431 *number_result = retval_int; | |
7432 else if (retval_str != NULL | |
7433 && retval_str != (char_u *)1 | |
7434 && retval_str != (char_u *)-1) | |
7435 *string_result = vim_strsave(retval_str); | |
7436 } | |
7437 | |
7438 # ifdef HAVE_SETJMP_H | |
7439 mch_endjmp(); | |
7440 # ifdef SIGHASARG | |
7441 if (lc_signal != 0) | |
7442 { | |
7443 int i; | |
7444 | |
7445 /* try to find the name of this signal */ | |
7446 for (i = 0; signal_info[i].sig != -1; i++) | |
7447 if (lc_signal == signal_info[i].sig) | |
7448 break; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
7449 semsg("E368: got SIG%s in libcall()", signal_info[i].name); |
7 | 7450 } |
7451 # endif | |
7452 # endif | |
7453 | |
12 | 7454 # if defined(USE_DLOPEN) |
7455 /* "dlerr" must be used before dlclose() */ | |
7456 if (dlerr != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
7457 semsg(_("dlerror = \"%s\""), dlerr); |
12 | 7458 |
7 | 7459 /* Free the DLL module. */ |
7460 (void)dlclose(hinstLib); | |
7461 # else | |
7462 (void)shl_unload(hinstLib); | |
7463 # endif | |
7464 } | |
7465 | |
7466 if (!success) | |
7467 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15306
diff
changeset
|
7468 semsg(_(e_libcall), funcname); |
7 | 7469 return FAIL; |
7470 } | |
7471 | |
7472 return OK; | |
7473 } | |
7474 #endif | |
7475 | |
7476 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) | |
7477 static int xterm_trace = -1; /* default: disabled */ | |
7478 static int xterm_button; | |
7479 | |
7480 /* | |
7481 * Setup a dummy window for X selections in a terminal. | |
7482 */ | |
7483 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7484 setup_term_clip(void) |
7 | 7485 { |
7486 int z = 0; | |
7487 char *strp = ""; | |
7488 Widget AppShell; | |
7489 | |
7490 if (!x_connect_to_server()) | |
7491 return; | |
7492 | |
7493 open_app_context(); | |
7494 if (app_context != NULL && xterm_Shell == (Widget)0) | |
7495 { | |
7496 int (*oldhandler)(); | |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7497 # if defined(HAVE_SETJMP_H) |
7 | 7498 int (*oldIOhandler)(); |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7499 # endif |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7500 # ifdef ELAPSED_FUNC |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7501 elapsed_T start_tv; |
7 | 7502 |
7503 if (p_verbose > 0) | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7504 ELAPSED_INIT(start_tv); |
7 | 7505 # endif |
7506 | |
7507 /* Ignore X errors while opening the display */ | |
7508 oldhandler = XSetErrorHandler(x_error_check); | |
7509 | |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7510 # if defined(HAVE_SETJMP_H) |
7 | 7511 /* Ignore X IO errors while opening the display */ |
7512 oldIOhandler = XSetIOErrorHandler(x_IOerror_check); | |
7513 mch_startjmp(); | |
7514 if (SETJMP(lc_jump_env) != 0) | |
7515 { | |
7516 mch_didjmp(); | |
7517 xterm_dpy = NULL; | |
7518 } | |
7519 else | |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7520 # endif |
7 | 7521 { |
7522 xterm_dpy = XtOpenDisplay(app_context, xterm_display, | |
7523 "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
7524 if (xterm_dpy != NULL) |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15123
diff
changeset
|
7525 xterm_dpy_retry_count = 0; |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7526 # if defined(HAVE_SETJMP_H) |
7 | 7527 mch_endjmp(); |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7528 # endif |
7 | 7529 } |
7530 | |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7531 # if defined(HAVE_SETJMP_H) |
7 | 7532 /* Now handle X IO errors normally. */ |
7533 (void)XSetIOErrorHandler(oldIOhandler); | |
15559
59d32a45da1a
patch 8.1.0787: compiler warning for unused function
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7534 # endif |
7 | 7535 /* Now handle X errors normally. */ |
7536 (void)XSetErrorHandler(oldhandler); | |
7537 | |
7538 if (xterm_dpy == NULL) | |
7539 { | |
7540 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
7541 verb_msg(_("Opening the X display failed")); |
7 | 7542 return; |
7543 } | |
7544 | |
7545 /* Catch terminating error of the X server connection. */ | |
7546 (void)XSetIOErrorHandler(x_IOerror_handler); | |
7547 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7548 # ifdef ELAPSED_FUNC |
7 | 7549 if (p_verbose > 0) |
292 | 7550 { |
7551 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7552 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 7553 verbose_leave(); |
7554 } | |
7 | 7555 # endif |
7556 | |
7557 /* Create a Shell to make converters work. */ | |
7558 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", | |
7559 applicationShellWidgetClass, xterm_dpy, | |
7560 NULL); | |
7561 if (AppShell == (Widget)0) | |
7562 return; | |
7563 xterm_Shell = XtVaCreatePopupShell("VIM", | |
7564 topLevelShellWidgetClass, AppShell, | |
7565 XtNmappedWhenManaged, 0, | |
7566 XtNwidth, 1, | |
7567 XtNheight, 1, | |
7568 NULL); | |
7569 if (xterm_Shell == (Widget)0) | |
7570 return; | |
7571 | |
7572 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
|
7573 x11_setup_selection(xterm_Shell); |
7 | 7574 if (x11_display == NULL) |
7575 x11_display = xterm_dpy; | |
7576 | |
7577 XtRealizeWidget(xterm_Shell); | |
7578 XSync(xterm_dpy, False); | |
7579 xterm_update(); | |
7580 } | |
7581 if (xterm_Shell != (Widget)0) | |
7582 { | |
7583 clip_init(TRUE); | |
7584 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) | |
7585 x11_window = (Window)atol(strp); | |
7586 /* Check if $WINDOWID is valid. */ | |
7587 if (test_x11_window(xterm_dpy) == FAIL) | |
7588 x11_window = 0; | |
7589 if (x11_window != 0) | |
7590 xterm_trace = 0; | |
7591 } | |
7592 } | |
7593 | |
7594 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7595 start_xterm_trace(int button) |
7 | 7596 { |
7597 if (x11_window == 0 || xterm_trace < 0 || xterm_Shell == (Widget)0) | |
7598 return; | |
7599 xterm_trace = 1; | |
7600 xterm_button = button; | |
7601 do_xterm_trace(); | |
7602 } | |
7603 | |
7604 | |
7605 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7606 stop_xterm_trace(void) |
7 | 7607 { |
7608 if (xterm_trace < 0) | |
7609 return; | |
7610 xterm_trace = 0; | |
7611 } | |
7612 | |
7613 /* | |
7614 * Query the xterm pointer and generate mouse termcodes if necessary | |
7615 * return TRUE if dragging is active, else FALSE | |
7616 */ | |
7617 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7618 do_xterm_trace(void) |
7 | 7619 { |
7620 Window root, child; | |
7621 int root_x, root_y; | |
7622 int win_x, win_y; | |
7623 int row, col; | |
7624 int_u mask_return; | |
7625 char_u buf[50]; | |
7626 char_u *strp; | |
7627 long got_hints; | |
7628 static char_u *mouse_code; | |
7629 static char_u mouse_name[2] = {KS_MOUSE, KE_FILLER}; | |
7630 static int prev_row = 0, prev_col = 0; | |
7631 static XSizeHints xterm_hints; | |
7632 | |
7633 if (xterm_trace <= 0) | |
7634 return FALSE; | |
7635 | |
7636 if (xterm_trace == 1) | |
7637 { | |
7638 /* Get the hints just before tracking starts. The font size might | |
1510 | 7639 * have changed recently. */ |
7640 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) | |
7641 || !(got_hints & PResizeInc) | |
7 | 7642 || xterm_hints.width_inc <= 1 |
7643 || xterm_hints.height_inc <= 1) | |
7644 { | |
7645 xterm_trace = -1; /* Not enough data -- disable tracing */ | |
7646 return FALSE; | |
7647 } | |
7648 | |
7649 /* Rely on the same mouse code for the duration of this */ | |
7650 mouse_code = find_termcode(mouse_name); | |
7651 prev_row = mouse_row; | |
7009 | 7652 prev_col = mouse_col; |
7 | 7653 xterm_trace = 2; |
7654 | |
7655 /* Find the offset of the chars, there might be a scrollbar on the | |
7656 * left of the window and/or a menu on the top (eterm etc.) */ | |
7657 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7658 &win_x, &win_y, &mask_return); | |
7659 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) | |
7660 - (xterm_hints.height_inc / 2); | |
7661 if (xterm_hints.y <= xterm_hints.height_inc / 2) | |
7662 xterm_hints.y = 2; | |
7663 xterm_hints.x = win_x - (xterm_hints.width_inc * mouse_col) | |
7664 - (xterm_hints.width_inc / 2); | |
7665 if (xterm_hints.x <= xterm_hints.width_inc / 2) | |
7666 xterm_hints.x = 2; | |
7667 return TRUE; | |
7668 } | |
2768 | 7669 if (mouse_code == NULL || STRLEN(mouse_code) > 45) |
7 | 7670 { |
7671 xterm_trace = 0; | |
7672 return FALSE; | |
7673 } | |
7674 | |
7675 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7676 &win_x, &win_y, &mask_return); | |
7677 | |
7678 row = check_row((win_y - xterm_hints.y) / xterm_hints.height_inc); | |
7679 col = check_col((win_x - xterm_hints.x) / xterm_hints.width_inc); | |
7680 if (row == prev_row && col == prev_col) | |
7681 return TRUE; | |
7682 | |
7683 STRCPY(buf, mouse_code); | |
7684 strp = buf + STRLEN(buf); | |
7685 *strp++ = (xterm_button | MOUSE_DRAG) & ~0x20; | |
7686 *strp++ = (char_u)(col + ' ' + 1); | |
7687 *strp++ = (char_u)(row + ' ' + 1); | |
7688 *strp = 0; | |
7689 add_to_input_buf(buf, STRLEN(buf)); | |
7690 | |
7691 prev_row = row; | |
7692 prev_col = col; | |
7693 return TRUE; | |
7694 } | |
7695 | |
7696 # if defined(FEAT_GUI) || defined(PROTO) | |
7697 /* | |
7698 * Destroy the display, window and app_context. Required for GTK. | |
7699 */ | |
7700 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7701 clear_xterm_clip(void) |
7 | 7702 { |
7703 if (xterm_Shell != (Widget)0) | |
7704 { | |
7705 XtDestroyWidget(xterm_Shell); | |
7706 xterm_Shell = (Widget)0; | |
7707 } | |
7708 if (xterm_dpy != NULL) | |
7709 { | |
1605 | 7710 # if 0 |
7 | 7711 /* Lesstif and Solaris crash here, lose some memory */ |
7712 XtCloseDisplay(xterm_dpy); | |
1605 | 7713 # endif |
7 | 7714 if (x11_display == xterm_dpy) |
7715 x11_display = NULL; | |
7716 xterm_dpy = NULL; | |
7717 } | |
1605 | 7718 # if 0 |
7 | 7719 if (app_context != (XtAppContext)NULL) |
7720 { | |
7721 /* Lesstif and Solaris crash here, lose some memory */ | |
7722 XtDestroyApplicationContext(app_context); | |
7723 app_context = (XtAppContext)NULL; | |
7724 } | |
1605 | 7725 # endif |
7 | 7726 } |
7727 # endif | |
7728 | |
7729 /* | |
4230 | 7730 * Catch up with GUI or X events. |
7731 */ | |
7732 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7733 clip_update(void) |
4230 | 7734 { |
7735 # ifdef FEAT_GUI | |
7736 if (gui.in_use) | |
7737 gui_mch_update(); | |
7738 else | |
7739 # endif | |
7740 if (xterm_Shell != (Widget)0) | |
7741 xterm_update(); | |
7742 } | |
7743 | |
7744 /* | |
7 | 7745 * Catch up with any queued X events. This may put keyboard input into the |
7746 * input buffer, call resize call-backs, trigger timers etc. If there is | |
7747 * nothing in the X event queue (& no timers pending), then we return | |
7748 * immediately. | |
7749 */ | |
7750 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7751 xterm_update(void) |
7 | 7752 { |
7753 XEvent event; | |
7754 | |
6683 | 7755 for (;;) |
7 | 7756 { |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7757 XtInputMask mask = XtAppPending(app_context); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7758 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7759 if (mask == 0 || vim_is_input_buf_full()) |
6683 | 7760 break; |
7761 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7762 if (mask & XtIMXEvent) |
7 | 7763 { |
6683 | 7764 /* 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
|
7765 XtAppNextEvent(app_context, &event); |
6683 | 7766 #ifdef FEAT_CLIENTSERVER |
7767 { | |
7768 XPropertyEvent *e = (XPropertyEvent *)&event; | |
7769 | |
7770 if (e->type == PropertyNotify && e->window == commWindow | |
7 | 7771 && 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
|
7772 serverEventProc(xterm_dpy, &event, 0); |
6683 | 7773 } |
7774 #endif | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7775 XtDispatchEvent(&event); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7776 } |
6683 | 7777 else |
7778 { | |
7779 /* 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
|
7780 XtAppProcessEvent(app_context, mask); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7781 } |
7 | 7782 } |
7783 } | |
7784 | |
7785 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7786 clip_xterm_own_selection(VimClipboard *cbd) |
7 | 7787 { |
7788 if (xterm_Shell != (Widget)0) | |
7789 return clip_x11_own_selection(xterm_Shell, cbd); | |
7790 return FAIL; | |
7791 } | |
7792 | |
7793 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7794 clip_xterm_lose_selection(VimClipboard *cbd) |
7 | 7795 { |
7796 if (xterm_Shell != (Widget)0) | |
7797 clip_x11_lose_selection(xterm_Shell, cbd); | |
7798 } | |
7799 | |
7800 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7801 clip_xterm_request_selection(VimClipboard *cbd) |
7 | 7802 { |
7803 if (xterm_Shell != (Widget)0) | |
7804 clip_x11_request_selection(xterm_Shell, xterm_dpy, cbd); | |
7805 } | |
7806 | |
7807 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7808 clip_xterm_set_selection(VimClipboard *cbd) |
7 | 7809 { |
7810 clip_x11_set_selection(cbd); | |
7811 } | |
7812 #endif | |
7813 | |
7814 | |
7815 #if defined(USE_XSMP) || defined(PROTO) | |
7816 /* | |
7817 * Code for X Session Management Protocol. | |
7818 */ | |
7819 | |
7820 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7821 /* | |
7822 * This is our chance to ask the user if they want to save, | |
7823 * or abort the logout | |
7824 */ | |
7825 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7826 xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data UNUSED) |
7 | 7827 { |
7828 cmdmod_T save_cmdmod; | |
7829 int cancel_shutdown = False; | |
7830 | |
7831 save_cmdmod = cmdmod; | |
7832 cmdmod.confirm = TRUE; | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7420
diff
changeset
|
7833 if (check_changed_any(FALSE, FALSE)) |
7 | 7834 /* Mustn't logout */ |
7835 cancel_shutdown = True; | |
7836 cmdmod = save_cmdmod; | |
7837 setcursor(); /* position cursor */ | |
7838 out_flush(); | |
7839 | |
7840 /* Done interaction */ | |
7841 SmcInteractDone(smc_conn, cancel_shutdown); | |
7842 | |
7843 /* Finish off | |
7844 * Only end save-yourself here if we're not cancelling shutdown; | |
7845 * we'll get a cancelled callback later in which we'll end it. | |
7846 * Hopefully get around glitchy SMs (like GNOME-1) | |
7847 */ | |
7848 if (!cancel_shutdown) | |
7849 { | |
7850 xsmp.save_yourself = False; | |
7851 SmcSaveYourselfDone(smc_conn, True); | |
7852 } | |
7853 } | |
7854 # endif | |
7855 | |
7856 /* | |
7857 * Callback that starts save-yourself. | |
7858 */ | |
7859 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7860 xsmp_handle_save_yourself( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7861 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7862 SmPointer client_data UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7863 int save_type UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7864 Bool shutdown, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7865 int interact_style UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7866 Bool fast UNUSED) |
7 | 7867 { |
7868 /* Handle already being in saveyourself */ | |
7869 if (xsmp.save_yourself) | |
7870 SmcSaveYourselfDone(smc_conn, True); | |
7871 xsmp.save_yourself = True; | |
7872 xsmp.shutdown = shutdown; | |
7873 | |
7874 /* First up, preserve all files */ | |
7875 out_flush(); | |
7876 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
7877 | |
7878 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
7879 verb_msg(_("XSMP handling save-yourself request")); |
7 | 7880 |
7881 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7882 /* Now see if we can ask about unsaved files */ | |
7883 if (shutdown && !fast && gui.in_use) | |
7884 /* Need to interact with user, but need SM's permission */ | |
7885 SmcInteractRequest(smc_conn, SmDialogError, | |
7886 xsmp_handle_interaction, client_data); | |
7887 else | |
7888 # endif | |
7889 { | |
7890 /* Can stop the cycle here */ | |
7891 SmcSaveYourselfDone(smc_conn, True); | |
7892 xsmp.save_yourself = False; | |
7893 } | |
7894 } | |
7895 | |
7896 | |
7897 /* | |
7898 * Callback to warn us of imminent death. | |
7899 */ | |
7900 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7901 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED) |
7 | 7902 { |
7903 xsmp_close(); | |
7904 | |
7905 /* quit quickly leaving swapfiles for modified buffers behind */ | |
7906 getout_preserve_modified(0); | |
7907 } | |
7908 | |
7909 | |
7910 /* | |
7911 * Callback to tell us that save-yourself has completed. | |
7912 */ | |
7913 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7914 xsmp_save_complete( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7915 SmcConn smc_conn UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7916 SmPointer client_data UNUSED) |
7 | 7917 { |
7918 xsmp.save_yourself = False; | |
7919 } | |
7920 | |
7921 | |
7922 /* | |
7923 * Callback to tell us that an instigated shutdown was cancelled | |
7924 * (maybe even by us) | |
7925 */ | |
7926 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7927 xsmp_shutdown_cancelled( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7928 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7929 SmPointer client_data UNUSED) |
7 | 7930 { |
7931 if (xsmp.save_yourself) | |
7932 SmcSaveYourselfDone(smc_conn, True); | |
7933 xsmp.save_yourself = False; | |
7934 xsmp.shutdown = False; | |
7935 } | |
7936 | |
7937 | |
7938 /* | |
7939 * Callback to tell us that a new ICE connection has been established. | |
7940 */ | |
7941 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7942 xsmp_ice_connection( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7943 IceConn iceConn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7944 IcePointer clientData UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7945 Bool opening, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7946 IcePointer *watchData UNUSED) |
7 | 7947 { |
7948 /* Intercept creation of ICE connection fd */ | |
7949 if (opening) | |
7950 { | |
7951 xsmp_icefd = IceConnectionNumber(iceConn); | |
7952 IceRemoveConnectionWatch(xsmp_ice_connection, NULL); | |
7953 } | |
7954 } | |
7955 | |
7956 | |
7957 /* Handle any ICE processing that's required; return FAIL if SM lost */ | |
7958 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7959 xsmp_handle_requests(void) |
7 | 7960 { |
7961 Bool rep; | |
7962 | |
7963 if (IceProcessMessages(xsmp.iceconn, NULL, &rep) | |
7964 == IceProcessMessagesIOError) | |
7965 { | |
7966 /* Lost ICE */ | |
7967 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
7968 verb_msg(_("XSMP lost ICE connection")); |
7 | 7969 xsmp_close(); |
7970 return FAIL; | |
7971 } | |
7972 else | |
7973 return OK; | |
7974 } | |
7975 | |
7976 static int dummy; | |
7977 | |
7978 /* Set up X Session Management Protocol */ | |
7979 void | |
7980 xsmp_init(void) | |
7981 { | |
7982 char errorstring[80]; | |
7983 SmcCallbacks smcallbacks; | |
7984 #if 0 | |
7985 SmPropValue smname; | |
7986 SmProp smnameprop; | |
7987 SmProp *smprops[1]; | |
7988 #endif | |
7989 | |
7990 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
7991 verb_msg(_("XSMP opening connection")); |
7 | 7992 |
7993 xsmp.save_yourself = xsmp.shutdown = False; | |
7994 | |
7995 /* Set up SM callbacks - must have all, even if they're not used */ | |
7996 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; | |
7997 smcallbacks.save_yourself.client_data = NULL; | |
7998 smcallbacks.die.callback = xsmp_die; | |
7999 smcallbacks.die.client_data = NULL; | |
8000 smcallbacks.save_complete.callback = xsmp_save_complete; | |
8001 smcallbacks.save_complete.client_data = NULL; | |
8002 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; | |
8003 smcallbacks.shutdown_cancelled.client_data = NULL; | |
8004 | |
8005 /* Set up a watch on ICE connection creations. The "dummy" argument is | |
8006 * apparently required for FreeBSD (we get a BUS error when using NULL). */ | |
8007 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) | |
8008 { | |
8009 if (p_verbose > 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
8010 verb_msg(_("XSMP ICE connection watch failed")); |
7 | 8011 return; |
8012 } | |
8013 | |
8014 /* Create an SM connection */ | |
8015 xsmp.smcconn = SmcOpenConnection( | |
8016 NULL, | |
8017 NULL, | |
8018 SmProtoMajor, | |
8019 SmProtoMinor, | |
8020 SmcSaveYourselfProcMask | SmcDieProcMask | |
8021 | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
8022 &smcallbacks, | |
8023 NULL, | |
1605 | 8024 &xsmp.clientid, |
14828
421e120ffb30
patch 8.1.0426: accessing invalid memory in SmcOpenConnection()
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
8025 sizeof(errorstring) - 1, |
7 | 8026 errorstring); |
8027 if (xsmp.smcconn == NULL) | |
8028 { | |
8029 char errorreport[132]; | |
273 | 8030 |
292 | 8031 if (p_verbose > 0) |
8032 { | |
8033 vim_snprintf(errorreport, sizeof(errorreport), | |
273 | 8034 _("XSMP SmcOpenConnection failed: %s"), errorstring); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
8035 verb_msg(errorreport); |
292 | 8036 } |
7 | 8037 return; |
8038 } | |
8039 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); | |
8040 | |
8041 #if 0 | |
8042 /* ID ourselves */ | |
8043 smname.value = "vim"; | |
8044 smname.length = 3; | |
8045 smnameprop.name = "SmProgram"; | |
8046 smnameprop.type = "SmARRAY8"; | |
8047 smnameprop.num_vals = 1; | |
8048 smnameprop.vals = &smname; | |
8049 | |
8050 smprops[0] = &smnameprop; | |
8051 SmcSetProperties(xsmp.smcconn, 1, smprops); | |
8052 #endif | |
8053 } | |
8054 | |
8055 | |
8056 /* Shut down XSMP comms. */ | |
8057 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8058 xsmp_close(void) |
7 | 8059 { |
8060 if (xsmp_icefd != -1) | |
8061 { | |
8062 SmcCloseConnection(xsmp.smcconn, 0, NULL); | |
1737 | 8063 if (xsmp.clientid != NULL) |
8064 free(xsmp.clientid); | |
1605 | 8065 xsmp.clientid = NULL; |
7 | 8066 xsmp_icefd = -1; |
8067 } | |
8068 } | |
8069 #endif /* USE_XSMP */ | |
8070 | |
8071 | |
8072 #ifdef EBCDIC | |
8073 /* Translate character to its CTRL- value */ | |
8074 char CtrlTable[] = | |
8075 { | |
8076 /* 00 - 5E */ | |
8077 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8078 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8079 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8080 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8081 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8082 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8083 /* ^ */ 0x1E, | |
8084 /* - */ 0x1F, | |
8085 /* 61 - 6C */ | |
8086 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8087 /* _ */ 0x1F, | |
8088 /* 6E - 80 */ | |
8089 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8090 /* a */ 0x01, | |
8091 /* b */ 0x02, | |
8092 /* c */ 0x03, | |
8093 /* d */ 0x37, | |
8094 /* e */ 0x2D, | |
8095 /* f */ 0x2E, | |
8096 /* g */ 0x2F, | |
8097 /* h */ 0x16, | |
8098 /* i */ 0x05, | |
8099 /* 8A - 90 */ | |
8100 0, 0, 0, 0, 0, 0, 0, | |
8101 /* j */ 0x15, | |
8102 /* k */ 0x0B, | |
8103 /* l */ 0x0C, | |
8104 /* m */ 0x0D, | |
8105 /* n */ 0x0E, | |
8106 /* o */ 0x0F, | |
8107 /* p */ 0x10, | |
8108 /* q */ 0x11, | |
8109 /* r */ 0x12, | |
8110 /* 9A - A1 */ | |
8111 0, 0, 0, 0, 0, 0, 0, 0, | |
8112 /* s */ 0x13, | |
8113 /* t */ 0x3C, | |
8114 /* u */ 0x3D, | |
8115 /* v */ 0x32, | |
8116 /* w */ 0x26, | |
8117 /* x */ 0x18, | |
8118 /* y */ 0x19, | |
8119 /* z */ 0x3F, | |
8120 /* AA - AC */ | |
8121 0, 0, 0, | |
8122 /* [ */ 0x27, | |
8123 /* AE - BC */ | |
8124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8125 /* ] */ 0x1D, | |
8126 /* BE - C0 */ 0, 0, 0, | |
8127 /* A */ 0x01, | |
8128 /* B */ 0x02, | |
8129 /* C */ 0x03, | |
8130 /* D */ 0x37, | |
8131 /* E */ 0x2D, | |
8132 /* F */ 0x2E, | |
8133 /* G */ 0x2F, | |
8134 /* H */ 0x16, | |
8135 /* I */ 0x05, | |
8136 /* CA - D0 */ 0, 0, 0, 0, 0, 0, 0, | |
8137 /* J */ 0x15, | |
8138 /* K */ 0x0B, | |
8139 /* L */ 0x0C, | |
8140 /* M */ 0x0D, | |
8141 /* N */ 0x0E, | |
8142 /* O */ 0x0F, | |
8143 /* P */ 0x10, | |
8144 /* Q */ 0x11, | |
8145 /* R */ 0x12, | |
8146 /* DA - DF */ 0, 0, 0, 0, 0, 0, | |
8147 /* \ */ 0x1C, | |
8148 /* E1 */ 0, | |
8149 /* S */ 0x13, | |
8150 /* T */ 0x3C, | |
8151 /* U */ 0x3D, | |
8152 /* V */ 0x32, | |
8153 /* W */ 0x26, | |
8154 /* X */ 0x18, | |
8155 /* Y */ 0x19, | |
8156 /* Z */ 0x3F, | |
8157 /* EA - FF*/ 0, 0, 0, 0, 0, 0, | |
8158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
8159 }; | |
8160 | |
8161 char MetaCharTable[]= | |
8162 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
8163 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, | |
8164 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, | |
8165 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, | |
8166 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0 | |
8167 }; | |
8168 | |
8169 | |
8170 /* TODO: Use characters NOT numbers!!! */ | |
8171 char CtrlCharTable[]= | |
8172 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
8173 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, | |
8174 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, | |
8175 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, | |
8176 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233, | |
8177 }; | |
8178 | |
8179 | |
8180 #endif |