Mercurial > vim
annotate src/os_unix.c @ 11981:cf36b424ea03 v8.0.0871
patch 8.0.0871: status line for a terminal window always has "[+]".
commit https://github.com/vim/vim/commit/086d535f775da1abc557f5f28d101ff3308dc18f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 5 18:19:55 2017 +0200
patch 8.0.0871: status line for a terminal window always has "[+]".
Problem: The status line for a terminal window always has "[+]".
Solution: Do make the status line include "[+]" for a terminal window.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 05 Aug 2017 18:30:04 +0200 |
parents | 74e45c11b754 |
children | 85f0f557661e |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10019
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * OS/2 port by Paul Slootman | |
5 * VMS merge by Zoltan Arpadffy | |
6 * | |
7 * Do ":help uganda" in Vim to read copying and usage conditions. | |
8 * Do ":help credits" in Vim to see a list of people who contributed. | |
9 * See README.txt for an overview of the Vim source code. | |
10 */ | |
11 | |
12 /* | |
13 * os_unix.c -- code for all flavors of Unix (BSD, SYSV, SVR4, POSIX, ...) | |
14 * Also for OS/2, using the excellent EMX package!!! | |
15 * Also for BeOS and Atari MiNT. | |
16 * | |
17 * A lot of this file was originally written by Juergen Weigert and later | |
18 * changed beyond recognition. | |
19 */ | |
20 | |
21 /* | |
22 * Some systems have a prototype for select() that has (int *) instead of | |
23 * (fd_set *), which is wrong. This define removes that prototype. We define | |
24 * our own prototype below. | |
25 * Don't use it for the Mac, it causes a warning for precompiled headers. | |
26 * TODO: use a configure check for precompiled headers? | |
27 */ | |
1076 | 28 #if !defined(__APPLE__) && !defined(__TANDEM) |
7 | 29 # define select select_declared_wrong |
30 #endif | |
31 | |
32 #include "vim.h" | |
33 | |
14 | 34 #ifdef FEAT_MZSCHEME |
35 # include "if_mzsch.h" | |
36 #endif | |
37 | |
7 | 38 #include "os_unixx.h" /* unix includes for os_unix.c only */ |
39 | |
40 #ifdef USE_XSMP | |
41 # include <X11/SM/SMlib.h> | |
42 #endif | |
43 | |
1583 | 44 #ifdef HAVE_SELINUX |
45 # include <selinux/selinux.h> | |
46 static int selinux_enabled = -1; | |
47 #endif | |
48 | |
5788 | 49 #ifdef HAVE_SMACK |
50 # include <attr/xattr.h> | |
51 # include <linux/xattr.h> | |
52 # ifndef SMACK_LABEL_LEN | |
53 # define SMACK_LABEL_LEN 1024 | |
54 # endif | |
55 #endif | |
56 | |
7 | 57 /* |
58 * Use this prototype for select, some include files have a wrong prototype | |
59 */ | |
1076 | 60 #ifndef __TANDEM |
61 # undef select | |
62 # ifdef __BEOS__ | |
63 # define select beos_select | |
64 # endif | |
7 | 65 #endif |
66 | |
1102 | 67 #ifdef __CYGWIN__ |
68 # ifndef WIN32 | |
1657 | 69 # include <cygwin/version.h> |
70 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or | |
71 * for cygwin_conv_path() */ | |
4168 | 72 # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
73 # define WIN32_LEAN_AND_MEAN | |
74 # include <windows.h> | |
75 # include "winclip.pro" | |
76 # endif | |
1102 | 77 # endif |
78 #endif | |
79 | |
7 | 80 #if defined(HAVE_SELECT) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
81 extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); |
7 | 82 #endif |
83 | |
84 #ifdef FEAT_MOUSE_GPM | |
85 # include <gpm.h> | |
86 /* <linux/keyboard.h> contains defines conflicting with "keymap.h", | |
87 * I just copied relevant defines here. A cleaner solution would be to put gpm | |
88 * code into separate file and include there linux/keyboard.h | |
89 */ | |
90 /* #include <linux/keyboard.h> */ | |
91 # define KG_SHIFT 0 | |
92 # define KG_CTRL 2 | |
93 # define KG_ALT 3 | |
94 # define KG_ALTGR 1 | |
95 # define KG_SHIFTL 4 | |
96 # define KG_SHIFTR 5 | |
97 # define KG_CTRLL 6 | |
98 # define KG_CTRLR 7 | |
99 # define KG_CAPSSHIFT 8 | |
100 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
101 static void gpm_close(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
102 static int gpm_open(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
103 static int mch_gpm_process(void); |
7 | 104 #endif |
105 | |
1620 | 106 #ifdef FEAT_SYSMOUSE |
107 # include <sys/consio.h> | |
108 # include <sys/fbio.h> | |
109 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
110 static int sysmouse_open(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
111 static void sysmouse_close(void); |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
112 static RETSIGTYPE sig_sysmouse SIGPROTOARG; |
1620 | 113 #endif |
114 | |
7 | 115 /* |
116 * end of autoconf section. To be extended... | |
117 */ | |
118 | |
119 /* Are the following #ifdefs still required? And why? Is that for X11? */ | |
120 | |
121 #if defined(ESIX) || defined(M_UNIX) && !defined(SCO) | |
122 # ifdef SIGWINCH | |
123 # undef SIGWINCH | |
124 # endif | |
125 # ifdef TIOCGWINSZ | |
126 # undef TIOCGWINSZ | |
127 # endif | |
128 #endif | |
129 | |
130 #if defined(SIGWINDOW) && !defined(SIGWINCH) /* hpux 9.01 has it */ | |
131 # define SIGWINCH SIGWINDOW | |
132 #endif | |
133 | |
134 #ifdef FEAT_X11 | |
135 # include <X11/Xlib.h> | |
136 # include <X11/Xutil.h> | |
137 # include <X11/Xatom.h> | |
138 # ifdef FEAT_XCLIPBOARD | |
139 # include <X11/Intrinsic.h> | |
140 # include <X11/Shell.h> | |
141 # include <X11/StringDefs.h> | |
142 static Widget xterm_Shell = (Widget)0; | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
143 static void clip_update(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
144 static void xterm_update(void); |
7 | 145 # endif |
146 | |
147 # if defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE) | |
148 Window x11_window = 0; | |
149 # endif | |
150 Display *x11_display = NULL; | |
151 | |
152 # ifdef FEAT_TITLE | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
153 static int get_x11_windis(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
154 static void set_x11_title(char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
155 static void set_x11_icon(char_u *); |
7 | 156 # endif |
157 #endif | |
158 | |
159 #ifdef FEAT_TITLE | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
160 static int get_x11_title(int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
161 static int get_x11_icon(int); |
7 | 162 |
163 static char_u *oldtitle = NULL; | |
164 static int did_set_title = FALSE; | |
165 static char_u *oldicon = NULL; | |
166 static int did_set_icon = FALSE; | |
167 #endif | |
168 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
169 static void may_core_dump(void); |
7 | 170 |
3048 | 171 #ifdef HAVE_UNION_WAIT |
172 typedef union wait waitstatus; | |
173 #else | |
174 typedef int waitstatus; | |
175 #endif | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
176 static pid_t wait4pid(pid_t, waitstatus *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
177 |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
178 static int WaitForChar(long msec, int *interrupted, int ignore_input); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
179 static int WaitForCharOrMouse(long msec, int *interrupted, int ignore_input); |
5541 | 180 #if defined(__BEOS__) || defined(VMS) |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
181 int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 182 #else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
183 static int RealWaitForChar(int, long, int *, int *interrupted); |
7 | 184 #endif |
185 | |
186 #ifdef FEAT_XCLIPBOARD | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
187 static int do_xterm_trace(void); |
331 | 188 # define XT_TRACE_DELAY 50 /* delay for xterm tracing */ |
7 | 189 #endif |
190 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
191 static void handle_resize(void); |
7 | 192 |
193 #if defined(SIGWINCH) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
194 static RETSIGTYPE sig_winch SIGPROTOARG; |
7 | 195 #endif |
196 #if defined(SIGINT) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
197 static RETSIGTYPE catch_sigint SIGPROTOARG; |
7 | 198 #endif |
199 #if defined(SIGPWR) | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
200 static RETSIGTYPE catch_sigpwr SIGPROTOARG; |
7 | 201 #endif |
202 #if defined(SIGALRM) && defined(FEAT_X11) \ | |
203 && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) | |
204 # define SET_SIG_ALARM | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
205 static RETSIGTYPE sig_alarm SIGPROTOARG; |
1832 | 206 /* volatile because it is used in signal handler sig_alarm(). */ |
207 static volatile int sig_alarm_called; | |
7 | 208 #endif |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
209 static RETSIGTYPE deathtrap SIGPROTOARG; |
7 | 210 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
211 static void catch_int_signal(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
212 static void set_signals(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
213 static void catch_signals(RETSIGTYPE (*func_deadly)(), RETSIGTYPE (*func_other)()); |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
214 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
215 # define SIGSET_DECL(set) sigset_t set; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
216 # define BLOCK_SIGNALS(set) block_signals(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
217 # define UNBLOCK_SIGNALS(set) unblock_signals(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
218 #else |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
219 # define SIGSET_DECL(set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
220 # define BLOCK_SIGNALS(set) do { /**/ } while (0) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
221 # define UNBLOCK_SIGNALS(set) do { /**/ } while (0) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
222 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
223 static int have_wildcard(int, char_u **); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
224 static int have_dollars(int, char_u **); |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
225 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
226 static int save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file); |
7 | 227 |
228 #ifndef SIG_ERR | |
1879 | 229 # define SIG_ERR ((RETSIGTYPE (*)())-1) |
7 | 230 #endif |
231 | |
1832 | 232 /* volatile because it is used in signal handler sig_winch(). */ |
233 static volatile int do_resize = FALSE; | |
7 | 234 static char_u *extra_shell_arg = NULL; |
235 static int show_shell_mess = TRUE; | |
1832 | 236 /* volatile because it is used in signal handler deathtrap(). */ |
237 static volatile int deadly_signal = 0; /* The signal we caught */ | |
238 /* volatile because it is used in signal handler deathtrap(). */ | |
239 static volatile int in_mch_delay = FALSE; /* sleeping in mch_delay() */ | |
7 | 240 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
241 #if defined(FEAT_JOB_CHANNEL) && !defined(USE_SYSTEM) |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
242 static int dont_check_job_ended = 0; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
243 #endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
244 |
7 | 245 static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ |
246 | |
247 #ifdef USE_XSMP | |
248 typedef struct | |
249 { | |
250 SmcConn smcconn; /* The SM connection ID */ | |
251 IceConn iceconn; /* The ICE connection ID */ | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
252 char *clientid; /* The client ID for the current smc session */ |
7 | 253 Bool save_yourself; /* If we're in the middle of a save_yourself */ |
254 Bool shutdown; /* If we're in shutdown mode */ | |
255 } xsmp_config_T; | |
256 | |
257 static xsmp_config_T xsmp; | |
258 #endif | |
259 | |
260 #ifdef SYS_SIGLIST_DECLARED | |
261 /* | |
262 * I have seen | |
263 * extern char *_sys_siglist[NSIG]; | |
264 * on Irix, Linux, NetBSD and Solaris. It contains a nice list of strings | |
265 * that describe the signals. That is nearly what we want here. But | |
266 * autoconf does only check for sys_siglist (without the underscore), I | |
267 * do not want to change everything today.... jw. | |
10375
2055d3722c5b
commit https://github.com/vim/vim/commit/3f7d0907269558cb3ea184a3083640f9e20bb21e
Christian Brabandt <cb@256bit.org>
parents:
10353
diff
changeset
|
268 * This is why AC_DECL_SYS_SIGLIST is commented out in configure.ac. |
7 | 269 */ |
270 #endif | |
271 | |
272 static struct signalinfo | |
273 { | |
274 int sig; /* Signal number, eg. SIGSEGV etc */ | |
275 char *name; /* Signal name (not char_u!). */ | |
276 char deadly; /* Catch as a deadly signal? */ | |
277 } signal_info[] = | |
278 { | |
279 #ifdef SIGHUP | |
280 {SIGHUP, "HUP", TRUE}, | |
281 #endif | |
282 #ifdef SIGQUIT | |
283 {SIGQUIT, "QUIT", TRUE}, | |
284 #endif | |
285 #ifdef SIGILL | |
286 {SIGILL, "ILL", TRUE}, | |
287 #endif | |
288 #ifdef SIGTRAP | |
289 {SIGTRAP, "TRAP", TRUE}, | |
290 #endif | |
291 #ifdef SIGABRT | |
292 {SIGABRT, "ABRT", TRUE}, | |
293 #endif | |
294 #ifdef SIGEMT | |
295 {SIGEMT, "EMT", TRUE}, | |
296 #endif | |
297 #ifdef SIGFPE | |
298 {SIGFPE, "FPE", TRUE}, | |
299 #endif | |
300 #ifdef SIGBUS | |
301 {SIGBUS, "BUS", TRUE}, | |
302 #endif | |
4074 | 303 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) |
304 /* MzScheme uses SEGV in its garbage collector */ | |
7 | 305 {SIGSEGV, "SEGV", TRUE}, |
306 #endif | |
307 #ifdef SIGSYS | |
308 {SIGSYS, "SYS", TRUE}, | |
309 #endif | |
310 #ifdef SIGALRM | |
311 {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ | |
312 #endif | |
313 #ifdef SIGTERM | |
314 {SIGTERM, "TERM", TRUE}, | |
315 #endif | |
2701 | 316 #if defined(SIGVTALRM) && !defined(FEAT_RUBY) |
7 | 317 {SIGVTALRM, "VTALRM", TRUE}, |
318 #endif | |
1560 | 319 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) |
320 /* MzScheme uses SIGPROF for its own needs; On Linux with profiling | |
321 * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ | |
7 | 322 {SIGPROF, "PROF", TRUE}, |
323 #endif | |
324 #ifdef SIGXCPU | |
325 {SIGXCPU, "XCPU", TRUE}, | |
326 #endif | |
327 #ifdef SIGXFSZ | |
328 {SIGXFSZ, "XFSZ", TRUE}, | |
329 #endif | |
330 #ifdef SIGUSR1 | |
331 {SIGUSR1, "USR1", TRUE}, | |
332 #endif | |
1620 | 333 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) |
334 /* Used for sysmouse handling */ | |
7 | 335 {SIGUSR2, "USR2", TRUE}, |
336 #endif | |
337 #ifdef SIGINT | |
338 {SIGINT, "INT", FALSE}, | |
339 #endif | |
340 #ifdef SIGWINCH | |
341 {SIGWINCH, "WINCH", FALSE}, | |
342 #endif | |
343 #ifdef SIGTSTP | |
344 {SIGTSTP, "TSTP", FALSE}, | |
345 #endif | |
346 #ifdef SIGPIPE | |
347 {SIGPIPE, "PIPE", FALSE}, | |
348 #endif | |
349 {-1, "Unknown!", FALSE} | |
350 }; | |
351 | |
1935 | 352 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
353 mch_chdir(char *path) |
1935 | 354 { |
355 if (p_verbose >= 5) | |
356 { | |
357 verbose_enter(); | |
358 smsg((char_u *)"chdir(%s)", path); | |
359 verbose_leave(); | |
360 } | |
361 # ifdef VMS | |
362 return chdir(vms_fixfilename(path)); | |
363 # else | |
364 return chdir(path); | |
365 # endif | |
366 } | |
367 | |
1757 | 368 /* |
369 * Write s[len] to the screen. | |
370 */ | |
7 | 371 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
372 mch_write(char_u *s, int len) |
7 | 373 { |
1757 | 374 ignored = (int)write(1, (char *)s, len); |
7 | 375 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
|
376 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); |
7 | 377 } |
378 | |
379 /* | |
1450 | 380 * mch_inchar(): low level input function. |
7 | 381 * Get a characters from the keyboard. |
382 * Return the number of characters that are available. | |
383 * If wtime == 0 do not wait for characters. | |
384 * If wtime == n wait a short time for characters. | |
385 * If wtime == -1 wait forever for characters. | |
386 */ | |
387 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
388 mch_inchar( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
389 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
390 int maxlen, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
391 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
|
392 int tb_change_cnt) |
7 | 393 { |
394 int len; | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
395 int interrupted = FALSE; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
396 int did_start_blocking = FALSE; |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
397 long wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
398 long elapsed_time = 0; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
399 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
400 ELAPSED_TYPE start_tv; |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
401 |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
402 ELAPSED_INIT(start_tv); |
9207
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
403 #endif |
7 | 404 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
405 /* 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
|
406 for (;;) |
61e669c5da6f
commit https://github.com/vim/vim/commit/e30a3d01dc1b6b066748b1d61cced05cf92b3c80
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
407 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
408 /* 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
|
409 * columns=99" command was used. */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
410 while (do_resize) |
7 | 411 handle_resize(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
412 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
413 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
414 parse_queued_messages(); |
11834
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11826
diff
changeset
|
415 /* If input was put directly in typeahead buffer bail out here. */ |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11826
diff
changeset
|
416 if (typebuf_changed(tb_change_cnt)) |
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11826
diff
changeset
|
417 return 0; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
418 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
419 if (wtime < 0 && did_start_blocking) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
420 /* 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
|
421 wait_time = -1; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
422 else |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
423 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
424 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
425 wait_time = wtime; |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
426 else |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
427 /* going to block after p_ut */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
428 wait_time = p_ut; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
429 #ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
430 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
|
431 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
432 wait_time -= elapsed_time; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
433 if (wait_time < 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
434 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
435 if (wtime >= 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
436 /* no character available within "wtime" */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
437 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
438 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
439 if (wtime < 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
440 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
441 /* no character available within 'updatetime' */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
442 did_start_blocking = TRUE; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
443 #ifdef FEAT_AUTOCMD |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
444 if (trigger_cursorhold() && maxlen >= 3 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
445 && !typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
446 { |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
447 buf[0] = K_SPECIAL; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
448 buf[1] = KS_EXTRA; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
449 buf[2] = (int)KE_CURSORHOLD; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
450 return 3; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
451 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
452 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
453 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
454 * 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
|
455 * 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
|
456 * Also done when interrupted by SIGWINCH. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
457 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
458 before_blocking(); |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
459 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
460 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
461 } |
9189
4b55d8e162d4
commit https://github.com/vim/vim/commit/cf7c11a9479ba7ce775b86c7a846fae48321d260
Christian Brabandt <cb@256bit.org>
parents:
9074
diff
changeset
|
462 } |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
463 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
464 #ifdef FEAT_JOB_CHANNEL |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
465 /* 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
|
466 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
|
467 wait_time = 100L; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
468 /* 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
|
469 * should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
470 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
|
471 wait_time = 10L; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
472 #endif |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
473 #ifdef FEAT_BEVAL |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
474 if (p_beval && wait_time > 100L) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
475 /* 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
|
476 * 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
|
477 wait_time = 100L; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10620
diff
changeset
|
478 #endif |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
479 |
7 | 480 /* |
2436 | 481 * We want to be interrupted by the winch signal |
482 * or by an event on the monitored file descriptors. | |
7 | 483 */ |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
484 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
|
485 { |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
486 /* 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
|
487 if (typebuf_changed(tb_change_cnt)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
488 return 0; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
489 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
490 /* |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
491 * 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
|
492 * 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
|
493 * trying until none is available |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
494 * 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
|
495 * do it. |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
496 */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
497 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
|
498 if (len > 0) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
499 return len; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
500 continue; |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
501 } |
7 | 502 |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
503 /* no character available */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
504 #if !(defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)) |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
505 /* estimate the elapsed time */ |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
506 elapsed_time += wait_time; |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
507 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
508 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
509 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
|
510 #ifdef FEAT_CLIENTSERVER |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
511 || server_waiting() |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
512 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
513 #ifdef MESSAGE_QUEUE |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
514 || interrupted |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
515 #endif |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
516 || 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
|
517 || (wtime < 0 && !did_start_blocking)) |
10309
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
518 continue; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
519 |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
520 /* no character available or interrupted */ |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
521 break; |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
522 } |
88331ee68367
commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents:
10297
diff
changeset
|
523 return 0; |
7 | 524 } |
525 | |
526 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
527 handle_resize(void) |
7 | 528 { |
529 do_resize = FALSE; | |
530 shell_resized(); | |
531 } | |
532 | |
533 /* | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
534 * Return non-zero if a character is available. |
7 | 535 */ |
536 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
537 mch_char_avail(void) |
7 | 538 { |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
539 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
|
540 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
541 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
542 #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
|
543 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
544 * 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
|
545 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
546 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
547 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
548 { |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
549 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
|
550 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
551 #endif |
7 | 552 |
553 #if defined(HAVE_TOTAL_MEM) || defined(PROTO) | |
554 # ifdef HAVE_SYS_RESOURCE_H | |
1879 | 555 # include <sys/resource.h> |
7 | 556 # endif |
557 # if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTL) | |
558 # include <sys/sysctl.h> | |
559 # endif | |
560 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) | |
561 # include <sys/sysinfo.h> | |
562 # endif | |
563 | |
564 /* | |
1110 | 565 * Return total amount of memory available in Kbyte. |
566 * Doesn't change when memory has been allocated. | |
7 | 567 */ |
568 long_u | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
569 mch_total_mem(int special UNUSED) |
7 | 570 { |
571 long_u mem = 0; | |
1110 | 572 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ |
7 | 573 |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
574 # ifdef HAVE_SYSCTL |
7 | 575 int mib[2], physmem; |
576 size_t len; | |
577 | |
578 /* BSD way of getting the amount of RAM available. */ | |
579 mib[0] = CTL_HW; | |
580 mib[1] = HW_USERMEM; | |
581 len = sizeof(physmem); | |
582 if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0) | |
583 mem = (long_u)physmem; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
584 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
585 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
586 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) |
7 | 587 if (mem == 0) |
588 { | |
589 struct sysinfo sinfo; | |
590 | |
591 /* Linux way of getting amount of RAM available */ | |
592 if (sysinfo(&sinfo) == 0) | |
1110 | 593 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
594 # ifdef HAVE_SYSINFO_MEM_UNIT |
1110 | 595 /* avoid overflow as much as possible */ |
596 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) | |
597 { | |
598 sinfo.mem_unit = sinfo.mem_unit >> 1; | |
599 --shiftright; | |
600 } | |
601 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
|
602 # else |
7 | 603 mem = sinfo.totalram; |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
604 # endif |
1110 | 605 } |
7 | 606 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
607 # endif |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
608 |
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
609 # ifdef HAVE_SYSCONF |
7 | 610 if (mem == 0) |
611 { | |
612 long pagesize, pagecount; | |
613 | |
614 /* Solaris way of getting amount of RAM available */ | |
615 pagesize = sysconf(_SC_PAGESIZE); | |
616 pagecount = sysconf(_SC_PHYS_PAGES); | |
617 if (pagesize > 0 && pagecount > 0) | |
1110 | 618 { |
619 /* avoid overflow as much as possible */ | |
620 while (shiftright > 0 && (pagesize & 1) == 0) | |
621 { | |
1204 | 622 pagesize = (long_u)pagesize >> 1; |
1110 | 623 --shiftright; |
624 } | |
7 | 625 mem = (long_u)pagesize * pagecount; |
1110 | 626 } |
7 | 627 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
628 # endif |
7 | 629 |
630 /* Return the minimum of the physical memory and the user limit, because | |
631 * 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
|
632 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) |
7 | 633 { |
634 struct rlimit rlp; | |
635 | |
636 if (getrlimit(RLIMIT_DATA, &rlp) == 0 | |
637 && 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
|
638 # ifdef RLIM_INFINITY |
7 | 639 && rlp.rlim_cur != RLIM_INFINITY |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
640 # endif |
1110 | 641 && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright) |
7 | 642 ) |
1110 | 643 { |
644 mem = (long_u)rlp.rlim_cur; | |
645 shiftright = 10; | |
646 } | |
7 | 647 } |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
648 # endif |
7 | 649 |
650 if (mem > 0) | |
1110 | 651 return mem >> shiftright; |
652 return (long_u)0x1fffff; | |
7 | 653 } |
654 #endif | |
655 | |
656 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
657 mch_delay(long msec, int ignoreinput) |
7 | 658 { |
659 int old_tmode; | |
14 | 660 #ifdef FEAT_MZSCHEME |
661 long total = msec; /* remember original value */ | |
662 #endif | |
7 | 663 |
664 if (ignoreinput) | |
665 { | |
666 /* Go to cooked mode without echo, to allow SIGINT interrupting us | |
1530 | 667 * here. But we don't want QUIT to kill us (CTRL-\ used in a |
668 * shell may produce SIGQUIT). */ | |
669 in_mch_delay = TRUE; | |
7 | 670 old_tmode = curr_tmode; |
671 if (curr_tmode == TMODE_RAW) | |
672 settmode(TMODE_SLEEP); | |
673 | |
674 /* | |
675 * Everybody sleeps in a different way... | |
676 * Prefer nanosleep(), some versions of usleep() can only sleep up to | |
677 * one second. | |
678 */ | |
14 | 679 #ifdef FEAT_MZSCHEME |
680 do | |
681 { | |
682 /* if total is large enough, wait by portions in p_mzq */ | |
683 if (total > p_mzq) | |
684 msec = p_mzq; | |
685 else | |
686 msec = total; | |
687 total -= msec; | |
688 #endif | |
7 | 689 #ifdef HAVE_NANOSLEEP |
690 { | |
691 struct timespec ts; | |
692 | |
693 ts.tv_sec = msec / 1000; | |
694 ts.tv_nsec = (msec % 1000) * 1000000; | |
695 (void)nanosleep(&ts, NULL); | |
696 } | |
697 #else | |
698 # ifdef HAVE_USLEEP | |
699 while (msec >= 1000) | |
700 { | |
701 usleep((unsigned int)(999 * 1000)); | |
702 msec -= 999; | |
703 } | |
704 usleep((unsigned int)(msec * 1000)); | |
705 # else | |
706 # ifndef HAVE_SELECT | |
707 poll(NULL, 0, (int)msec); | |
708 # else | |
709 { | |
710 struct timeval tv; | |
711 | |
712 tv.tv_sec = msec / 1000; | |
713 tv.tv_usec = (msec % 1000) * 1000; | |
714 /* | |
715 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get | |
716 * a patch from Sun to fix this. Reported by Gunnar Pedersen. | |
717 */ | |
718 select(0, NULL, NULL, NULL, &tv); | |
719 } | |
720 # endif /* HAVE_SELECT */ | |
721 # endif /* HAVE_NANOSLEEP */ | |
722 #endif /* HAVE_USLEEP */ | |
14 | 723 #ifdef FEAT_MZSCHEME |
724 } | |
725 while (total > 0); | |
726 #endif | |
7 | 727 |
728 settmode(old_tmode); | |
1530 | 729 in_mch_delay = FALSE; |
7 | 730 } |
731 else | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
732 WaitForChar(msec, NULL, FALSE); |
7 | 733 } |
734 | |
180 | 735 #if defined(HAVE_STACK_LIMIT) \ |
7 | 736 || (!defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGSTACK)) |
737 # define HAVE_CHECK_STACK_GROWTH | |
738 /* | |
739 * Support for checking for an almost-out-of-stack-space situation. | |
740 */ | |
741 | |
742 /* | |
743 * Return a pointer to an item on the stack. Used to find out if the stack | |
744 * grows up or down. | |
745 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
746 static void check_stack_growth(char *p); |
7 | 747 static int stack_grows_downwards; |
748 | |
749 /* | |
750 * Find out if the stack grows upwards or downwards. | |
751 * "p" points to a variable on the stack of the caller. | |
752 */ | |
753 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
754 check_stack_growth(char *p) |
7 | 755 { |
756 int i; | |
757 | |
758 stack_grows_downwards = (p > (char *)&i); | |
759 } | |
760 #endif | |
761 | |
180 | 762 #if defined(HAVE_STACK_LIMIT) || defined(PROTO) |
7 | 763 static char *stack_limit = NULL; |
764 | |
765 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
766 # include <pthread.h> | |
767 # include <pthread_np.h> | |
768 #endif | |
769 | |
770 /* | |
771 * Find out until how var the stack can grow without getting into trouble. | |
772 * Called when starting up and when switching to the signal stack in | |
773 * deathtrap(). | |
774 */ | |
775 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
776 get_stack_limit(void) |
7 | 777 { |
778 struct rlimit rlp; | |
779 int i; | |
780 long lim; | |
781 | |
782 /* Set the stack limit to 15/16 of the allowable size. Skip this when the | |
783 * limit doesn't fit in a long (rlim_cur might be "long long"). */ | |
784 if (getrlimit(RLIMIT_STACK, &rlp) == 0 | |
785 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
786 # ifdef RLIM_INFINITY | |
787 && rlp.rlim_cur != RLIM_INFINITY | |
788 # endif | |
789 ) | |
790 { | |
791 lim = (long)rlp.rlim_cur; | |
792 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
793 { | |
794 pthread_attr_t attr; | |
795 size_t size; | |
796 | |
797 /* On FreeBSD the initial thread always has a fixed stack size, no | |
798 * matter what the limits are set to. Normally it's 1 Mbyte. */ | |
799 pthread_attr_init(&attr); | |
800 if (pthread_attr_get_np(pthread_self(), &attr) == 0) | |
801 { | |
802 pthread_attr_getstacksize(&attr, &size); | |
803 if (lim > (long)size) | |
804 lim = (long)size; | |
805 } | |
806 pthread_attr_destroy(&attr); | |
807 } | |
808 #endif | |
809 if (stack_grows_downwards) | |
810 { | |
811 stack_limit = (char *)((long)&i - (lim / 16L * 15L)); | |
812 if (stack_limit >= (char *)&i) | |
813 /* overflow, set to 1/16 of current stack position */ | |
814 stack_limit = (char *)((long)&i / 16L); | |
815 } | |
816 else | |
817 { | |
818 stack_limit = (char *)((long)&i + (lim / 16L * 15L)); | |
819 if (stack_limit <= (char *)&i) | |
820 stack_limit = NULL; /* overflow */ | |
821 } | |
822 } | |
823 } | |
824 | |
825 /* | |
826 * Return FAIL when running out of stack space. | |
827 * "p" must point to any variable local to the caller that's on the stack. | |
828 */ | |
829 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
830 mch_stackcheck(char *p) |
7 | 831 { |
832 if (stack_limit != NULL) | |
833 { | |
834 if (stack_grows_downwards) | |
835 { | |
836 if (p < stack_limit) | |
837 return FAIL; | |
838 } | |
839 else if (p > stack_limit) | |
840 return FAIL; | |
841 } | |
842 return OK; | |
843 } | |
844 #endif | |
845 | |
846 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
847 /* | |
848 * Support for using the signal stack. | |
849 * This helps when we run out of stack space, which causes a SIGSEGV. The | |
850 * signal handler then must run on another stack, since the normal stack is | |
851 * completely full. | |
852 */ | |
853 | |
5421 | 854 #if defined(HAVE_AVAILABILITYMACROS_H) |
5411 | 855 # include <AvailabilityMacros.h> |
856 #endif | |
857 | |
7 | 858 #ifndef SIGSTKSZ |
859 # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ | |
860 #endif | |
861 | |
862 # ifdef HAVE_SIGALTSTACK | |
863 static stack_t sigstk; /* for sigaltstack() */ | |
864 # else | |
865 static struct sigstack sigstk; /* for sigstack() */ | |
866 # endif | |
867 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
868 static void init_signal_stack(void); |
7 | 869 static char *signal_stack; |
870 | |
871 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
872 init_signal_stack(void) |
7 | 873 { |
874 if (signal_stack != NULL) | |
875 { | |
876 # ifdef HAVE_SIGALTSTACK | |
1375 | 877 # if defined(__APPLE__) && (!defined(MAC_OS_X_VERSION_MAX_ALLOWED) \ |
878 || MAC_OS_X_VERSION_MAX_ALLOWED <= 1040) | |
7 | 879 /* missing prototype. Adding it to osdef?.h.in doesn't work, because |
880 * "struct sigaltstack" needs to be declared. */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
881 extern int sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss); |
7 | 882 # endif |
883 | |
884 # ifdef HAVE_SS_BASE | |
885 sigstk.ss_base = signal_stack; | |
886 # else | |
887 sigstk.ss_sp = signal_stack; | |
888 # endif | |
889 sigstk.ss_size = SIGSTKSZ; | |
890 sigstk.ss_flags = 0; | |
891 (void)sigaltstack(&sigstk, NULL); | |
892 # else | |
893 sigstk.ss_sp = signal_stack; | |
894 if (stack_grows_downwards) | |
895 sigstk.ss_sp += SIGSTKSZ - 1; | |
896 sigstk.ss_onstack = 0; | |
897 (void)sigstack(&sigstk, NULL); | |
898 # endif | |
899 } | |
900 } | |
901 #endif | |
902 | |
903 /* | |
1832 | 904 * We need correct prototypes for a signal function, otherwise mean compilers |
7 | 905 * will barf when the second argument to signal() is ``wrong''. |
906 * Let me try it with a few tricky defines from my own osdef.h (jw). | |
907 */ | |
908 #if defined(SIGWINCH) | |
909 static RETSIGTYPE | |
910 sig_winch SIGDEFARG(sigarg) | |
911 { | |
912 /* this is not required on all systems, but it doesn't hurt anybody */ | |
913 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
914 do_resize = TRUE; | |
915 SIGRETURN; | |
916 } | |
917 #endif | |
918 | |
919 #if defined(SIGINT) | |
920 static RETSIGTYPE | |
921 catch_sigint SIGDEFARG(sigarg) | |
922 { | |
923 /* this is not required on all systems, but it doesn't hurt anybody */ | |
924 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
925 got_int = TRUE; | |
926 SIGRETURN; | |
927 } | |
928 #endif | |
929 | |
930 #if defined(SIGPWR) | |
931 static RETSIGTYPE | |
932 catch_sigpwr SIGDEFARG(sigarg) | |
933 { | |
37 | 934 /* this is not required on all systems, but it doesn't hurt anybody */ |
935 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
7 | 936 /* |
937 * I'm not sure we get the SIGPWR signal when the system is really going | |
938 * down or when the batteries are almost empty. Just preserve the swap | |
939 * files and don't exit, that can't do any harm. | |
940 */ | |
941 ml_sync_all(FALSE, FALSE); | |
942 SIGRETURN; | |
943 } | |
944 #endif | |
945 | |
946 #ifdef SET_SIG_ALARM | |
947 /* | |
948 * signal function for alarm(). | |
949 */ | |
950 static RETSIGTYPE | |
951 sig_alarm SIGDEFARG(sigarg) | |
952 { | |
953 /* doesn't do anything, just to break a system call */ | |
954 sig_alarm_called = TRUE; | |
955 SIGRETURN; | |
956 } | |
957 #endif | |
958 | |
188 | 959 #if (defined(HAVE_SETJMP_H) \ |
960 && ((defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) \ | |
961 || defined(FEAT_LIBCALL))) \ | |
962 || defined(PROTO) | |
7 | 963 /* |
964 * A simplistic version of setjmp() that only allows one level of using. | |
965 * Don't call twice before calling mch_endjmp()!. | |
966 * Usage: | |
967 * mch_startjmp(); | |
968 * if (SETJMP(lc_jump_env) != 0) | |
969 * { | |
970 * mch_didjmp(); | |
971 * EMSG("crash!"); | |
972 * } | |
973 * else | |
974 * { | |
975 * do_the_work; | |
976 * mch_endjmp(); | |
977 * } | |
978 * Note: Can't move SETJMP() here, because a function calling setjmp() must | |
979 * not return before the saved environment is used. | |
980 * Returns OK for normal return, FAIL when the protected code caused a | |
981 * problem and LONGJMP() was used. | |
982 */ | |
983 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
984 mch_startjmp(void) |
7 | 985 { |
986 #ifdef SIGHASARG | |
987 lc_signal = 0; | |
988 #endif | |
989 lc_active = TRUE; | |
990 } | |
991 | |
992 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
993 mch_endjmp(void) |
7 | 994 { |
995 lc_active = FALSE; | |
996 } | |
997 | |
998 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
999 mch_didjmp(void) |
7 | 1000 { |
1001 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1002 /* On FreeBSD the signal stack has to be reset after using siglongjmp(), | |
1003 * otherwise catching the signal only works once. */ | |
1004 init_signal_stack(); | |
1005 # endif | |
1006 } | |
1007 #endif | |
1008 | |
1009 /* | |
1010 * This function handles deadly signals. | |
5338 | 1011 * It tries to preserve any swap files and exit properly. |
7 | 1012 * (partly from Elvis). |
5338 | 1013 * NOTE: Avoid unsafe functions, such as allocating memory, they can result in |
1014 * a deadlock. | |
7 | 1015 */ |
1016 static RETSIGTYPE | |
1017 deathtrap SIGDEFARG(sigarg) | |
1018 { | |
1019 static int entered = 0; /* count the number of times we got here. | |
1020 Note: when memory has been corrupted | |
1021 this may get an arbitrary value! */ | |
1022 #ifdef SIGHASARG | |
1023 int i; | |
1024 #endif | |
1025 | |
1026 #if defined(HAVE_SETJMP_H) | |
1027 /* | |
1028 * Catch a crash in protected code. | |
1029 * Restores the environment saved in lc_jump_env, which looks like | |
1030 * SETJMP() returns 1. | |
1031 */ | |
1032 if (lc_active) | |
1033 { | |
1034 # if defined(SIGHASARG) | |
1035 lc_signal = sigarg; | |
1036 # endif | |
1037 lc_active = FALSE; /* don't jump again */ | |
1038 LONGJMP(lc_jump_env, 1); | |
1039 /* NOTREACHED */ | |
1040 } | |
1041 #endif | |
1042 | |
36 | 1043 #ifdef SIGHASARG |
1530 | 1044 # ifdef SIGQUIT |
1045 /* While in mch_delay() we go to cooked mode to allow a CTRL-C to | |
1046 * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when | |
1047 * pressing CTRL-\, but we don't want Vim to exit then. */ | |
1048 if (in_mch_delay && sigarg == SIGQUIT) | |
1049 SIGRETURN; | |
1050 # endif | |
1051 | |
37 | 1052 /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return |
1053 * here. This avoids that a non-reentrant function is interrupted, e.g., | |
1054 * free(). Calling free() again may then cause a crash. */ | |
1055 if (entered == 0 | |
1056 && (0 | |
1057 # ifdef SIGHUP | |
1058 || sigarg == SIGHUP | |
1059 # endif | |
1060 # ifdef SIGQUIT | |
1061 || sigarg == SIGQUIT | |
1062 # endif | |
1063 # ifdef SIGTERM | |
1064 || sigarg == SIGTERM | |
1065 # endif | |
1066 # ifdef SIGPWR | |
1067 || sigarg == SIGPWR | |
1068 # endif | |
1069 # ifdef SIGUSR1 | |
1070 || sigarg == SIGUSR1 | |
1071 # endif | |
1072 # ifdef SIGUSR2 | |
1073 || sigarg == SIGUSR2 | |
1074 # endif | |
1075 ) | |
413 | 1076 && !vim_handle_signal(sigarg)) |
36 | 1077 SIGRETURN; |
1078 #endif | |
1079 | |
7 | 1080 /* Remember how often we have been called. */ |
1081 ++entered; | |
1082 | |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1083 #ifdef FEAT_AUTOCMD |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1084 /* 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
|
1085 * available in the signal stack. */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1086 block_autocmds(); |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1087 #endif |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1088 |
7 | 1089 #ifdef FEAT_EVAL |
1090 /* Set the v:dying variable. */ | |
1091 set_vim_var_nr(VV_DYING, (long)entered); | |
1092 #endif | |
1093 | |
180 | 1094 #ifdef HAVE_STACK_LIMIT |
7 | 1095 /* Since we are now using the signal stack, need to reset the stack |
1096 * limit. Otherwise using a regexp will fail. */ | |
1097 get_stack_limit(); | |
1098 #endif | |
1099 | |
758 | 1100 #if 0 |
1101 /* This is for opening gdb the moment Vim crashes. | |
1102 * You need to manually adjust the file name and Vim executable name. | |
1103 * Suggested by SungHyun Nam. */ | |
1104 { | |
1105 # define VI_GDB_FILE "/tmp/vimgdb" | |
1106 # define VIM_NAME "/usr/bin/vim" | |
1107 FILE *fp = fopen(VI_GDB_FILE, "w"); | |
1108 if (fp) | |
1109 { | |
1110 fprintf(fp, | |
1111 "file %s\n" | |
1112 "attach %d\n" | |
1113 "set height 1000\n" | |
1114 "bt full\n" | |
1115 , VIM_NAME, getpid()); | |
1116 fclose(fp); | |
1117 system("xterm -e gdb -x "VI_GDB_FILE); | |
1118 unlink(VI_GDB_FILE); | |
1119 } | |
1120 } | |
1121 #endif | |
1122 | |
7 | 1123 #ifdef SIGHASARG |
1124 /* try to find the name of this signal */ | |
1125 for (i = 0; signal_info[i].sig != -1; i++) | |
1126 if (sigarg == signal_info[i].sig) | |
1127 break; | |
1128 deadly_signal = sigarg; | |
1129 #endif | |
1130 | |
1131 full_screen = FALSE; /* don't write message to the GUI, it might be | |
1132 * part of the problem... */ | |
1133 /* | |
1134 * If something goes wrong after entering here, we may get here again. | |
1135 * When this happens, give a message and try to exit nicely (resetting the | |
1136 * terminal mode, etc.) | |
1137 * When this happens twice, just exit, don't even try to give a message, | |
1138 * stack may be corrupt or something weird. | |
1139 * When this still happens again (or memory was corrupted in such a way | |
1140 * that "entered" was clobbered) use _exit(), don't try freeing resources. | |
1141 */ | |
1142 if (entered >= 3) | |
1143 { | |
1144 reset_signals(); /* don't catch any signals anymore */ | |
1145 may_core_dump(); | |
1146 if (entered >= 4) | |
1147 _exit(8); | |
1148 exit(7); | |
1149 } | |
1150 if (entered == 2) | |
1151 { | |
5338 | 1152 /* No translation, it may call malloc(). */ |
1153 OUT_STR("Vim: Double signal, exiting\n"); | |
7 | 1154 out_flush(); |
1155 getout(1); | |
1156 } | |
1157 | |
5338 | 1158 /* No translation, it may call malloc(). */ |
7 | 1159 #ifdef SIGHASARG |
5338 | 1160 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", |
7 | 1161 signal_info[i].name); |
1162 #else | |
5338 | 1163 sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); |
1164 #endif | |
1165 | |
1166 /* Preserve files and exit. This sets the really_exiting flag to prevent | |
1167 * calling free(). */ | |
1168 preserve_exit(); | |
7 | 1169 |
9262
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1170 /* NOTREACHED */ |
c9f2b70feac0
commit https://github.com/vim/vim/commit/e429e70f050cb2941f1f8427cf918b68444c904e
Christian Brabandt <cb@256bit.org>
parents:
9209
diff
changeset
|
1171 |
33 | 1172 #ifdef NBDEBUG |
1173 reset_signals(); | |
1174 may_core_dump(); | |
1175 abort(); | |
1176 #endif | |
1177 | |
7 | 1178 SIGRETURN; |
1179 } | |
1180 | |
1832 | 1181 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1182 /* |
1183 * On Solaris with multi-threading, suspending might not work immediately. | |
1184 * Catch the SIGCONT signal, which will be used as an indication whether the | |
1185 * suspending has been done or not. | |
1832 | 1186 * |
1187 * On Linux, signal is not always handled immediately either. | |
1188 * See https://bugs.launchpad.net/bugs/291373 | |
1189 * | |
2701 | 1190 * volatile because it is used in signal handler sigcont_handler(). |
7 | 1191 */ |
1832 | 1192 static volatile int sigcont_received; |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1193 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
7 | 1194 |
1195 /* | |
1196 * signal handler for SIGCONT | |
1197 */ | |
1198 static RETSIGTYPE | |
1199 sigcont_handler SIGDEFARG(sigarg) | |
1200 { | |
1201 sigcont_received = TRUE; | |
1202 SIGRETURN; | |
1203 } | |
1204 #endif | |
1205 | |
2586 | 1206 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1207 static void loose_clipboard(void); |
4230 | 1208 # ifdef USE_SYSTEM |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1209 static void save_clipboard(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1210 static void restore_clipboard(void); |
4209 | 1211 |
1212 static void *clip_star_save = NULL; | |
1213 static void *clip_plus_save = NULL; | |
4230 | 1214 # endif |
2586 | 1215 |
1216 /* | |
1217 * Called when Vim is going to sleep or execute a shell command. | |
1218 * We can't respond to requests for the X selections. Lose them, otherwise | |
1219 * other applications will hang. But first copy the text to cut buffer 0. | |
1220 */ | |
1221 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1222 loose_clipboard(void) |
2586 | 1223 { |
1224 if (clip_star.owned || clip_plus.owned) | |
1225 { | |
1226 x11_export_final_selection(); | |
1227 if (clip_star.owned) | |
1228 clip_lose_selection(&clip_star); | |
1229 if (clip_plus.owned) | |
1230 clip_lose_selection(&clip_plus); | |
1231 if (x11_display != NULL) | |
1232 XFlush(x11_display); | |
1233 } | |
1234 } | |
4209 | 1235 |
4230 | 1236 # ifdef USE_SYSTEM |
4209 | 1237 /* |
1238 * Save clipboard text to restore later. | |
1239 */ | |
1240 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1241 save_clipboard(void) |
4209 | 1242 { |
1243 if (clip_star.owned) | |
1244 clip_star_save = get_register('*', TRUE); | |
1245 if (clip_plus.owned) | |
1246 clip_plus_save = get_register('+', TRUE); | |
1247 } | |
1248 | |
1249 /* | |
1250 * Restore clipboard text if no one own the X selection. | |
1251 */ | |
1252 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1253 restore_clipboard(void) |
4209 | 1254 { |
1255 if (clip_star_save != NULL) | |
1256 { | |
1257 if (!clip_gen_owner_exists(&clip_star)) | |
1258 put_register('*', clip_star_save); | |
1259 else | |
1260 free_register(clip_star_save); | |
1261 clip_star_save = NULL; | |
1262 } | |
1263 if (clip_plus_save != NULL) | |
1264 { | |
1265 if (!clip_gen_owner_exists(&clip_plus)) | |
1266 put_register('+', clip_plus_save); | |
1267 else | |
1268 free_register(clip_plus_save); | |
1269 clip_plus_save = NULL; | |
1270 } | |
1271 } | |
4230 | 1272 # endif |
2586 | 1273 #endif |
1274 | |
7 | 1275 /* |
1276 * If the machine has job control, use it to suspend the program, | |
1277 * otherwise fake it by starting a new shell. | |
1278 */ | |
1279 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1280 mch_suspend(void) |
7 | 1281 { |
1282 /* BeOS does have SIGTSTP, but it doesn't work. */ | |
1283 #if defined(SIGTSTP) && !defined(__BEOS__) | |
1284 out_flush(); /* needed to make cursor visible on some systems */ | |
1285 settmode(TMODE_COOK); | |
1286 out_flush(); /* needed to disable mouse on some systems */ | |
1287 | |
1288 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2586 | 1289 loose_clipboard(); |
7 | 1290 # endif |
1291 | |
1832 | 1292 # if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1293 sigcont_received = FALSE; |
1294 # endif | |
1295 kill(0, SIGTSTP); /* send ourselves a STOP signal */ | |
1832 | 1296 # if defined(_REENTRANT) && defined(SIGCONT) |
1297 /* | |
1298 * Wait for the SIGCONT signal to be handled. It generally happens | |
1299 * immediately, but somehow not all the time. Do not call pause() | |
1300 * because there would be race condition which would hang Vim if | |
1301 * signal happened in between the test of sigcont_received and the | |
1302 * call to pause(). If signal is not yet received, call sleep(0) | |
1303 * to just yield CPU. Signal should then be received. If somehow | |
1304 * it's still not received, sleep 1, 2, 3 ms. Don't bother waiting | |
1305 * further if signal is not received after 1+2+3+4 ms (not expected | |
1306 * to happen). | |
1307 */ | |
1308 { | |
1932 | 1309 long wait_time; |
1310 for (wait_time = 0; !sigcont_received && wait_time <= 3L; wait_time++) | |
1832 | 1311 /* Loop is not entered most of the time */ |
1932 | 1312 mch_delay(wait_time, FALSE); |
1832 | 1313 } |
7 | 1314 # endif |
1315 | |
1316 # ifdef FEAT_TITLE | |
1317 /* | |
1318 * Set oldtitle to NULL, so the current title is obtained again. | |
1319 */ | |
1320 vim_free(oldtitle); | |
1321 oldtitle = NULL; | |
1322 # endif | |
1323 settmode(TMODE_RAW); | |
1324 need_check_timestamps = TRUE; | |
1325 did_check_timestamps = FALSE; | |
1326 #else | |
1327 suspend_shell(); | |
1328 #endif | |
1329 } | |
1330 | |
1331 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1332 mch_init(void) |
7 | 1333 { |
1334 Columns = 80; | |
1335 Rows = 24; | |
1336 | |
1337 out_flush(); | |
1338 set_signals(); | |
167 | 1339 |
765 | 1340 #ifdef MACOS_CONVERT |
167 | 1341 mac_conv_init(); |
1342 #endif | |
4168 | 1343 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
1344 win_clip_init(); | |
1345 #endif | |
7 | 1346 } |
1347 | |
1348 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1349 set_signals(void) |
7 | 1350 { |
1351 #if defined(SIGWINCH) | |
1352 /* | |
1353 * WINDOW CHANGE signal is handled with sig_winch(). | |
1354 */ | |
1355 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
1356 #endif | |
1357 | |
1358 /* | |
1359 * We want the STOP signal to work, to make mch_suspend() work. | |
1360 * For "rvim" the STOP signal is ignored. | |
1361 */ | |
1362 #ifdef SIGTSTP | |
1363 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); | |
1364 #endif | |
1832 | 1365 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1366 signal(SIGCONT, sigcont_handler); |
1367 #endif | |
1368 | |
1369 /* | |
1370 * We want to ignore breaking of PIPEs. | |
1371 */ | |
1372 #ifdef SIGPIPE | |
1373 signal(SIGPIPE, SIG_IGN); | |
1374 #endif | |
1375 | |
1376 #ifdef SIGINT | |
167 | 1377 catch_int_signal(); |
7 | 1378 #endif |
1379 | |
1380 /* | |
1381 * Ignore alarm signals (Perl's alarm() generates it). | |
1382 */ | |
1383 #ifdef SIGALRM | |
1384 signal(SIGALRM, SIG_IGN); | |
1385 #endif | |
1386 | |
1387 /* | |
1388 * Catch SIGPWR (power failure?) to preserve the swap files, so that no | |
1389 * work will be lost. | |
1390 */ | |
1391 #ifdef SIGPWR | |
1392 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
1393 #endif | |
1394 | |
1395 /* | |
1396 * Arrange for other signals to gracefully shutdown Vim. | |
1397 */ | |
1398 catch_signals(deathtrap, SIG_ERR); | |
1399 | |
1400 #if defined(FEAT_GUI) && defined(SIGHUP) | |
1401 /* | |
1402 * When the GUI is running, ignore the hangup signal. | |
1403 */ | |
1404 if (gui.in_use) | |
1405 signal(SIGHUP, SIG_IGN); | |
1406 #endif | |
1407 } | |
1408 | |
167 | 1409 #if defined(SIGINT) || defined(PROTO) |
1410 /* | |
1411 * Catch CTRL-C (only works while in Cooked mode). | |
1412 */ | |
1413 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1414 catch_int_signal(void) |
167 | 1415 { |
1416 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
1417 } | |
1418 #endif | |
1419 | |
7 | 1420 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1421 reset_signals(void) |
7 | 1422 { |
1423 catch_signals(SIG_DFL, SIG_DFL); | |
1832 | 1424 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1425 /* SIGCONT isn't in the list, because its default action is ignore */ |
1426 signal(SIGCONT, SIG_DFL); | |
1427 #endif | |
1428 } | |
1429 | |
1430 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1431 catch_signals( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1432 RETSIGTYPE (*func_deadly)(), |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1433 RETSIGTYPE (*func_other)()) |
7 | 1434 { |
1435 int i; | |
1436 | |
1437 for (i = 0; signal_info[i].sig != -1; i++) | |
1438 if (signal_info[i].deadly) | |
1439 { | |
1440 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) | |
1441 struct sigaction sa; | |
1442 | |
1443 /* Setup to use the alternate stack for the signal function. */ | |
1444 sa.sa_handler = func_deadly; | |
1445 sigemptyset(&sa.sa_mask); | |
1446 # if defined(__linux__) && defined(_REENTRANT) | |
1447 /* On Linux, with glibc compiled for kernel 2.2, there is a bug in | |
1448 * thread handling in combination with using the alternate stack: | |
1449 * pthread library functions try to use the stack pointer to | |
1450 * identify the current thread, causing a SEGV signal, which | |
1451 * recursively calls deathtrap() and hangs. */ | |
1452 sa.sa_flags = 0; | |
1453 # else | |
1454 sa.sa_flags = SA_ONSTACK; | |
1455 # endif | |
1456 sigaction(signal_info[i].sig, &sa, NULL); | |
1457 #else | |
1458 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) | |
1459 struct sigvec sv; | |
1460 | |
1461 /* Setup to use the alternate stack for the signal function. */ | |
1462 sv.sv_handler = func_deadly; | |
1463 sv.sv_mask = 0; | |
1464 sv.sv_flags = SV_ONSTACK; | |
1465 sigvec(signal_info[i].sig, &sv, NULL); | |
1466 # else | |
1467 signal(signal_info[i].sig, func_deadly); | |
1468 # endif | |
1469 #endif | |
1470 } | |
1471 else if (func_other != SIG_ERR) | |
1472 signal(signal_info[i].sig, func_other); | |
1473 } | |
1474 | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1475 #ifdef HAVE_SIGPROCMASK |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1476 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1477 block_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1478 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1479 sigset_t newset; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1480 int i; |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1481 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1482 sigemptyset(&newset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1483 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1484 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
|
1485 sigaddset(&newset, signal_info[i].sig); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1486 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1487 # if defined(_REENTRANT) && defined(SIGCONT) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1488 /* 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
|
1489 sigaddset(&newset, SIGCONT); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1490 # endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1491 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1492 sigprocmask(SIG_BLOCK, &newset, set); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1493 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1494 |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1495 static void |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1496 unblock_signals(sigset_t *set) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1497 { |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1498 sigprocmask(SIG_SETMASK, set, NULL); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1499 } |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1500 #endif |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
1501 |
7 | 1502 /* |
37 | 1503 * Handling of SIGHUP, SIGQUIT and SIGTERM: |
1146 | 1504 * "when" == a signal: when busy, postpone and return FALSE, otherwise |
1505 * return TRUE | |
1506 * "when" == SIGNAL_BLOCK: Going to be busy, block signals | |
1507 * "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
|
1508 * signal |
36 | 1509 * Returns TRUE when Vim should exit. |
1510 */ | |
1511 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1512 vim_handle_signal(int sig) |
36 | 1513 { |
37 | 1514 static int got_signal = 0; |
1515 static int blocked = TRUE; | |
1516 | |
1517 switch (sig) | |
36 | 1518 { |
37 | 1519 case SIGNAL_BLOCK: blocked = TRUE; |
1520 break; | |
1521 | |
1522 case SIGNAL_UNBLOCK: blocked = FALSE; | |
1523 if (got_signal != 0) | |
1524 { | |
1525 kill(getpid(), got_signal); | |
1526 got_signal = 0; | |
1527 } | |
1528 break; | |
1529 | |
1530 default: if (!blocked) | |
36 | 1531 return TRUE; /* exit! */ |
37 | 1532 got_signal = sig; |
1533 #ifdef SIGPWR | |
1534 if (sig != SIGPWR) | |
1535 #endif | |
1536 got_int = TRUE; /* break any loops */ | |
36 | 1537 break; |
1538 } | |
1539 return FALSE; | |
1540 } | |
1541 | |
1542 /* | |
7 | 1543 * Check_win checks whether we have an interactive stdout. |
1544 */ | |
1545 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1546 mch_check_win(int argc UNUSED, char **argv UNUSED) |
7 | 1547 { |
1548 if (isatty(1)) | |
1549 return OK; | |
1550 return FAIL; | |
1551 } | |
1552 | |
1553 /* | |
1554 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
1555 */ | |
1556 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1557 mch_input_isatty(void) |
7 | 1558 { |
1559 if (isatty(read_cmd_fd)) | |
1560 return TRUE; | |
1561 return FALSE; | |
1562 } | |
1563 | |
1564 #ifdef FEAT_X11 | |
1565 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1566 # if defined(ELAPSED_TIMEVAL) \ |
7 | 1567 && (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE)) |
1568 | |
1569 /* | |
1570 * Give a message about the elapsed time for opening the X window. | |
1571 */ | |
1572 static void | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1573 xopen_message(long elapsed_msec) |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1574 { |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1575 smsg((char_u *)_("Opening the X display took %ld msec"), elapsed_msec); |
7 | 1576 } |
1577 # endif | |
1578 #endif | |
1579 | |
1580 #if defined(FEAT_X11) && (defined(FEAT_TITLE) || defined(FEAT_XCLIPBOARD)) | |
1581 /* | |
1582 * A few functions shared by X11 title and clipboard code. | |
1583 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1584 static int x_error_handler(Display *dpy, XErrorEvent *error_event); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1585 static int x_error_check(Display *dpy, XErrorEvent *error_event); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1586 static int x_connect_to_server(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1587 static int test_x11_window(Display *dpy); |
7 | 1588 |
1589 static int got_x_error = FALSE; | |
1590 | |
1591 /* | |
1592 * X Error handler, otherwise X just exits! (very rude) -- webb | |
1593 */ | |
1594 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1595 x_error_handler(Display *dpy, XErrorEvent *error_event) |
7 | 1596 { |
42 | 1597 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); |
7 | 1598 STRCAT(IObuff, _("\nVim: Got X error\n")); |
1599 | |
1600 /* We cannot print a message and continue, because no X calls are allowed | |
1601 * here (causes my system to hang). Silently continuing might be an | |
1602 * alternative... */ | |
1603 preserve_exit(); /* preserve files and exit */ | |
1604 | |
1605 return 0; /* NOTREACHED */ | |
1606 } | |
1607 | |
1608 /* | |
1609 * Another X Error handler, just used to check for errors. | |
1610 */ | |
1611 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1612 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
7 | 1613 { |
1614 got_x_error = TRUE; | |
1615 return 0; | |
1616 } | |
1617 | |
1618 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) | |
1619 # if defined(HAVE_SETJMP_H) | |
1620 /* | |
1621 * An X IO Error handler, used to catch error while opening the display. | |
1622 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1623 static int x_IOerror_check(Display *dpy); |
7 | 1624 |
1625 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1626 x_IOerror_check(Display *dpy UNUSED) |
7 | 1627 { |
1628 /* This function should not return, it causes exit(). Longjump instead. */ | |
1629 LONGJMP(lc_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1630 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1631 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
|
1632 # endif |
7 | 1633 } |
1634 # endif | |
1635 | |
1636 /* | |
1637 * An X IO Error handler, used to catch terminal errors. | |
1638 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1639 static int x_IOerror_handler(Display *dpy); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1640 static void may_restore_clipboard(void); |
6383 | 1641 static int xterm_dpy_was_reset = FALSE; |
7 | 1642 |
1643 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1644 x_IOerror_handler(Display *dpy UNUSED) |
7 | 1645 { |
1646 xterm_dpy = NULL; | |
6383 | 1647 xterm_dpy_was_reset = TRUE; |
7 | 1648 x11_window = 0; |
1649 x11_display = NULL; | |
1650 xterm_Shell = (Widget)0; | |
1651 | |
1652 /* This function should not return, it causes exit(). Longjump instead. */ | |
1653 LONGJMP(x_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1654 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1655 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
|
1656 # endif |
7 | 1657 } |
6383 | 1658 |
1659 /* | |
1660 * If the X11 connection was lost try to restore it. | |
1661 * Helps when the X11 server was stopped and restarted while Vim was inactive | |
6448 | 1662 * (e.g. through tmux). |
6383 | 1663 */ |
1664 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1665 may_restore_clipboard(void) |
6383 | 1666 { |
1667 if (xterm_dpy_was_reset) | |
1668 { | |
1669 xterm_dpy_was_reset = FALSE; | |
6458 | 1670 |
1671 # ifndef LESSTIF_VERSION | |
1672 /* This has been reported to avoid Vim getting stuck. */ | |
1673 if (app_context != (XtAppContext)NULL) | |
1674 { | |
1675 XtDestroyApplicationContext(app_context); | |
1676 app_context = (XtAppContext)NULL; | |
1677 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
1678 } | |
1679 # endif | |
1680 | |
6383 | 1681 setup_term_clip(); |
1682 get_x11_title(FALSE); | |
1683 } | |
1684 } | |
7 | 1685 #endif |
1686 | |
1687 /* | |
1688 * Return TRUE when connection to the X server is desired. | |
1689 */ | |
1690 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1691 x_connect_to_server(void) |
7 | 1692 { |
1693 #if defined(FEAT_CLIENTSERVER) | |
1694 if (x_force_connect) | |
1695 return TRUE; | |
1696 #endif | |
1697 if (x_no_connect) | |
1698 return FALSE; | |
1699 | |
1700 /* Check for a match with "exclude:" from 'clipboard'. */ | |
1701 if (clip_exclude_prog != NULL) | |
1702 { | |
6375 | 1703 if (vim_regexec_prog(&clip_exclude_prog, FALSE, T_NAME, (colnr_T)0)) |
7 | 1704 return FALSE; |
1705 } | |
1706 return TRUE; | |
1707 } | |
1708 | |
1709 /* | |
1710 * Test if "dpy" and x11_window are valid by getting the window title. | |
1711 * I don't actually want it yet, so there may be a simpler call to use, but | |
1712 * this will cause the error handler x_error_check() to be called if anything | |
1713 * is wrong, such as the window pointer being invalid (as can happen when the | |
1714 * user changes his DISPLAY, but not his WINDOWID) -- webb | |
1715 */ | |
1716 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1717 test_x11_window(Display *dpy) |
7 | 1718 { |
1719 int (*old_handler)(); | |
1720 XTextProperty text_prop; | |
1721 | |
1722 old_handler = XSetErrorHandler(x_error_check); | |
1723 got_x_error = FALSE; | |
1724 if (XGetWMName(dpy, x11_window, &text_prop)) | |
1725 XFree((void *)text_prop.value); | |
1726 XSync(dpy, False); | |
1727 (void)XSetErrorHandler(old_handler); | |
1728 | |
1729 if (p_verbose > 0 && got_x_error) | |
292 | 1730 verb_msg((char_u *)_("Testing the X display failed")); |
7 | 1731 |
1732 return (got_x_error ? FAIL : OK); | |
1733 } | |
1734 #endif | |
1735 | |
1736 #ifdef FEAT_TITLE | |
1737 | |
1738 #ifdef FEAT_X11 | |
1739 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1740 static int get_x11_thing(int get_title, int test_only); |
7 | 1741 |
1742 /* | |
1743 * try to get x11 window and display | |
1744 * | |
1745 * return FAIL for failure, OK otherwise | |
1746 */ | |
1747 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1748 get_x11_windis(void) |
7 | 1749 { |
1750 char *winid; | |
1751 static int result = -1; | |
1752 #define XD_NONE 0 /* x11_display not set here */ | |
1753 #define XD_HERE 1 /* x11_display opened here */ | |
1754 #define XD_GUI 2 /* x11_display used from gui.dpy */ | |
1755 #define XD_XTERM 3 /* x11_display used from xterm_dpy */ | |
1756 static int x11_display_from = XD_NONE; | |
1757 static int did_set_error_handler = FALSE; | |
1758 | |
1759 if (!did_set_error_handler) | |
1760 { | |
1761 /* X just exits if it finds an error otherwise! */ | |
1762 (void)XSetErrorHandler(x_error_handler); | |
1763 did_set_error_handler = TRUE; | |
1764 } | |
1765 | |
574 | 1766 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
7 | 1767 if (gui.in_use) |
1768 { | |
1769 /* | |
1770 * If the X11 display was opened here before, for the window where Vim | |
1771 * was started, close that one now to avoid a memory leak. | |
1772 */ | |
1773 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1774 { | |
1775 XCloseDisplay(x11_display); | |
1776 x11_display_from = XD_NONE; | |
1777 } | |
1778 if (gui_get_x11_windis(&x11_window, &x11_display) == OK) | |
1779 { | |
1780 x11_display_from = XD_GUI; | |
1781 return OK; | |
1782 } | |
1783 x11_display = NULL; | |
1784 return FAIL; | |
1785 } | |
1786 else if (x11_display_from == XD_GUI) | |
1787 { | |
1788 /* GUI must have stopped somehow, clear x11_display */ | |
1789 x11_window = 0; | |
1790 x11_display = NULL; | |
1791 x11_display_from = XD_NONE; | |
1792 } | |
1793 #endif | |
1794 | |
1795 /* When started with the "-X" argument, don't try connecting. */ | |
1796 if (!x_connect_to_server()) | |
1797 return FAIL; | |
1798 | |
1799 /* | |
1800 * If WINDOWID not set, should try another method to find out | |
1801 * what the current window number is. The only code I know for | |
1802 * this is very complicated. | |
1803 * We assume that zero is invalid for WINDOWID. | |
1804 */ | |
1805 if (x11_window == 0 && (winid = getenv("WINDOWID")) != NULL) | |
1806 x11_window = (Window)atol(winid); | |
1807 | |
1808 #ifdef FEAT_XCLIPBOARD | |
1809 if (xterm_dpy != NULL && x11_window != 0) | |
1810 { | |
1450 | 1811 /* We may have checked it already, but Gnome terminal can move us to |
1812 * another window, so we need to check every time. */ | |
1813 if (x11_display_from != XD_XTERM) | |
1814 { | |
1815 /* | |
1816 * If the X11 display was opened here before, for the window where | |
1817 * Vim was started, close that one now to avoid a memory leak. | |
1818 */ | |
1819 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1820 XCloseDisplay(x11_display); | |
1821 x11_display = xterm_dpy; | |
1822 x11_display_from = XD_XTERM; | |
1823 } | |
7 | 1824 if (test_x11_window(x11_display) == FAIL) |
1825 { | |
1826 /* probably bad $WINDOWID */ | |
1827 x11_window = 0; | |
1828 x11_display = NULL; | |
1829 x11_display_from = XD_NONE; | |
1830 return FAIL; | |
1831 } | |
1832 return OK; | |
1833 } | |
1834 #endif | |
1835 | |
1836 if (x11_window == 0 || x11_display == NULL) | |
1837 result = -1; | |
1838 | |
1839 if (result != -1) /* Have already been here and set this */ | |
1840 return result; /* Don't do all these X calls again */ | |
1841 | |
1842 if (x11_window != 0 && x11_display == NULL) | |
1843 { | |
1844 #ifdef SET_SIG_ALARM | |
1845 RETSIGTYPE (*sig_save)(); | |
1846 #endif | |
1847 #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
1848 struct timeval start_tv; | |
1849 | |
1850 if (p_verbose > 0) | |
1851 gettimeofday(&start_tv, NULL); | |
1852 #endif | |
1853 | |
1854 #ifdef SET_SIG_ALARM | |
1855 /* | |
1856 * Opening the Display may hang if the DISPLAY setting is wrong, or | |
1857 * the network connection is bad. Set an alarm timer to get out. | |
1858 */ | |
1859 sig_alarm_called = FALSE; | |
1860 sig_save = (RETSIGTYPE (*)())signal(SIGALRM, | |
1861 (RETSIGTYPE (*)())sig_alarm); | |
1862 alarm(2); | |
1863 #endif | |
1864 x11_display = XOpenDisplay(NULL); | |
1865 | |
1866 #ifdef SET_SIG_ALARM | |
1867 alarm(0); | |
1868 signal(SIGALRM, (RETSIGTYPE (*)())sig_save); | |
1869 if (p_verbose > 0 && sig_alarm_called) | |
292 | 1870 verb_msg((char_u *)_("Opening the X display timed out")); |
7 | 1871 #endif |
1872 if (x11_display != NULL) | |
1873 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1874 # ifdef ELAPSED_FUNC |
7 | 1875 if (p_verbose > 0) |
292 | 1876 { |
1877 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
1878 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 1879 verbose_leave(); |
1880 } | |
7 | 1881 # endif |
1882 if (test_x11_window(x11_display) == FAIL) | |
1883 { | |
1884 /* Maybe window id is bad */ | |
1885 x11_window = 0; | |
1886 XCloseDisplay(x11_display); | |
1887 x11_display = NULL; | |
1888 } | |
1889 else | |
1890 x11_display_from = XD_HERE; | |
1891 } | |
1892 } | |
1893 if (x11_window == 0 || x11_display == NULL) | |
1894 return (result = FAIL); | |
2609 | 1895 |
1896 # ifdef FEAT_EVAL | |
1897 set_vim_var_nr(VV_WINDOWID, (long)x11_window); | |
1898 # endif | |
1899 | |
7 | 1900 return (result = OK); |
1901 } | |
1902 | |
1903 /* | |
1904 * Determine original x11 Window Title | |
1905 */ | |
1906 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1907 get_x11_title(int test_only) |
7 | 1908 { |
32 | 1909 return get_x11_thing(TRUE, test_only); |
7 | 1910 } |
1911 | |
1912 /* | |
1913 * Determine original x11 Window icon | |
1914 */ | |
1915 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1916 get_x11_icon(int test_only) |
7 | 1917 { |
1918 int retval = FALSE; | |
1919 | |
1920 retval = get_x11_thing(FALSE, test_only); | |
1921 | |
1922 /* could not get old icon, use terminal name */ | |
1923 if (oldicon == NULL && !test_only) | |
1924 { | |
1925 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 1926 oldicon = vim_strsave(T_NAME + 8); |
7 | 1927 else |
1940 | 1928 oldicon = vim_strsave(T_NAME); |
7 | 1929 } |
1930 | |
1931 return retval; | |
1932 } | |
1933 | |
1934 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1935 get_x11_thing( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1936 int get_title, /* get title string */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1937 int test_only) |
7 | 1938 { |
1939 XTextProperty text_prop; | |
1940 int retval = FALSE; | |
1941 Status status; | |
1942 | |
1943 if (get_x11_windis() == OK) | |
1944 { | |
1945 /* Get window/icon name if any */ | |
1946 if (get_title) | |
1947 status = XGetWMName(x11_display, x11_window, &text_prop); | |
1948 else | |
1949 status = XGetWMIconName(x11_display, x11_window, &text_prop); | |
1950 | |
1951 /* | |
1952 * If terminal is xterm, then x11_window may be a child window of the | |
1953 * outer xterm window that actually contains the window/icon name, so | |
1954 * keep traversing up the tree until a window with a title/icon is | |
1955 * found. | |
1956 */ | |
1957 /* Previously this was only done for xterm and alikes. I don't see a | |
1958 * reason why it would fail for other terminal emulators. | |
1959 * if (term_is_xterm) */ | |
1960 { | |
1961 Window root; | |
1962 Window parent; | |
1963 Window win = x11_window; | |
1964 Window *children; | |
1965 unsigned int num_children; | |
1966 | |
1967 while (!status || text_prop.value == NULL) | |
1968 { | |
1969 if (!XQueryTree(x11_display, win, &root, &parent, &children, | |
1970 &num_children)) | |
1971 break; | |
1972 if (children) | |
1973 XFree((void *)children); | |
1974 if (parent == root || parent == 0) | |
1975 break; | |
1976 | |
1977 win = parent; | |
1978 if (get_title) | |
1979 status = XGetWMName(x11_display, win, &text_prop); | |
1980 else | |
1981 status = XGetWMIconName(x11_display, win, &text_prop); | |
1982 } | |
1983 } | |
1984 if (status && text_prop.value != NULL) | |
1985 { | |
1986 retval = TRUE; | |
1987 if (!test_only) | |
1988 { | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1989 #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
|
1990 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
|
1991 # ifdef FEAT_MBYTE |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1992 && !has_mbyte |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1993 # endif |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1994 ) |
7 | 1995 { |
1996 #endif | |
1997 if (get_title) | |
1998 oldtitle = vim_strsave((char_u *)text_prop.value); | |
1999 else | |
2000 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
|
2001 #if defined(FEAT_XFONTSET) || defined(FEAT_MBYTE) |
7 | 2002 } |
2003 else | |
2004 { | |
2005 char **cl; | |
2006 Status transform_status; | |
2007 int n = 0; | |
2008 | |
2009 transform_status = XmbTextPropertyToTextList(x11_display, | |
2010 &text_prop, | |
2011 &cl, &n); | |
2012 if (transform_status >= Success && n > 0 && cl[0]) | |
2013 { | |
2014 if (get_title) | |
2015 oldtitle = vim_strsave((char_u *) cl[0]); | |
2016 else | |
2017 oldicon = vim_strsave((char_u *) cl[0]); | |
2018 XFreeStringList(cl); | |
2019 } | |
2020 else | |
2021 { | |
2022 if (get_title) | |
2023 oldtitle = vim_strsave((char_u *)text_prop.value); | |
2024 else | |
2025 oldicon = vim_strsave((char_u *)text_prop.value); | |
2026 } | |
2027 } | |
2028 #endif | |
2029 } | |
2030 XFree((void *)text_prop.value); | |
2031 } | |
2032 } | |
2033 return retval; | |
2034 } | |
2035 | |
6282 | 2036 /* Xutf8 functions are not avaialble on older systems. Note that on some |
2037 * systems X_HAVE_UTF8_STRING may be defined in a header file but | |
2038 * Xutf8SetWMProperties() is not in the X11 library. Configure checks for | |
2039 * that and defines HAVE_XUTF8SETWMPROPERTIES. */ | |
7 | 2040 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) |
6282 | 2041 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES |
7 | 2042 # define USE_UTF8_STRING |
2043 # endif | |
2044 #endif | |
2045 | |
2046 /* | |
2047 * Set x11 Window Title | |
2048 * | |
2049 * get_x11_windis() must be called before this and have returned OK | |
2050 */ | |
2051 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2052 set_x11_title(char_u *title) |
7 | 2053 { |
2054 /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING | |
2055 * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't | |
2056 * supported everywhere and STRING doesn't work for multi-byte titles. | |
2057 */ | |
2058 #ifdef USE_UTF8_STRING | |
2059 if (enc_utf8) | |
2060 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, | |
2061 NULL, NULL, 0, NULL, NULL, NULL); | |
2062 else | |
2063 #endif | |
2064 { | |
2065 #if XtSpecificationRelease >= 4 | |
2066 # ifdef FEAT_XFONTSET | |
2067 XmbSetWMProperties(x11_display, x11_window, (const char *)title, | |
2068 NULL, NULL, 0, NULL, NULL, NULL); | |
2069 # else | |
2070 XTextProperty text_prop; | |
129 | 2071 char *c_title = (char *)title; |
7 | 2072 |
2073 /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ | |
129 | 2074 (void)XStringListToTextProperty(&c_title, 1, &text_prop); |
7 | 2075 XSetWMProperties(x11_display, x11_window, &text_prop, |
2076 NULL, NULL, 0, NULL, NULL, NULL); | |
2077 # endif | |
2078 #else | |
2079 XStoreName(x11_display, x11_window, (char *)title); | |
2080 #endif | |
2081 } | |
2082 XFlush(x11_display); | |
2083 } | |
2084 | |
2085 /* | |
2086 * Set x11 Window icon | |
2087 * | |
2088 * get_x11_windis() must be called before this and have returned OK | |
2089 */ | |
2090 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2091 set_x11_icon(char_u *icon) |
7 | 2092 { |
2093 /* See above for comments about using X*SetWMProperties(). */ | |
2094 #ifdef USE_UTF8_STRING | |
2095 if (enc_utf8) | |
2096 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2097 NULL, 0, NULL, NULL, NULL); | |
2098 else | |
2099 #endif | |
2100 { | |
2101 #if XtSpecificationRelease >= 4 | |
2102 # ifdef FEAT_XFONTSET | |
2103 XmbSetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2104 NULL, 0, NULL, NULL, NULL); | |
2105 # else | |
2106 XTextProperty text_prop; | |
129 | 2107 char *c_icon = (char *)icon; |
2108 | |
2109 (void)XStringListToTextProperty(&c_icon, 1, &text_prop); | |
7 | 2110 XSetWMProperties(x11_display, x11_window, NULL, &text_prop, |
2111 NULL, 0, NULL, NULL, NULL); | |
2112 # endif | |
2113 #else | |
2114 XSetIconName(x11_display, x11_window, (char *)icon); | |
2115 #endif | |
2116 } | |
2117 XFlush(x11_display); | |
2118 } | |
2119 | |
2120 #else /* FEAT_X11 */ | |
2121 | |
2122 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2123 get_x11_title(int test_only UNUSED) |
7 | 2124 { |
2125 return FALSE; | |
2126 } | |
2127 | |
2128 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2129 get_x11_icon(int test_only) |
7 | 2130 { |
2131 if (!test_only) | |
2132 { | |
2133 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 2134 oldicon = vim_strsave(T_NAME + 8); |
7 | 2135 else |
1940 | 2136 oldicon = vim_strsave(T_NAME); |
7 | 2137 } |
2138 return FALSE; | |
2139 } | |
2140 | |
2141 #endif /* FEAT_X11 */ | |
2142 | |
2143 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2144 mch_can_restore_title(void) |
7 | 2145 { |
2146 return get_x11_title(TRUE); | |
2147 } | |
2148 | |
2149 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2150 mch_can_restore_icon(void) |
7 | 2151 { |
2152 return get_x11_icon(TRUE); | |
2153 } | |
2154 | |
2155 /* | |
2156 * Set the window title and icon. | |
2157 */ | |
2158 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2159 mch_settitle(char_u *title, char_u *icon) |
7 | 2160 { |
2161 int type = 0; | |
2162 static int recursive = 0; | |
2163 | |
2164 if (T_NAME == NULL) /* no terminal name (yet) */ | |
2165 return; | |
2166 if (title == NULL && icon == NULL) /* nothing to do */ | |
2167 return; | |
2168 | |
2169 /* When one of the X11 functions causes a deadly signal, we get here again | |
2170 * recursively. Avoid hanging then (something is probably locked). */ | |
2171 if (recursive) | |
2172 return; | |
2173 ++recursive; | |
2174 | |
2175 /* | |
2176 * if the window ID and the display is known, we may use X11 calls | |
2177 */ | |
2178 #ifdef FEAT_X11 | |
2179 if (get_x11_windis() == OK) | |
2180 type = 1; | |
2181 #else | |
2182 # if defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_GTK) | |
2183 if (gui.in_use) | |
2184 type = 1; | |
2185 # endif | |
2186 #endif | |
2187 | |
2188 /* | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2189 * Note: if "t_ts" is set, title is set with escape sequence rather |
7 | 2190 * than x11 calls, because the x11 calls don't always work |
2191 */ | |
2192 if ((type || *T_TS != NUL) && title != NULL) | |
2193 { | |
2194 if (oldtitle == NULL | |
2195 #ifdef FEAT_GUI | |
2196 && !gui.in_use | |
2197 #endif | |
2198 ) /* first call but not in GUI, save title */ | |
2199 (void)get_x11_title(FALSE); | |
2200 | |
2201 if (*T_TS != NUL) /* it's OK if t_fs is empty */ | |
2202 term_settitle(title); | |
2203 #ifdef FEAT_X11 | |
2204 else | |
2205 # ifdef FEAT_GUI_GTK | |
2206 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2207 # endif | |
2208 set_x11_title(title); /* x11 */ | |
2209 #endif | |
64 | 2210 #if defined(FEAT_GUI_GTK) \ |
7 | 2211 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
2212 else | |
2213 gui_mch_settitle(title, icon); | |
2214 #endif | |
2215 did_set_title = TRUE; | |
2216 } | |
2217 | |
2218 if ((type || *T_CIS != NUL) && icon != NULL) | |
2219 { | |
2220 if (oldicon == NULL | |
2221 #ifdef FEAT_GUI | |
2222 && !gui.in_use | |
2223 #endif | |
2224 ) /* first call, save icon */ | |
2225 get_x11_icon(FALSE); | |
2226 | |
2227 if (*T_CIS != NUL) | |
2228 { | |
2229 out_str(T_CIS); /* set icon start */ | |
2230 out_str_nf(icon); | |
2231 out_str(T_CIE); /* set icon end */ | |
2232 out_flush(); | |
2233 } | |
2234 #ifdef FEAT_X11 | |
2235 else | |
2236 # ifdef FEAT_GUI_GTK | |
2237 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2238 # endif | |
2239 set_x11_icon(icon); /* x11 */ | |
2240 #endif | |
2241 did_set_icon = TRUE; | |
2242 } | |
2243 --recursive; | |
2244 } | |
2245 | |
2246 /* | |
2247 * Restore the window/icon title. | |
2248 * "which" is one of: | |
2249 * 1 only restore title | |
2250 * 2 only restore icon | |
2251 * 3 restore title and icon | |
2252 */ | |
2253 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2254 mch_restore_title(int which) |
7 | 2255 { |
2256 /* only restore the title or icon when it has been set */ | |
2257 mch_settitle(((which & 1) && did_set_title) ? | |
2258 (oldtitle ? oldtitle : p_titleold) : NULL, | |
2259 ((which & 2) && did_set_icon) ? oldicon : NULL); | |
2260 } | |
2261 | |
2262 #endif /* FEAT_TITLE */ | |
2263 | |
2264 /* | |
2265 * Return TRUE if "name" looks like some xterm name. | |
158 | 2266 * Seiichi Sato mentioned that "mlterm" works like xterm. |
7 | 2267 */ |
2268 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2269 vim_is_xterm(char_u *name) |
7 | 2270 { |
2271 if (name == NULL) | |
2272 return FALSE; | |
2273 return (STRNICMP(name, "xterm", 5) == 0 | |
2274 || STRNICMP(name, "nxterm", 6) == 0 | |
2275 || STRNICMP(name, "kterm", 5) == 0 | |
158 | 2276 || STRNICMP(name, "mlterm", 6) == 0 |
7 | 2277 || STRNICMP(name, "rxvt", 4) == 0 |
2278 || STRCMP(name, "builtin_xterm") == 0); | |
2279 } | |
2280 | |
1620 | 2281 #if defined(FEAT_MOUSE_XTERM) || defined(PROTO) |
2282 /* | |
2283 * Return TRUE if "name" appears to be that of a terminal | |
2284 * known to support the xterm-style mouse protocol. | |
2285 * Relies on term_is_xterm having been set to its correct value. | |
2286 */ | |
2287 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2288 use_xterm_like_mouse(char_u *name) |
1620 | 2289 { |
2290 return (name != NULL | |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2291 && (term_is_xterm |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2292 || STRNICMP(name, "screen", 6) == 0 |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2293 || STRNICMP(name, "tmux", 4) == 0 |
9873
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2294 || STRICMP(name, "st") == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2295 || STRNICMP(name, "st-", 3) == 0 |
043b7a9579e6
commit https://github.com/vim/vim/commit/e56132bb4167f8b6ea4814cc2c99a71df3d07ff8
Christian Brabandt <cb@256bit.org>
parents:
9552
diff
changeset
|
2296 || STRNICMP(name, "stterm", 6) == 0)); |
1620 | 2297 } |
2298 #endif | |
2299 | |
7 | 2300 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) |
2301 /* | |
2302 * Return non-zero when using an xterm mouse, according to 'ttymouse'. | |
2303 * Return 1 for "xterm". | |
2304 * Return 2 for "xterm2". | |
3145 | 2305 * Return 3 for "urxvt". |
3746 | 2306 * Return 4 for "sgr". |
7 | 2307 */ |
2308 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2309 use_xterm_mouse(void) |
7 | 2310 { |
3746 | 2311 if (ttym_flags == TTYM_SGR) |
2312 return 4; | |
3145 | 2313 if (ttym_flags == TTYM_URXVT) |
2314 return 3; | |
7 | 2315 if (ttym_flags == TTYM_XTERM2) |
2316 return 2; | |
2317 if (ttym_flags == TTYM_XTERM) | |
2318 return 1; | |
2319 return 0; | |
2320 } | |
2321 #endif | |
2322 | |
2323 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2324 vim_is_iris(char_u *name) |
7 | 2325 { |
2326 if (name == NULL) | |
2327 return FALSE; | |
2328 return (STRNICMP(name, "iris-ansi", 9) == 0 | |
2329 || STRCMP(name, "builtin_iris-ansi") == 0); | |
2330 } | |
2331 | |
2332 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2333 vim_is_vt300(char_u *name) |
7 | 2334 { |
2335 if (name == NULL) | |
2336 return FALSE; /* actually all ANSI comp. terminals should be here */ | |
22 | 2337 /* catch VT100 - VT5xx */ |
2338 return ((STRNICMP(name, "vt", 2) == 0 | |
2339 && vim_strchr((char_u *)"12345", name[2]) != NULL) | |
7 | 2340 || STRCMP(name, "builtin_vt320") == 0); |
2341 } | |
2342 | |
2343 /* | |
2344 * Return TRUE if "name" is a terminal for which 'ttyfast' should be set. | |
2345 * This should include all windowed terminal emulators. | |
2346 */ | |
2347 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2348 vim_is_fastterm(char_u *name) |
7 | 2349 { |
2350 if (name == NULL) | |
2351 return FALSE; | |
2352 if (vim_is_xterm(name) || vim_is_vt300(name) || vim_is_iris(name)) | |
2353 return TRUE; | |
2354 return ( STRNICMP(name, "hpterm", 6) == 0 | |
2355 || STRNICMP(name, "sun-cmd", 7) == 0 | |
2356 || STRNICMP(name, "screen", 6) == 0 | |
10266
e86f23a078ca
commit https://github.com/vim/vim/commit/0ba407012c63064f03f1a5677677d4da423e5a73
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2357 || STRNICMP(name, "tmux", 4) == 0 |
7 | 2358 || STRNICMP(name, "dtterm", 6) == 0); |
2359 } | |
2360 | |
2361 /* | |
2362 * Insert user name in s[len]. | |
2363 * Return OK if a name found. | |
2364 */ | |
2365 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2366 mch_get_user_name(char_u *s, int len) |
7 | 2367 { |
2368 #ifdef VMS | |
509 | 2369 vim_strncpy(s, (char_u *)cuserid(NULL), len - 1); |
7 | 2370 return OK; |
2371 #else | |
2372 return mch_get_uname(getuid(), s, len); | |
2373 #endif | |
2374 } | |
2375 | |
2376 /* | |
2377 * Insert user name for "uid" in s[len]. | |
2378 * Return OK if a name found. | |
2379 */ | |
2380 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2381 mch_get_uname(uid_t uid, char_u *s, int len) |
7 | 2382 { |
2383 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) | |
2384 struct passwd *pw; | |
2385 | |
2386 if ((pw = getpwuid(uid)) != NULL | |
2387 && pw->pw_name != NULL && *(pw->pw_name) != NUL) | |
2388 { | |
418 | 2389 vim_strncpy(s, (char_u *)pw->pw_name, len - 1); |
7 | 2390 return OK; |
2391 } | |
2392 #endif | |
2393 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ | |
2394 return FAIL; /* a number is not a name */ | |
2395 } | |
2396 | |
2397 /* | |
2398 * Insert host name is s[len]. | |
2399 */ | |
2400 | |
2401 #ifdef HAVE_SYS_UTSNAME_H | |
2402 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2403 mch_get_host_name(char_u *s, int len) |
7 | 2404 { |
2405 struct utsname vutsname; | |
2406 | |
2407 if (uname(&vutsname) < 0) | |
2408 *s = NUL; | |
2409 else | |
418 | 2410 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); |
7 | 2411 } |
2412 #else /* HAVE_SYS_UTSNAME_H */ | |
2413 | |
2414 # ifdef HAVE_SYS_SYSTEMINFO_H | |
2415 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) | |
2416 # endif | |
2417 | |
2418 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2419 mch_get_host_name(char_u *s, int len) |
7 | 2420 { |
2421 # ifdef VAXC | |
2422 vaxc$gethostname((char *)s, len); | |
2423 # else | |
2424 gethostname((char *)s, len); | |
2425 # endif | |
2426 s[len - 1] = NUL; /* make sure it's terminated */ | |
2427 } | |
2428 #endif /* HAVE_SYS_UTSNAME_H */ | |
2429 | |
2430 /* | |
2431 * return process ID | |
2432 */ | |
2433 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2434 mch_get_pid(void) |
7 | 2435 { |
2436 return (long)getpid(); | |
2437 } | |
2438 | |
2439 #if !defined(HAVE_STRERROR) && defined(USE_GETCWD) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
2440 static char *strerror(int); |
7 | 2441 |
2442 static char * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2443 strerror(int err) |
7 | 2444 { |
2445 extern int sys_nerr; | |
2446 extern char *sys_errlist[]; | |
2447 static char er[20]; | |
2448 | |
2449 if (err > 0 && err < sys_nerr) | |
2450 return (sys_errlist[err]); | |
2451 sprintf(er, "Error %d", err); | |
2452 return er; | |
2453 } | |
2454 #endif | |
2455 | |
2456 /* | |
2457 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2458 * Return OK for success, FAIL for failure. | |
2459 */ | |
2460 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2461 mch_dirname(char_u *buf, int len) |
7 | 2462 { |
2463 #if defined(USE_GETCWD) | |
2464 if (getcwd((char *)buf, len) == NULL) | |
2465 { | |
2466 STRCPY(buf, strerror(errno)); | |
2467 return FAIL; | |
2468 } | |
2469 return OK; | |
2470 #else | |
2471 return (getwd((char *)buf) != NULL ? OK : FAIL); | |
2472 #endif | |
2473 } | |
2474 | |
2475 /* | |
1045 | 2476 * Get absolute file name into "buf[len]". |
7 | 2477 * |
2478 * return FAIL for failure, OK for success | |
2479 */ | |
2480 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2481 mch_FullName( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2482 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2483 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2484 int len, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2485 int force) /* also expand when already absolute path */ |
7 | 2486 { |
2487 int l; | |
1082 | 2488 #ifdef HAVE_FCHDIR |
7 | 2489 int fd = -1; |
2490 static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ | |
1082 | 2491 #endif |
7 | 2492 char_u olddir[MAXPATHL]; |
2493 char_u *p; | |
2494 int retval = OK; | |
1615 | 2495 #ifdef __CYGWIN__ |
1620 | 2496 char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but |
2497 it's not always defined */ | |
2498 #endif | |
7 | 2499 |
1082 | 2500 #ifdef VMS |
2501 fname = vms_fixfilename(fname); | |
2502 #endif | |
2503 | |
1102 | 2504 #ifdef __CYGWIN__ |
2505 /* | |
2506 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". | |
2507 */ | |
1657 | 2508 # 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
|
2509 /* 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
|
2510 * a forward slash. */ |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2511 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
|
2512 fname, posix_fname, MAXPATHL); |
1657 | 2513 # else |
1615 | 2514 cygwin_conv_to_posix_path(fname, posix_fname); |
1657 | 2515 # endif |
1615 | 2516 fname = posix_fname; |
1102 | 2517 #endif |
2518 | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2519 /* 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
|
2520 * 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
|
2521 if ((force || !mch_isFullName(fname)) |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2522 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) |
7 | 2523 { |
2524 /* | |
2525 * If the file name has a path, change to that directory for a moment, | |
2526 * and then do the getwd() (and get back to where we were). | |
2527 * This will get the correct path name with "../" things. | |
2528 */ | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2529 if (p != NULL) |
7 | 2530 { |
1082 | 2531 #ifdef HAVE_FCHDIR |
7 | 2532 /* |
2533 * Use fchdir() if possible, it's said to be faster and more | |
2534 * reliable. But on SunOS 4 it might not work. Check this by | |
2535 * doing a fchdir() right now. | |
2536 */ | |
2537 if (!dont_fchdir) | |
2538 { | |
2539 fd = open(".", O_RDONLY | O_EXTRA, 0); | |
2540 if (fd >= 0 && fchdir(fd) < 0) | |
2541 { | |
2542 close(fd); | |
2543 fd = -1; | |
2544 dont_fchdir = TRUE; /* don't try again */ | |
2545 } | |
2546 } | |
1082 | 2547 #endif |
7 | 2548 |
2549 /* Only change directory when we are sure we can return to where | |
2550 * we are now. After doing "su" chdir(".") might not work. */ | |
2551 if ( | |
1082 | 2552 #ifdef HAVE_FCHDIR |
7 | 2553 fd < 0 && |
1082 | 2554 #endif |
7 | 2555 (mch_dirname(olddir, MAXPATHL) == FAIL |
2556 || mch_chdir((char *)olddir) != 0)) | |
2557 { | |
2558 p = NULL; /* can't get current dir: don't chdir */ | |
2559 retval = FAIL; | |
2560 } | |
2561 else | |
2562 { | |
2563 /* The directory is copied into buf[], to be able to remove | |
2564 * the file name without changing it (could be a string in | |
2565 * read-only memory) */ | |
2566 if (p - fname >= len) | |
2567 retval = FAIL; | |
2568 else | |
2569 { | |
418 | 2570 vim_strncpy(buf, fname, p - fname); |
7 | 2571 if (mch_chdir((char *)buf)) |
2572 retval = FAIL; | |
2573 else | |
2574 fname = p + 1; | |
2575 *buf = NUL; | |
2576 } | |
2577 } | |
2578 } | |
2579 if (mch_dirname(buf, len) == FAIL) | |
2580 { | |
2581 retval = FAIL; | |
2582 *buf = NUL; | |
2583 } | |
2584 if (p != NULL) | |
2585 { | |
1082 | 2586 #ifdef HAVE_FCHDIR |
7 | 2587 if (fd >= 0) |
2588 { | |
1935 | 2589 if (p_verbose >= 5) |
2590 { | |
2591 verbose_enter(); | |
2592 MSG("fchdir() to previous dir"); | |
2593 verbose_leave(); | |
2594 } | |
7 | 2595 l = fchdir(fd); |
2596 close(fd); | |
2597 } | |
2598 else | |
1082 | 2599 #endif |
7 | 2600 l = mch_chdir((char *)olddir); |
2601 if (l != 0) | |
2602 EMSG(_(e_prev_dir)); | |
2603 } | |
2604 | |
2605 l = STRLEN(buf); | |
3867 | 2606 if (l >= len - 1) |
2607 retval = FAIL; /* no space for trailing "/" */ | |
1082 | 2608 #ifndef VMS |
3867 | 2609 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL |
7 | 2610 && STRCMP(fname, ".") != 0) |
3867 | 2611 STRCAT(buf, "/"); |
1082 | 2612 #endif |
7 | 2613 } |
1045 | 2614 |
7 | 2615 /* Catch file names which are too long. */ |
1877 | 2616 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) |
7 | 2617 return FAIL; |
2618 | |
2619 /* Do not append ".", "/dir/." is equal to "/dir". */ | |
2620 if (STRCMP(fname, ".") != 0) | |
2621 STRCAT(buf, fname); | |
2622 | |
2623 return OK; | |
2624 } | |
2625 | |
2626 /* | |
2627 * Return TRUE if "fname" does not depend on the current directory. | |
2628 */ | |
2629 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2630 mch_isFullName(char_u *fname) |
7 | 2631 { |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
2632 #ifdef VMS |
7 | 2633 return ( fname[0] == '/' || fname[0] == '.' || |
2634 strchr((char *)fname,':') || strchr((char *)fname,'"') || | |
2635 (strchr((char *)fname,'[') && strchr((char *)fname,']'))|| | |
2636 (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
|
2637 #else |
7 | 2638 return (*fname == '/' || *fname == '~'); |
2639 #endif | |
2640 } | |
2641 | |
585 | 2642 #if defined(USE_FNAME_CASE) || defined(PROTO) |
2643 /* | |
2644 * Set the case of the file name, if it already exists. This will cause the | |
2645 * file name to remain exactly the same. | |
1450 | 2646 * Only required for file systems where case is ignored and preserved. |
585 | 2647 */ |
2648 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2649 fname_case( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2650 char_u *name, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2651 int len UNUSED) /* buffer size, only used when name gets longer */ |
585 | 2652 { |
2653 struct stat st; | |
2654 char_u *slash, *tail; | |
2655 DIR *dirp; | |
2656 struct dirent *dp; | |
2657 | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2658 if (mch_lstat((char *)name, &st) >= 0) |
585 | 2659 { |
2660 /* Open the directory where the file is located. */ | |
2661 slash = vim_strrchr(name, '/'); | |
2662 if (slash == NULL) | |
2663 { | |
2664 dirp = opendir("."); | |
2665 tail = name; | |
2666 } | |
2667 else | |
2668 { | |
2669 *slash = NUL; | |
2670 dirp = opendir((char *)name); | |
2671 *slash = '/'; | |
2672 tail = slash + 1; | |
2673 } | |
2674 | |
2675 if (dirp != NULL) | |
2676 { | |
2677 while ((dp = readdir(dirp)) != NULL) | |
2678 { | |
2679 /* Only accept names that differ in case and are the same byte | |
2680 * length. TODO: accept different length name. */ | |
2681 if (STRICMP(tail, dp->d_name) == 0 | |
2682 && STRLEN(tail) == STRLEN(dp->d_name)) | |
2683 { | |
2684 char_u newname[MAXPATHL + 1]; | |
2685 struct stat st2; | |
2686 | |
2687 /* Verify the inode is equal. */ | |
2688 vim_strncpy(newname, name, MAXPATHL); | |
2689 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, | |
2690 MAXPATHL - (tail - name)); | |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
2691 if (mch_lstat((char *)newname, &st2) >= 0 |
585 | 2692 && st.st_ino == st2.st_ino |
2693 && st.st_dev == st2.st_dev) | |
2694 { | |
2695 STRCPY(tail, dp->d_name); | |
2696 break; | |
2697 } | |
2698 } | |
2699 } | |
2700 | |
2701 closedir(dirp); | |
2702 } | |
2703 } | |
2704 } | |
2705 #endif | |
2706 | |
7 | 2707 /* |
2708 * Get file permissions for 'name'. | |
2709 * Returns -1 when it doesn't exist. | |
2710 */ | |
2711 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2712 mch_getperm(char_u *name) |
7 | 2713 { |
2714 struct stat statb; | |
2715 | |
2716 /* Keep the #ifdef outside of stat(), it may be a macro. */ | |
2717 #ifdef VMS | |
2718 if (stat((char *)vms_fixfilename(name), &statb)) | |
2719 #else | |
2720 if (stat((char *)name, &statb)) | |
2721 #endif | |
2722 return -1; | |
1350 | 2723 #ifdef __INTERIX |
2724 /* The top bit makes the value negative, which means the file doesn't | |
2725 * exist. Remove the bit, we don't use it. */ | |
2726 return statb.st_mode & ~S_ADDACE; | |
2727 #else | |
7 | 2728 return statb.st_mode; |
1350 | 2729 #endif |
7 | 2730 } |
2731 | |
2732 /* | |
2733 * set file permission for 'name' to 'perm' | |
2734 * | |
2735 * return FAIL for failure, OK otherwise | |
2736 */ | |
2737 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2738 mch_setperm(char_u *name, long perm) |
7 | 2739 { |
2740 return (chmod((char *) | |
2741 #ifdef VMS | |
2742 vms_fixfilename(name), | |
2743 #else | |
2744 name, | |
2745 #endif | |
2746 (mode_t)perm) == 0 ? OK : FAIL); | |
2747 } | |
2748 | |
2749 #if defined(HAVE_ACL) || defined(PROTO) | |
2750 # ifdef HAVE_SYS_ACL_H | |
2751 # include <sys/acl.h> | |
2752 # endif | |
2753 # ifdef HAVE_SYS_ACCESS_H | |
2754 # include <sys/access.h> | |
2755 # endif | |
2756 | |
2757 # ifdef HAVE_SOLARIS_ACL | |
2758 typedef struct vim_acl_solaris_T { | |
2759 int acl_cnt; | |
2760 aclent_t *acl_entry; | |
2761 } vim_acl_solaris_T; | |
2762 # endif | |
2763 | |
1583 | 2764 #if defined(HAVE_SELINUX) || defined(PROTO) |
2765 /* | |
2766 * Copy security info from "from_file" to "to_file". | |
2767 */ | |
2768 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2769 mch_copy_sec(char_u *from_file, char_u *to_file) |
1583 | 2770 { |
2771 if (from_file == NULL) | |
2772 return; | |
2773 | |
2774 if (selinux_enabled == -1) | |
2775 selinux_enabled = is_selinux_enabled(); | |
2776 | |
2777 if (selinux_enabled > 0) | |
2778 { | |
2779 security_context_t from_context = NULL; | |
2780 security_context_t to_context = NULL; | |
2781 | |
2782 if (getfilecon((char *)from_file, &from_context) < 0) | |
2783 { | |
2784 /* If the filesystem doesn't support extended attributes, | |
2785 the original had no special security context and the | |
2786 target cannot have one either. */ | |
2787 if (errno == EOPNOTSUPP) | |
2788 return; | |
2789 | |
2790 MSG_PUTS(_("\nCould not get security context for ")); | |
2791 msg_outtrans(from_file); | |
2792 msg_putchar('\n'); | |
2793 return; | |
2794 } | |
2795 if (getfilecon((char *)to_file, &to_context) < 0) | |
2796 { | |
2797 MSG_PUTS(_("\nCould not get security context for ")); | |
2798 msg_outtrans(to_file); | |
2799 msg_putchar('\n'); | |
2800 freecon (from_context); | |
2801 return ; | |
2802 } | |
2803 if (strcmp(from_context, to_context) != 0) | |
2804 { | |
2805 if (setfilecon((char *)to_file, from_context) < 0) | |
2806 { | |
2807 MSG_PUTS(_("\nCould not set security context for ")); | |
2808 msg_outtrans(to_file); | |
2809 msg_putchar('\n'); | |
2810 } | |
2811 } | |
2812 freecon(to_context); | |
2813 freecon(from_context); | |
2814 } | |
2815 } | |
2816 #endif /* HAVE_SELINUX */ | |
2817 | |
5788 | 2818 #if defined(HAVE_SMACK) && !defined(PROTO) |
2819 /* | |
2820 * Copy security info from "from_file" to "to_file". | |
2821 */ | |
2822 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2823 mch_copy_sec(char_u *from_file, char_u *to_file) |
5788 | 2824 { |
5832 | 2825 static const char * const smack_copied_attributes[] = |
5788 | 2826 { |
2827 XATTR_NAME_SMACK, | |
2828 XATTR_NAME_SMACKEXEC, | |
2829 XATTR_NAME_SMACKMMAP | |
2830 }; | |
2831 | |
2832 char buffer[SMACK_LABEL_LEN]; | |
2833 const char *name; | |
2834 int index; | |
2835 int ret; | |
2836 ssize_t size; | |
2837 | |
2838 if (from_file == NULL) | |
2839 return; | |
2840 | |
2841 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) | |
2842 / sizeof(smack_copied_attributes)[0]) ; index++) | |
2843 { | |
2844 /* get the name of the attribute to copy */ | |
2845 name = smack_copied_attributes[index]; | |
2846 | |
2847 /* get the value of the attribute in buffer */ | |
2848 size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); | |
2849 if (size >= 0) | |
2850 { | |
2851 /* copy the attribute value of buffer */ | |
2852 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); | |
2853 if (ret < 0) | |
2854 { | |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2855 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2856 _("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
|
2857 name, to_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2858 msg_outtrans(IObuff); |
5788 | 2859 msg_putchar('\n'); |
2860 } | |
2861 } | |
2862 else | |
2863 { | |
2864 /* what reason of not having the attribute value? */ | |
2865 switch (errno) | |
2866 { | |
2867 case ENOTSUP: | |
2868 /* extended attributes aren't supported or enabled */ | |
2869 /* should a message be echoed? not sure... */ | |
2870 return; /* leave because it isn't usefull to continue */ | |
2871 | |
2872 case ERANGE: | |
2873 default: | |
2874 /* 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
|
2875 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2876 _("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
|
2877 name, from_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2878 msg_puts(IObuff); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2879 msg_putchar('\n'); |
5788 | 2880 /* FALLTHROUGH to remove the attribute */ |
2881 | |
2882 case ENODATA: | |
2883 /* no attribute of this name */ | |
2884 ret = removexattr((char*)to_file, name); | |
5800 | 2885 /* Silently ignore errors, apparently this happens when |
2886 * smack is not actually being used. */ | |
5788 | 2887 break; |
2888 } | |
2889 } | |
2890 } | |
2891 } | |
2892 #endif /* HAVE_SMACK */ | |
2893 | |
7 | 2894 /* |
2895 * Return a pointer to the ACL of file "fname" in allocated memory. | |
2896 * Return NULL if the ACL is not available for whatever reason. | |
2897 */ | |
2898 vim_acl_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2899 mch_get_acl(char_u *fname UNUSED) |
7 | 2900 { |
2901 vim_acl_T ret = NULL; | |
2902 #ifdef HAVE_POSIX_ACL | |
2903 ret = (vim_acl_T)acl_get_file((char *)fname, ACL_TYPE_ACCESS); | |
2904 #else | |
3330 | 2905 #ifdef HAVE_SOLARIS_ZFS_ACL |
2906 acl_t *aclent; | |
2907 | |
2908 if (acl_get((char *)fname, 0, &aclent) < 0) | |
2909 return NULL; | |
2910 ret = (vim_acl_T)aclent; | |
2911 #else | |
7 | 2912 #ifdef HAVE_SOLARIS_ACL |
2913 vim_acl_solaris_T *aclent; | |
2914 | |
2915 aclent = malloc(sizeof(vim_acl_solaris_T)); | |
2916 if ((aclent->acl_cnt = acl((char *)fname, GETACLCNT, 0, NULL)) < 0) | |
2917 { | |
2918 free(aclent); | |
2919 return NULL; | |
2920 } | |
2921 aclent->acl_entry = malloc(aclent->acl_cnt * sizeof(aclent_t)); | |
2922 if (acl((char *)fname, GETACL, aclent->acl_cnt, aclent->acl_entry) < 0) | |
2923 { | |
2924 free(aclent->acl_entry); | |
2925 free(aclent); | |
2926 return NULL; | |
2927 } | |
2928 ret = (vim_acl_T)aclent; | |
2929 #else | |
2930 #if defined(HAVE_AIX_ACL) | |
2931 int aclsize; | |
2932 struct acl *aclent; | |
2933 | |
2934 aclsize = sizeof(struct acl); | |
2935 aclent = malloc(aclsize); | |
2936 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
2937 { | |
2938 if (errno == ENOSPC) | |
2939 { | |
2940 aclsize = aclent->acl_len; | |
2941 aclent = realloc(aclent, aclsize); | |
2942 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
2943 { | |
2944 free(aclent); | |
2945 return NULL; | |
2946 } | |
2947 } | |
2948 else | |
2949 { | |
2950 free(aclent); | |
2951 return NULL; | |
2952 } | |
2953 } | |
2954 ret = (vim_acl_T)aclent; | |
2955 #endif /* HAVE_AIX_ACL */ | |
2956 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 2957 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 2958 #endif /* HAVE_POSIX_ACL */ |
2959 return ret; | |
2960 } | |
2961 | |
2962 /* | |
2963 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
2964 */ | |
2965 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2966 mch_set_acl(char_u *fname UNUSED, vim_acl_T aclent) |
7 | 2967 { |
2968 if (aclent == NULL) | |
2969 return; | |
2970 #ifdef HAVE_POSIX_ACL | |
2971 acl_set_file((char *)fname, ACL_TYPE_ACCESS, (acl_t)aclent); | |
2972 #else | |
3330 | 2973 #ifdef HAVE_SOLARIS_ZFS_ACL |
2974 acl_set((char *)fname, (acl_t *)aclent); | |
2975 #else | |
7 | 2976 #ifdef HAVE_SOLARIS_ACL |
2977 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt, | |
2978 ((vim_acl_solaris_T *)aclent)->acl_entry); | |
2979 #else | |
2980 #ifdef HAVE_AIX_ACL | |
2981 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); | |
2982 #endif /* HAVE_AIX_ACL */ | |
2983 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 2984 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 2985 #endif /* HAVE_POSIX_ACL */ |
2986 } | |
2987 | |
2988 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2989 mch_free_acl(vim_acl_T aclent) |
7 | 2990 { |
2991 if (aclent == NULL) | |
2992 return; | |
2993 #ifdef HAVE_POSIX_ACL | |
2994 acl_free((acl_t)aclent); | |
2995 #else | |
3330 | 2996 #ifdef HAVE_SOLARIS_ZFS_ACL |
2997 acl_free((acl_t *)aclent); | |
2998 #else | |
7 | 2999 #ifdef HAVE_SOLARIS_ACL |
3000 free(((vim_acl_solaris_T *)aclent)->acl_entry); | |
3001 free(aclent); | |
3002 #else | |
3003 #ifdef HAVE_AIX_ACL | |
3004 free(aclent); | |
3005 #endif /* HAVE_AIX_ACL */ | |
3006 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 3007 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 3008 #endif /* HAVE_POSIX_ACL */ |
3009 } | |
3010 #endif | |
3011 | |
3012 /* | |
3013 * Set hidden flag for "name". | |
3014 */ | |
3015 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3016 mch_hide(char_u *name UNUSED) |
7 | 3017 { |
3018 /* can't hide a file */ | |
3019 } | |
3020 | |
3021 /* | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3022 * return TRUE if "name" is a directory or a symlink to a directory |
7 | 3023 * return FALSE if "name" is not a directory |
3024 * return FALSE for error | |
3025 */ | |
3026 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3027 mch_isdir(char_u *name) |
7 | 3028 { |
3029 struct stat statb; | |
3030 | |
3031 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ | |
3032 return FALSE; | |
3033 if (stat((char *)name, &statb)) | |
3034 return FALSE; | |
3035 #ifdef _POSIX_SOURCE | |
3036 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); | |
3037 #else | |
3038 return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); | |
3039 #endif | |
3040 } | |
3041 | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3042 /* |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3043 * 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
|
3044 * 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
|
3045 * return FALSE for error |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3046 */ |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3047 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3048 mch_isrealdir(char_u *name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3049 { |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3050 struct stat statb; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3051 |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3052 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
|
3053 return FALSE; |
10328
299f1669c20e
commit https://github.com/vim/vim/commit/de5e2c219b99895445fb75ae3541ee69282a5846
Christian Brabandt <cb@256bit.org>
parents:
10320
diff
changeset
|
3054 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
|
3055 return FALSE; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3056 #ifdef _POSIX_SOURCE |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3057 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
|
3058 #else |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3059 return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3060 #endif |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3061 } |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
3062 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3063 static int executable_file(char_u *name); |
7 | 3064 |
3065 /* | |
3066 * Return 1 if "name" is an executable file, 0 if not or it doesn't exist. | |
3067 */ | |
3068 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3069 executable_file(char_u *name) |
7 | 3070 { |
3071 struct stat st; | |
3072 | |
3073 if (stat((char *)name, &st)) | |
3074 return 0; | |
5704 | 3075 #ifdef VMS |
3076 /* Like on Unix system file can have executable rights but not necessarily | |
3077 * be an executable, but on Unix is not a default for an ordianry file to | |
3078 * have an executable flag - on VMS it is in most cases. | |
3079 * Therefore, this check does not have any sense - let keep us to the | |
3080 * conventions instead: | |
3081 * *.COM and *.EXE files are the executables - the rest are not. This is | |
3082 * not ideal but better then it was. | |
3083 */ | |
3084 int vms_executable = 0; | |
3085 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) | |
3086 { | |
3087 if (strstr(vms_tolower((char*)name),".exe") != NULL | |
3088 || strstr(vms_tolower((char*)name),".com")!= NULL) | |
3089 vms_executable = 1; | |
3090 } | |
3091 return vms_executable; | |
3092 #else | |
7 | 3093 return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0; |
5704 | 3094 #endif |
7 | 3095 } |
3096 | |
3097 /* | |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
3098 * Return TRUE if "name" can be found in $PATH and executed, FALSE if not. |
6695 | 3099 * If "use_path" is FALSE only check if "name" is executable. |
7 | 3100 * Return -1 if unknown. |
3101 */ | |
3102 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3103 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3104 { |
3105 char_u *buf; | |
3106 char_u *p, *e; | |
3107 int retval; | |
3108 | |
6695 | 3109 /* When "use_path" is false and if it's an absolute or relative path don't |
3110 * need to use $PATH. */ | |
3111 if (!use_path || mch_isFullName(name) || (name[0] == '.' | |
3112 && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) | |
5704 | 3113 { |
6695 | 3114 /* There must be a path separator, files in the current directory |
3115 * can't be executed. */ | |
3116 if (gettail(name) != name && executable_file(name)) | |
5782 | 3117 { |
3118 if (path != NULL) | |
3119 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3120 if (name[0] != '/') |
5782 | 3121 *path = FullName_save(name, TRUE); |
3122 else | |
3123 *path = vim_strsave(name); | |
3124 } | |
3125 return TRUE; | |
3126 } | |
3127 return FALSE; | |
5704 | 3128 } |
7 | 3129 |
3130 p = (char_u *)getenv("PATH"); | |
3131 if (p == NULL || *p == NUL) | |
3132 return -1; | |
3133 buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); | |
3134 if (buf == NULL) | |
3135 return -1; | |
3136 | |
3137 /* | |
3138 * Walk through all entries in $PATH to check if "name" exists there and | |
3139 * is an executable file. | |
3140 */ | |
3141 for (;;) | |
3142 { | |
3143 e = (char_u *)strchr((char *)p, ':'); | |
3144 if (e == NULL) | |
3145 e = p + STRLEN(p); | |
3146 if (e - p <= 1) /* empty entry means current dir */ | |
3147 STRCPY(buf, "./"); | |
3148 else | |
3149 { | |
418 | 3150 vim_strncpy(buf, p, e - p); |
7 | 3151 add_pathsep(buf); |
3152 } | |
3153 STRCAT(buf, name); | |
3154 retval = executable_file(buf); | |
3155 if (retval == 1) | |
5782 | 3156 { |
3157 if (path != NULL) | |
3158 { | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3159 if (buf[0] != '/') |
5782 | 3160 *path = FullName_save(buf, TRUE); |
3161 else | |
3162 *path = vim_strsave(buf); | |
3163 } | |
7 | 3164 break; |
5782 | 3165 } |
7 | 3166 |
3167 if (*e != ':') | |
3168 break; | |
3169 p = e + 1; | |
3170 } | |
3171 | |
3172 vim_free(buf); | |
3173 return retval; | |
3174 } | |
3175 | |
3176 /* | |
3177 * Check what "name" is: | |
3178 * NODE_NORMAL: file or directory (or doesn't exist) | |
3179 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3180 * NODE_OTHER: non-writable things | |
3181 */ | |
3182 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3183 mch_nodetype(char_u *name) |
7 | 3184 { |
3185 struct stat st; | |
3186 | |
3187 if (stat((char *)name, &st)) | |
3188 return NODE_NORMAL; | |
3189 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) | |
3190 return NODE_NORMAL; | |
3191 if (S_ISBLK(st.st_mode)) /* block device isn't writable */ | |
3192 return NODE_OTHER; | |
3193 /* Everything else is writable? */ | |
3194 return NODE_WRITABLE; | |
3195 } | |
3196 | |
3197 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3198 mch_early_init(void) |
7 | 3199 { |
3200 #ifdef HAVE_CHECK_STACK_GROWTH | |
3201 int i; | |
180 | 3202 |
7 | 3203 check_stack_growth((char *)&i); |
3204 | |
180 | 3205 # ifdef HAVE_STACK_LIMIT |
7 | 3206 get_stack_limit(); |
3207 # endif | |
3208 | |
3209 #endif | |
3210 | |
3211 /* | |
3212 * Setup an alternative stack for signals. Helps to catch signals when | |
3213 * running out of stack space. | |
3214 * Use of sigaltstack() is preferred, it's more portable. | |
3215 * Ignore any errors. | |
3216 */ | |
3217 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1737 | 3218 signal_stack = (char *)alloc(SIGSTKSZ); |
7 | 3219 init_signal_stack(); |
3220 #endif | |
3221 } | |
3222 | |
355 | 3223 #if defined(EXITFREE) || defined(PROTO) |
3224 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3225 mch_free_mem(void) |
355 | 3226 { |
359 | 3227 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
3228 if (clip_star.owned) | |
3229 clip_lose_selection(&clip_star); | |
3230 if (clip_plus.owned) | |
3231 clip_lose_selection(&clip_plus); | |
355 | 3232 # endif |
1605 | 3233 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
355 | 3234 if (xterm_Shell != (Widget)0) |
3235 XtDestroyWidget(xterm_Shell); | |
1605 | 3236 # ifndef LESSTIF_VERSION |
3237 /* Lesstif crashes here, lose some memory */ | |
355 | 3238 if (xterm_dpy != NULL) |
3239 XtCloseDisplay(xterm_dpy); | |
3240 if (app_context != (XtAppContext)NULL) | |
1605 | 3241 { |
355 | 3242 XtDestroyApplicationContext(app_context); |
1605 | 3243 # ifdef FEAT_X11 |
3244 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
3245 # endif | |
3246 } | |
3247 # endif | |
355 | 3248 # endif |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
3249 # if defined(FEAT_X11) |
1605 | 3250 if (x11_display != NULL |
3251 # ifdef FEAT_XCLIPBOARD | |
3252 && x11_display != xterm_dpy | |
3253 # endif | |
3254 ) | |
359 | 3255 XCloseDisplay(x11_display); |
3256 # endif | |
3257 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
3258 vim_free(signal_stack); | |
3259 signal_stack = NULL; | |
3260 # endif | |
3261 # ifdef FEAT_TITLE | |
3262 vim_free(oldtitle); | |
3263 vim_free(oldicon); | |
3264 # endif | |
355 | 3265 } |
3266 #endif | |
3267 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3268 static void exit_scroll(void); |
7 | 3269 |
3270 /* | |
3271 * Output a newline when exiting. | |
3272 * Make sure the newline goes to the same stream as the text. | |
3273 */ | |
3274 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3275 exit_scroll(void) |
7 | 3276 { |
167 | 3277 if (silent_mode) |
3278 return; | |
7 | 3279 if (newline_on_exit || msg_didout) |
3280 { | |
3281 if (msg_use_printf()) | |
3282 { | |
3283 if (info_message) | |
3284 mch_msg("\n"); | |
3285 else | |
3286 mch_errmsg("\r\n"); | |
3287 } | |
3288 else | |
3289 out_char('\n'); | |
3290 } | |
3291 else | |
3292 { | |
3293 restore_cterm_colors(); /* get original colors back */ | |
3294 msg_clr_eos_force(); /* clear the rest of the display */ | |
3295 windgoto((int)Rows - 1, 0); /* may have moved the cursor */ | |
3296 } | |
3297 } | |
3298 | |
3299 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3300 mch_exit(int r) |
7 | 3301 { |
3302 exiting = TRUE; | |
3303 | |
3304 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
3305 x11_export_final_selection(); | |
3306 #endif | |
3307 | |
3308 #ifdef FEAT_GUI | |
3309 if (!gui.in_use) | |
3310 #endif | |
3311 { | |
3312 settmode(TMODE_COOK); | |
3313 #ifdef FEAT_TITLE | |
3314 mch_restore_title(3); /* restore xterm title and icon name */ | |
3315 #endif | |
3316 /* | |
3317 * When t_ti is not empty but it doesn't cause swapping terminal | |
3318 * pages, need to output a newline when msg_didout is set. But when | |
3319 * t_ti does swap pages it should not go to the shell page. Do this | |
3320 * before stoptermcap(). | |
3321 */ | |
3322 if (swapping_screen() && !newline_on_exit) | |
3323 exit_scroll(); | |
3324 | |
3325 /* Stop termcap: May need to check for T_CRV response, which | |
3326 * requires RAW mode. */ | |
3327 stoptermcap(); | |
3328 | |
3329 /* | |
3330 * A newline is only required after a message in the alternate screen. | |
3331 * This is set to TRUE by wait_return(). | |
3332 */ | |
3333 if (!swapping_screen() || newline_on_exit) | |
3334 exit_scroll(); | |
3335 | |
3336 /* Cursor may have been switched off without calling starttermcap() | |
3337 * when doing "vim -u vimrc" and vimrc contains ":q". */ | |
3338 if (full_screen) | |
3339 cursor_on(); | |
3340 } | |
3341 out_flush(); | |
3342 ml_close_all(TRUE); /* remove all memfiles */ | |
3343 may_core_dump(); | |
3344 #ifdef FEAT_GUI | |
3345 if (gui.in_use) | |
3346 gui_exit(r); | |
3347 #endif | |
167 | 3348 |
765 | 3349 #ifdef MACOS_CONVERT |
167 | 3350 mac_conv_cleanup(); |
3351 #endif | |
3352 | |
7 | 3353 #ifdef __QNX__ |
3354 /* A core dump won't be created if the signal handler | |
3355 * doesn't return, so we can't call exit() */ | |
3356 if (deadly_signal != 0) | |
3357 return; | |
3358 #endif | |
3359 | |
33 | 3360 #ifdef FEAT_NETBEANS_INTG |
2210 | 3361 netbeans_send_disconnect(); |
33 | 3362 #endif |
355 | 3363 |
3364 #ifdef EXITFREE | |
3365 free_all_mem(); | |
3366 #endif | |
3367 | |
7 | 3368 exit(r); |
3369 } | |
3370 | |
3371 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3372 may_core_dump(void) |
7 | 3373 { |
3374 if (deadly_signal != 0) | |
3375 { | |
3376 signal(deadly_signal, SIG_DFL); | |
3377 kill(getpid(), deadly_signal); /* Die using the signal we caught */ | |
3378 } | |
3379 } | |
3380 | |
3381 #ifndef VMS | |
3382 | |
3383 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3384 mch_settmode(int tmode) |
7 | 3385 { |
3386 static int first = TRUE; | |
3387 | |
3388 /* Why is NeXT excluded here (and not in os_unixx.h)? */ | |
3389 #if defined(ECHOE) && defined(ICANON) && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) && !defined(__NeXT__) | |
3390 /* | |
3391 * for "new" tty systems | |
3392 */ | |
3393 # ifdef HAVE_TERMIOS_H | |
3394 static struct termios told; | |
3395 struct termios tnew; | |
3396 # else | |
3397 static struct termio told; | |
3398 struct termio tnew; | |
3399 # endif | |
3400 | |
3401 if (first) | |
3402 { | |
3403 first = FALSE; | |
3404 # if defined(HAVE_TERMIOS_H) | |
3405 tcgetattr(read_cmd_fd, &told); | |
3406 # else | |
3407 ioctl(read_cmd_fd, TCGETA, &told); | |
3408 # endif | |
3409 } | |
3410 | |
3411 tnew = told; | |
3412 if (tmode == TMODE_RAW) | |
3413 { | |
3414 /* | |
3415 * ~ICRNL enables typing ^V^M | |
3416 */ | |
3417 tnew.c_iflag &= ~ICRNL; | |
3418 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE | |
3419 # if defined(IEXTEN) && !defined(__MINT__) | |
3420 | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ | |
3421 /* but it breaks function keys on MINT */ | |
3422 # endif | |
3423 ); | |
3424 # ifdef ONLCR /* don't map NL -> CR NL, we do it ourselves */ | |
3425 tnew.c_oflag &= ~ONLCR; | |
3426 # endif | |
3427 tnew.c_cc[VMIN] = 1; /* return after 1 char */ | |
3428 tnew.c_cc[VTIME] = 0; /* don't wait */ | |
3429 } | |
3430 else if (tmode == TMODE_SLEEP) | |
9381
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3431 { |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3432 /* 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
|
3433 * typeahead characters. */ |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3434 tnew.c_lflag &= ~(ICANON | ECHO); |
c665cc3292e0
commit https://github.com/vim/vim/commit/40de45664c20e7ca46a28a3f472202f90e47f8bf
Christian Brabandt <cb@256bit.org>
parents:
9262
diff
changeset
|
3435 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
|
3436 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
|
3437 } |
7 | 3438 |
3439 # if defined(HAVE_TERMIOS_H) | |
3440 { | |
3441 int n = 10; | |
3442 | |
3443 /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a | |
3444 * few times. */ | |
3445 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 | |
3446 && errno == EINTR && n > 0) | |
3447 --n; | |
3448 } | |
3449 # else | |
3450 ioctl(read_cmd_fd, TCSETA, &tnew); | |
3451 # endif | |
3452 | |
3453 #else | |
3454 | |
3455 /* | |
3456 * for "old" tty systems | |
3457 */ | |
3458 # ifndef TIOCSETN | |
3459 # define TIOCSETN TIOCSETP /* for hpux 9.0 */ | |
3460 # endif | |
3461 static struct sgttyb ttybold; | |
3462 struct sgttyb ttybnew; | |
3463 | |
3464 if (first) | |
3465 { | |
3466 first = FALSE; | |
3467 ioctl(read_cmd_fd, TIOCGETP, &ttybold); | |
3468 } | |
3469 | |
3470 ttybnew = ttybold; | |
3471 if (tmode == TMODE_RAW) | |
3472 { | |
3473 ttybnew.sg_flags &= ~(CRMOD | ECHO); | |
3474 ttybnew.sg_flags |= RAW; | |
3475 } | |
3476 else if (tmode == TMODE_SLEEP) | |
3477 ttybnew.sg_flags &= ~(ECHO); | |
3478 ioctl(read_cmd_fd, TIOCSETN, &ttybnew); | |
3479 #endif | |
3480 curr_tmode = tmode; | |
3481 } | |
3482 | |
3483 /* | |
3484 * Try to get the code for "t_kb" from the stty setting | |
3485 * | |
3486 * Even if termcap claims a backspace key, the user's setting *should* | |
3487 * prevail. stty knows more about reality than termcap does, and if | |
3488 * somebody's usual erase key is DEL (which, for most BSD users, it will | |
3489 * be), they're going to get really annoyed if their erase key starts | |
3490 * doing forward deletes for no reason. (Eric Fischer) | |
3491 */ | |
3492 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3493 get_stty(void) |
7 | 3494 { |
3495 char_u buf[2]; | |
3496 char_u *p; | |
3497 | |
3498 /* Why is NeXT excluded here (and not in os_unixx.h)? */ | |
3499 #if defined(ECHOE) && defined(ICANON) && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) && !defined(__NeXT__) | |
3500 /* for "new" tty systems */ | |
3501 # ifdef HAVE_TERMIOS_H | |
3502 struct termios keys; | |
3503 # else | |
3504 struct termio keys; | |
3505 # endif | |
3506 | |
3507 # if defined(HAVE_TERMIOS_H) | |
3508 if (tcgetattr(read_cmd_fd, &keys) != -1) | |
3509 # else | |
3510 if (ioctl(read_cmd_fd, TCGETA, &keys) != -1) | |
3511 # endif | |
3512 { | |
3513 buf[0] = keys.c_cc[VERASE]; | |
3514 intr_char = keys.c_cc[VINTR]; | |
3515 #else | |
3516 /* for "old" tty systems */ | |
3517 struct sgttyb keys; | |
3518 | |
3519 if (ioctl(read_cmd_fd, TIOCGETP, &keys) != -1) | |
3520 { | |
3521 buf[0] = keys.sg_erase; | |
3522 intr_char = keys.sg_kill; | |
3523 #endif | |
3524 buf[1] = NUL; | |
3525 add_termcode((char_u *)"kb", buf, FALSE); | |
3526 | |
3527 /* | |
3528 * If <BS> and <DEL> are now the same, redefine <DEL>. | |
3529 */ | |
3530 p = find_termcode((char_u *)"kD"); | |
3531 if (p != NULL && p[0] == buf[0] && p[1] == buf[1]) | |
3532 do_fixdel(NULL); | |
3533 } | |
3534 #if 0 | |
3535 } /* to keep cindent happy */ | |
3536 #endif | |
3537 } | |
3538 | |
3539 #endif /* VMS */ | |
3540 | |
3541 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) | |
3542 /* | |
3543 * Set mouse clicks on or off. | |
3544 */ | |
3545 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3546 mch_setmouse(int on) |
7 | 3547 { |
3548 static int ison = FALSE; | |
3549 int xterm_mouse_vers; | |
3550 | |
3551 if (on == ison) /* return quickly if nothing to do */ | |
3552 return; | |
3553 | |
3554 xterm_mouse_vers = use_xterm_mouse(); | |
3145 | 3555 |
3556 # ifdef FEAT_MOUSE_URXVT | |
3746 | 3557 if (ttym_flags == TTYM_URXVT) |
3558 { | |
3145 | 3559 out_str_nf((char_u *) |
3560 (on | |
3561 ? IF_EB("\033[?1015h", ESC_STR "[?1015h") | |
3562 : IF_EB("\033[?1015l", ESC_STR "[?1015l"))); | |
3563 ison = on; | |
3564 } | |
3565 # endif | |
3566 | |
3746 | 3567 # ifdef FEAT_MOUSE_SGR |
3568 if (ttym_flags == TTYM_SGR) | |
3569 { | |
3570 out_str_nf((char_u *) | |
3571 (on | |
3572 ? IF_EB("\033[?1006h", ESC_STR "[?1006h") | |
3573 : IF_EB("\033[?1006l", ESC_STR "[?1006l"))); | |
3574 ison = on; | |
3575 } | |
3576 # endif | |
3577 | |
7 | 3578 if (xterm_mouse_vers > 0) |
3579 { | |
3580 if (on) /* enable mouse events, use mouse tracking if available */ | |
3581 out_str_nf((char_u *) | |
3582 (xterm_mouse_vers > 1 | |
3583 ? IF_EB("\033[?1002h", ESC_STR "[?1002h") | |
3584 : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); | |
3585 else /* disable mouse events, could probably always send the same */ | |
3586 out_str_nf((char_u *) | |
3587 (xterm_mouse_vers > 1 | |
3588 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") | |
3589 : IF_EB("\033[?1000l", ESC_STR "[?1000l"))); | |
3590 ison = on; | |
3591 } | |
3592 | |
3593 # ifdef FEAT_MOUSE_DEC | |
3594 else if (ttym_flags == TTYM_DEC) | |
3595 { | |
3596 if (on) /* enable mouse events */ | |
3597 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); | |
3598 else /* disable mouse events */ | |
3599 out_str_nf((char_u *)"\033['z"); | |
3600 ison = on; | |
3601 } | |
3602 # endif | |
3603 | |
3604 # ifdef FEAT_MOUSE_GPM | |
3605 else | |
3606 { | |
3607 if (on) | |
3608 { | |
3609 if (gpm_open()) | |
3610 ison = TRUE; | |
3611 } | |
3612 else | |
3613 { | |
3614 gpm_close(); | |
3615 ison = FALSE; | |
3616 } | |
3617 } | |
3618 # endif | |
3619 | |
1620 | 3620 # ifdef FEAT_SYSMOUSE |
3621 else | |
3622 { | |
3623 if (on) | |
3624 { | |
3625 if (sysmouse_open() == OK) | |
3626 ison = TRUE; | |
3627 } | |
3628 else | |
3629 { | |
3630 sysmouse_close(); | |
3631 ison = FALSE; | |
3632 } | |
3633 } | |
3634 # endif | |
3635 | |
7 | 3636 # ifdef FEAT_MOUSE_JSB |
3637 else | |
3638 { | |
3639 if (on) | |
3640 { | |
3641 /* D - Enable Mouse up/down messages | |
3642 * L - Enable Left Button Reporting | |
3643 * M - Enable Middle Button Reporting | |
3644 * R - Enable Right Button Reporting | |
3645 * K - Enable SHIFT and CTRL key Reporting | |
3646 * + - Enable Advanced messaging of mouse moves and up/down messages | |
3647 * Q - Quiet No Ack | |
3648 * # - Numeric value of mouse pointer required | |
3649 * 0 = Multiview 2000 cursor, used as standard | |
3650 * 1 = Windows Arrow | |
3651 * 2 = Windows I Beam | |
3652 * 3 = Windows Hour Glass | |
3653 * 4 = Windows Cross Hair | |
3654 * 5 = Windows UP Arrow | |
3655 */ | |
4299 | 3656 # ifdef JSBTERM_MOUSE_NONADVANCED |
3657 /* Disables full feedback of pointer movements */ | |
7 | 3658 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", |
3659 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); | |
4299 | 3660 # else |
7 | 3661 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\", |
3662 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\")); | |
4299 | 3663 # endif |
7 | 3664 ison = TRUE; |
3665 } | |
3666 else | |
3667 { | |
3668 out_str_nf((char_u *)IF_EB("\033[0~ZwQ\033\\", | |
3669 ESC_STR "[0~ZwQ" ESC_STR "\\")); | |
3670 ison = FALSE; | |
3671 } | |
3672 } | |
3673 # endif | |
3674 # ifdef FEAT_MOUSE_PTERM | |
3675 else | |
3676 { | |
3677 /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ | |
3678 if (on) | |
3679 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); | |
3680 else | |
3681 out_str_nf("\033[>1l\033[>6l\033[>7l\033[>1l\033[>9h"); | |
3682 ison = on; | |
3683 } | |
3684 # endif | |
3685 } | |
3686 | |
3687 /* | |
3688 * Set the mouse termcode, depending on the 'term' and 'ttymouse' options. | |
3689 */ | |
3690 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3691 check_mouse_termcode(void) |
7 | 3692 { |
3693 # ifdef FEAT_MOUSE_XTERM | |
3694 if (use_xterm_mouse() | |
3145 | 3695 # ifdef FEAT_MOUSE_URXVT |
3696 && use_xterm_mouse() != 3 | |
3697 # endif | |
7 | 3698 # ifdef FEAT_GUI |
3699 && !gui.in_use | |
3700 # endif | |
3701 ) | |
3702 { | |
3703 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
180 | 3704 ? IF_EB("\233M", CSI_STR "M") |
3705 : IF_EB("\033[M", ESC_STR "[M"))); | |
7 | 3706 if (*p_mouse != NUL) |
3707 { | |
3708 /* force mouse off and maybe on to send possibly new mouse | |
3709 * activation sequence to the xterm, with(out) drag tracing. */ | |
3710 mch_setmouse(FALSE); | |
3711 setmouse(); | |
3712 } | |
3713 } | |
3714 else | |
3715 del_mouse_termcode(KS_MOUSE); | |
3716 # endif | |
3717 | |
3718 # ifdef FEAT_MOUSE_GPM | |
3719 if (!use_xterm_mouse() | |
3720 # ifdef FEAT_GUI | |
3721 && !gui.in_use | |
3722 # endif | |
3723 ) | |
3724 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MG", ESC_STR "MG")); | |
3725 # endif | |
3726 | |
1620 | 3727 # ifdef FEAT_SYSMOUSE |
3728 if (!use_xterm_mouse() | |
3729 # ifdef FEAT_GUI | |
3730 && !gui.in_use | |
3731 # endif | |
3732 ) | |
3733 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS")); | |
3734 # endif | |
3735 | |
7 | 3736 # ifdef FEAT_MOUSE_JSB |
6102 | 3737 /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ |
7 | 3738 if (!use_xterm_mouse() |
3739 # ifdef FEAT_GUI | |
3740 && !gui.in_use | |
3741 # endif | |
3742 ) | |
3743 set_mouse_termcode(KS_JSBTERM_MOUSE, | |
3744 (char_u *)IF_EB("\033[0~zw", ESC_STR "[0~zw")); | |
3745 else | |
3746 del_mouse_termcode(KS_JSBTERM_MOUSE); | |
3747 # endif | |
3748 | |
3749 # ifdef FEAT_MOUSE_NET | |
180 | 3750 /* There is no conflict, but one may type "ESC }" from Insert mode. Don't |
7 | 3751 * define it in the GUI or when using an xterm. */ |
3752 if (!use_xterm_mouse() | |
3753 # ifdef FEAT_GUI | |
3754 && !gui.in_use | |
3755 # endif | |
3756 ) | |
3757 set_mouse_termcode(KS_NETTERM_MOUSE, | |
3758 (char_u *)IF_EB("\033}", ESC_STR "}")); | |
3759 else | |
3760 del_mouse_termcode(KS_NETTERM_MOUSE); | |
3761 # endif | |
3762 | |
3763 # ifdef FEAT_MOUSE_DEC | |
6102 | 3764 /* Conflicts with xterm mouse: "\033[" and "\033[M" */ |
5932 | 3765 if (!use_xterm_mouse() |
7 | 3766 # ifdef FEAT_GUI |
3767 && !gui.in_use | |
3768 # endif | |
3769 ) | |
180 | 3770 set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME) |
3771 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); | |
7 | 3772 else |
3773 del_mouse_termcode(KS_DEC_MOUSE); | |
3774 # endif | |
3775 # ifdef FEAT_MOUSE_PTERM | |
6102 | 3776 /* same conflict as the dec mouse */ |
5932 | 3777 if (!use_xterm_mouse() |
7 | 3778 # ifdef FEAT_GUI |
3779 && !gui.in_use | |
3780 # endif | |
3781 ) | |
3782 set_mouse_termcode(KS_PTERM_MOUSE, | |
3783 (char_u *) IF_EB("\033[", ESC_STR "[")); | |
3784 else | |
3785 del_mouse_termcode(KS_PTERM_MOUSE); | |
3786 # endif | |
3145 | 3787 # ifdef FEAT_MOUSE_URXVT |
5932 | 3788 if (use_xterm_mouse() == 3 |
3145 | 3789 # ifdef FEAT_GUI |
3790 && !gui.in_use | |
3791 # endif | |
3792 ) | |
3793 { | |
3794 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
|
3795 ? 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
|
3796 : IF_EB("\033[*M", ESC_STR "[*M"))); |
3145 | 3797 |
3798 if (*p_mouse != NUL) | |
3799 { | |
3800 mch_setmouse(FALSE); | |
3801 setmouse(); | |
3802 } | |
3803 } | |
3804 else | |
3805 del_mouse_termcode(KS_URXVT_MOUSE); | |
3806 # endif | |
3746 | 3807 # ifdef FEAT_MOUSE_SGR |
3808 if (use_xterm_mouse() == 4 | |
3809 # ifdef FEAT_GUI | |
3810 && !gui.in_use | |
3811 # endif | |
3812 ) | |
3813 { | |
3814 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
|
3815 ? 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
|
3816 : 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
|
3817 |
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3818 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
|
3819 ? 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
|
3820 : IF_EB("\033[<*m", ESC_STR "[<*m"))); |
3746 | 3821 |
3822 if (*p_mouse != NUL) | |
3823 { | |
3824 mch_setmouse(FALSE); | |
3825 setmouse(); | |
3826 } | |
3827 } | |
3828 else | |
11557
7e5e76d8d451
patch 8.0.0661: recognizing urxvt mouse codes does not work well
Christian Brabandt <cb@256bit.org>
parents:
11281
diff
changeset
|
3829 { |
3746 | 3830 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
|
3831 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
|
3832 } |
3746 | 3833 # endif |
7 | 3834 } |
3835 #endif | |
3836 | |
3837 /* | |
3838 * set screen mode, always fails. | |
3839 */ | |
3840 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3841 mch_screenmode(char_u *arg UNUSED) |
7 | 3842 { |
3843 EMSG(_(e_screenmode)); | |
3844 return FAIL; | |
3845 } | |
3846 | |
3847 #ifndef VMS | |
3848 | |
3849 /* | |
3850 * Try to get the current window size: | |
3851 * 1. with an ioctl(), most accurate method | |
3852 * 2. from the environment variables LINES and COLUMNS | |
3853 * 3. from the termcap | |
3854 * 4. keep using the old values | |
3855 * Return OK when size could be determined, FAIL otherwise. | |
3856 */ | |
3857 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3858 mch_get_shellsize(void) |
7 | 3859 { |
3860 long rows = 0; | |
3861 long columns = 0; | |
3862 char_u *p; | |
3863 | |
3864 /* | |
3865 * 1. try using an ioctl. It is the most accurate method. | |
3866 * | |
3867 * Try using TIOCGWINSZ first, some systems that have it also define | |
3868 * TIOCGSIZE but don't have a struct ttysize. | |
3869 */ | |
3870 # ifdef TIOCGWINSZ | |
3871 { | |
3872 struct winsize ws; | |
3873 int fd = 1; | |
3874 | |
3875 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
3876 if (!isatty(fd) && isatty(read_cmd_fd)) | |
3877 fd = read_cmd_fd; | |
3878 if (ioctl(fd, TIOCGWINSZ, &ws) == 0) | |
3879 { | |
3880 columns = ws.ws_col; | |
3881 rows = ws.ws_row; | |
3882 } | |
3883 } | |
3884 # else /* TIOCGWINSZ */ | |
3885 # ifdef TIOCGSIZE | |
3886 { | |
3887 struct ttysize ts; | |
3888 int fd = 1; | |
3889 | |
3890 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
3891 if (!isatty(fd) && isatty(read_cmd_fd)) | |
3892 fd = read_cmd_fd; | |
3893 if (ioctl(fd, TIOCGSIZE, &ts) == 0) | |
3894 { | |
3895 columns = ts.ts_cols; | |
3896 rows = ts.ts_lines; | |
3897 } | |
3898 } | |
3899 # endif /* TIOCGSIZE */ | |
3900 # endif /* TIOCGWINSZ */ | |
3901 | |
3902 /* | |
3903 * 2. get size from environment | |
164 | 3904 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules |
3905 * the ioctl() values! | |
7 | 3906 */ |
164 | 3907 if (columns == 0 || rows == 0 || vim_strchr(p_cpo, CPO_TSIZE) != NULL) |
7 | 3908 { |
3909 if ((p = (char_u *)getenv("LINES"))) | |
3910 rows = atoi((char *)p); | |
3911 if ((p = (char_u *)getenv("COLUMNS"))) | |
3912 columns = atoi((char *)p); | |
3913 } | |
3914 | |
3915 #ifdef HAVE_TGETENT | |
3916 /* | |
3917 * 3. try reading "co" and "li" entries from termcap | |
3918 */ | |
3919 if (columns == 0 || rows == 0) | |
3920 getlinecol(&columns, &rows); | |
3921 #endif | |
3922 | |
3923 /* | |
3924 * 4. If everything fails, use the old values | |
3925 */ | |
3926 if (columns <= 0 || rows <= 0) | |
3927 return FAIL; | |
3928 | |
3929 Rows = rows; | |
3930 Columns = columns; | |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
3931 limit_screen_size(); |
7 | 3932 return OK; |
3933 } | |
3934 | |
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
|
3935 #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
|
3936 /* |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3937 * 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
|
3938 */ |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3939 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
|
3940 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
|
3941 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3942 # 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
|
3943 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
|
3944 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3945 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
|
3946 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
|
3947 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
|
3948 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
|
3949 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
|
3950 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3951 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
|
3952 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
|
3953 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3954 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
|
3955 # 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
|
3956 # 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
|
3957 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
|
3958 |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3959 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
|
3960 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
|
3961 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
|
3962 { |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3963 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
|
3964 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
|
3965 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3966 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
|
3967 # 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
|
3968 # 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
|
3969 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
|
3970 } |
b4d8f956eb18
patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents:
11731
diff
changeset
|
3971 #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
|
3972 |
7 | 3973 /* |
3974 * Try to set the window size to Rows and Columns. | |
3975 */ | |
3976 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3977 mch_set_shellsize(void) |
7 | 3978 { |
3979 if (*T_CWS) | |
3980 { | |
3981 /* | |
3982 * NOTE: if you get an error here that term_set_winsize() is | |
3983 * undefined, check the output of configure. It could probably not | |
3984 * find a ncurses, termcap or termlib library. | |
3985 */ | |
3986 term_set_winsize((int)Rows, (int)Columns); | |
3987 out_flush(); | |
3988 screen_start(); /* don't know where cursor is now */ | |
3989 } | |
3990 } | |
3991 | |
3992 #endif /* VMS */ | |
3993 | |
3994 /* | |
3995 * Rows and/or Columns has changed. | |
3996 */ | |
3997 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3998 mch_new_shellsize(void) |
7 | 3999 { |
4000 /* Nothing to do. */ | |
4001 } | |
4002 | |
3048 | 4003 /* |
4004 * Wait for process "child" to end. | |
4005 * Return "child" if it exited properly, <= 0 on error. | |
4006 */ | |
4007 static pid_t | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4008 wait4pid(pid_t child, waitstatus *status) |
3048 | 4009 { |
4010 pid_t wait_pid = 0; | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4011 long delay_msec = 1; |
3048 | 4012 |
4013 while (wait_pid != child) | |
4014 { | |
3470 | 4015 /* When compiled with Python threads are probably used, in which case |
4016 * wait() sometimes hangs for no obvious reason. Use waitpid() | |
4017 * instead and loop (like the GUI). Also needed for other interfaces, | |
4018 * they might call system(). */ | |
4019 # ifdef __NeXT__ | |
3048 | 4020 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); |
3470 | 4021 # else |
3048 | 4022 wait_pid = waitpid(child, status, WNOHANG); |
3470 | 4023 # endif |
3048 | 4024 if (wait_pid == 0) |
4025 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4026 /* 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
|
4027 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4028 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
4029 delay_msec = 10; |
3048 | 4030 continue; |
4031 } | |
4032 if (wait_pid <= 0 | |
4033 # ifdef ECHILD | |
4034 && errno == ECHILD | |
4035 # endif | |
4036 ) | |
4037 break; | |
4038 } | |
4039 return wait_pid; | |
4040 } | |
4041 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4042 #if defined(FEAT_JOB_CHANNEL) || !defined(USE_SYSTEM) || defined(PROTO) |
7999
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
4043 /* |
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
4044 * Parse "cmd" and put the white-separated parts in "argv". |
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
4045 * "argv" is an allocated array with "argc" entries. |
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
4046 * Returns FAIL when out of memory. |
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
4047 */ |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4048 int |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4049 mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4050 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4051 int i; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4052 char_u *p; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4053 int inquote; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4054 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4055 /* |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4056 * Do this loop twice: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4057 * 1: find number of arguments |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4058 * 2: separate them and build argv[] |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4059 */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4060 for (i = 0; i < 2; ++i) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4061 { |
9009
149d976650a1
commit https://github.com/vim/vim/commit/6231cb8b5b208becf088531816027001acc754e5
Christian Brabandt <cb@256bit.org>
parents:
8958
diff
changeset
|
4062 p = skipwhite(cmd); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4063 inquote = FALSE; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4064 *argc = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4065 for (;;) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4066 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4067 if (i == 1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4068 (*argv)[*argc] = (char *)p; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4069 ++*argc; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4070 while (*p != NUL && (inquote || (*p != ' ' && *p != TAB))) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4071 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4072 if (*p == '"') |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4073 inquote = !inquote; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4074 ++p; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4075 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4076 if (*p == NUL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4077 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4078 if (i == 1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4079 *p++ = NUL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4080 p = skipwhite(p); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4081 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4082 if (*argv == NULL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4083 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4084 if (use_shcf) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4085 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4086 /* Account for possible multiple args in p_shcf. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4087 p = p_shcf; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4088 for (;;) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4089 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4090 p = skiptowhite(p); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4091 if (*p == NUL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4092 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4093 ++*argc; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4094 p = skipwhite(p); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4095 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4096 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4097 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4098 *argv = (char **)alloc((unsigned)((*argc + 4) * sizeof(char *))); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4099 if (*argv == NULL) /* out of memory */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4100 return FAIL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4101 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4102 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4103 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4104 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4105 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4106 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4107 #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
|
4108 /* |
3c1b59938042
patch 8.0.0829: job running in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
11894
diff
changeset
|
4109 * 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
|
4110 */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4111 static void |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4112 set_child_environment(long rows, long columns, char *term) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4113 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4114 # ifdef HAVE_SETENV |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4115 char envbuf[50]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4116 # else |
11717
30247960c8a7
patch 8.0.0741: cannot build with HPUX
Christian Brabandt <cb@256bit.org>
parents:
11713
diff
changeset
|
4117 static char envbuf_Term[30]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4118 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
|
4119 static char envbuf_Lines[20]; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4120 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
|
4121 static char envbuf_Colors[20]; |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4122 # 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
|
4123 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
|
4124 # 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
|
4125 # 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
|
4126 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
|
4127 # 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
|
4128 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
|
4129 # 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
|
4130 t_colors; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4131 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4132 # ifdef HAVE_SETENV |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4133 setenv("TERM", term, 1); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4134 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4135 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
|
4136 sprintf((char *)envbuf, "%ld", rows); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4137 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
|
4138 sprintf((char *)envbuf, "%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4139 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
|
4140 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
|
4141 setenv("COLORS", (char *)envbuf, 1); |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4142 # 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
|
4143 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
|
4144 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4145 # else |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4146 /* |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4147 * 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
|
4148 * 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
|
4149 * 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
|
4150 */ |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4151 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
|
4152 putenv(envbuf_Term); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4153 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
|
4154 putenv(envbuf_Rows); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4155 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
|
4156 putenv(envbuf_Lines); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4157 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
|
4158 "COLUMNS=%ld", columns); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4159 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
|
4160 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
|
4161 putenv(envbuf_Colors); |
11908
1e8d353cb827
patch 8.0.0834: can't build without the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11898
diff
changeset
|
4162 # 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
|
4163 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
|
4164 "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
|
4165 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
|
4166 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4167 # endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4168 } |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4169 |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4170 static void |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4171 set_default_child_environment(void) |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4172 { |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4173 set_child_environment(Rows, Columns, "dumb"); |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4174 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4175 #endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4176 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4177 #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
|
4178 /* |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
4179 * 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
|
4180 * 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
|
4181 * 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
|
4182 */ |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4183 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
|
4184 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
|
4185 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4186 char *tty_name; |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4187 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4188 *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
|
4189 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
|
4190 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4191 /* 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
|
4192 * 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
|
4193 * 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
|
4194 #ifdef O_NOCTTY |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4195 *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
|
4196 #else |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4197 *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
|
4198 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4199 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
|
4200 { |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4201 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
|
4202 *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
|
4203 } |
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
|
4204 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
|
4205 *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
|
4206 } |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4207 } |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4208 #endif |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
4209 |
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
|
4210 /* |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4211 * 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
|
4212 */ |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4213 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
|
4214 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
|
4215 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4216 # 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
|
4217 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
|
4218 { |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4219 # 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
|
4220 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
|
4221 # 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
|
4222 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
|
4223 # 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
|
4224 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
|
4225 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
|
4226 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4227 # 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
|
4228 } |
cca097489de5
patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
11908
diff
changeset
|
4229 |
7 | 4230 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4231 mch_call_shell( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4232 char_u *cmd, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4233 int options) /* SHELL_*, see vim.h */ |
7 | 4234 { |
4235 #ifdef VMS | |
4236 char *ifn = NULL; | |
4237 char *ofn = NULL; | |
4238 #endif | |
4239 int tmode = cur_tmode; | |
4240 #ifdef USE_SYSTEM /* use system() to start the shell: simple but slow */ | |
9552
49512aba8e32
commit https://github.com/vim/vim/commit/b2b050ab16565c117f0e7e411ffef3700d99203b
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
4241 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
|
4242 int x; |
7 | 4243 |
4244 out_flush(); | |
4245 | |
4246 if (options & SHELL_COOKED) | |
4247 settmode(TMODE_COOK); /* set to normal mode */ | |
4248 | |
2586 | 4249 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4209 | 4250 save_clipboard(); |
2586 | 4251 loose_clipboard(); |
4252 # endif | |
4253 | |
7 | 4254 if (cmd == NULL) |
4255 x = system((char *)p_sh); | |
4256 else | |
4257 { | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4258 # ifdef VMS |
7 | 4259 if (ofn = strchr((char *)cmd, '>')) |
4260 *ofn++ = '\0'; | |
4261 if (ifn = strchr((char *)cmd, '<')) | |
4262 { | |
4263 char *p; | |
4264 | |
4265 *ifn++ = '\0'; | |
4266 p = strchr(ifn,' '); /* chop off any trailing spaces */ | |
4267 if (p) | |
4268 *p = '\0'; | |
4269 } | |
4270 if (ofn) | |
4271 x = vms_sys((char *)cmd, ofn, ifn); | |
4272 else | |
4273 x = system((char *)cmd); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4274 # else |
7 | 4275 newcmd = lalloc(STRLEN(p_sh) |
4276 + (extra_shell_arg == NULL ? 0 : STRLEN(extra_shell_arg)) | |
4277 + STRLEN(p_shcf) + STRLEN(cmd) + 4, TRUE); | |
4278 if (newcmd == NULL) | |
4279 x = 0; | |
4280 else | |
4281 { | |
4282 sprintf((char *)newcmd, "%s %s %s %s", p_sh, | |
4283 extra_shell_arg == NULL ? "" : (char *)extra_shell_arg, | |
4284 (char *)p_shcf, | |
4285 (char *)cmd); | |
4286 x = system((char *)newcmd); | |
4287 vim_free(newcmd); | |
4288 } | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
4289 # endif |
7 | 4290 } |
4291 # ifdef VMS | |
4292 x = vms_sys_status(x); | |
4293 # endif | |
4294 if (emsg_silent) | |
4295 ; | |
4296 else if (x == 127) | |
4297 MSG_PUTS(_("\nCannot execute shell sh\n")); | |
4298 else if (x && !(options & SHELL_SILENT)) | |
4299 { | |
4300 MSG_PUTS(_("\nshell returned ")); | |
4301 msg_outnum((long)x); | |
4302 msg_putchar('\n'); | |
4303 } | |
4304 | |
4305 if (tmode == TMODE_RAW) | |
4306 settmode(TMODE_RAW); /* set to raw mode */ | |
4307 # ifdef FEAT_TITLE | |
4308 resettitle(); | |
4309 # endif | |
4209 | 4310 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4311 restore_clipboard(); | |
4312 # endif | |
7 | 4313 return x; |
4314 | |
4315 #else /* USE_SYSTEM */ /* don't use system(), use fork()/exec() */ | |
4316 | |
167 | 4317 # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use |
4318 127, some shells use that already */ | |
7 | 4319 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4320 char_u *newcmd; |
7 | 4321 pid_t pid; |
167 | 4322 pid_t wpid = 0; |
7 | 4323 pid_t wait_pid = 0; |
4324 # ifdef HAVE_UNION_WAIT | |
4325 union wait status; | |
4326 # else | |
4327 int status = -1; | |
4328 # endif | |
4329 int retval = -1; | |
4330 char **argv = NULL; | |
4331 int argc; | |
2994 | 4332 char_u *p_shcf_copy = NULL; |
7 | 4333 int i; |
4334 char_u *p; | |
167 | 4335 int pty_master_fd = -1; /* for pty's */ |
7 | 4336 # ifdef FEAT_GUI |
4337 int pty_slave_fd = -1; | |
167 | 4338 # endif |
602 | 4339 int fd_toshell[2]; /* for pipes */ |
7 | 4340 int fd_fromshell[2]; |
4341 int pipe_error = FALSE; | |
602 | 4342 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ |
7 | 4343 |
2586 | 4344 newcmd = vim_strsave(p_sh); |
4345 if (newcmd == NULL) /* out of memory */ | |
4346 goto error; | |
4347 | |
7 | 4348 out_flush(); |
4349 if (options & SHELL_COOKED) | |
4350 settmode(TMODE_COOK); /* set to normal mode */ | |
4351 | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4352 if (mch_parse_cmd(newcmd, TRUE, &argv, &argc) == FAIL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4353 goto error; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4354 |
7 | 4355 if (cmd != NULL) |
4356 { | |
3263 | 4357 char_u *s; |
4358 | |
7 | 4359 if (extra_shell_arg != NULL) |
4360 argv[argc++] = (char *)extra_shell_arg; | |
2994 | 4361 |
4362 /* Break 'shellcmdflag' into white separated parts. This doesn't | |
4363 * handle quoted strings, they are very unlikely to appear. */ | |
4364 p_shcf_copy = alloc((unsigned)STRLEN(p_shcf) + 1); | |
4365 if (p_shcf_copy == NULL) /* out of memory */ | |
4366 goto error; | |
4367 s = p_shcf_copy; | |
4368 p = p_shcf; | |
4369 while (*p != NUL) | |
4370 { | |
4371 argv[argc++] = (char *)s; | |
4372 while (*p && *p != ' ' && *p != TAB) | |
4373 *s++ = *p++; | |
4374 *s++ = NUL; | |
4375 p = skipwhite(p); | |
4376 } | |
4377 | |
7 | 4378 argv[argc++] = (char *)cmd; |
4379 } | |
4380 argv[argc] = NULL; | |
4381 | |
167 | 4382 /* |
4383 * For the GUI, when writing the output into the buffer and when reading | |
4384 * input from the buffer: Try using a pseudo-tty to get the stdin/stdout | |
4385 * of the executed command into the Vim window. Or use a pipe. | |
4386 */ | |
4387 if ((options & (SHELL_READ|SHELL_WRITE)) | |
7 | 4388 # ifdef FEAT_GUI |
167 | 4389 || (gui.in_use && show_shell_mess) |
4390 # endif | |
4391 ) | |
7 | 4392 { |
167 | 4393 # ifdef FEAT_GUI |
7 | 4394 /* |
4395 * Try to open a master pty. | |
4396 * If this works, open the slave pty. | |
4397 * If the slave can't be opened, close the master pty. | |
4398 */ | |
167 | 4399 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
|
4400 open_pty(&pty_master_fd, &pty_slave_fd, NULL); |
7 | 4401 /* |
4402 * If not opening a pty or it didn't work, try using pipes. | |
4403 */ | |
4404 if (pty_master_fd < 0) | |
167 | 4405 # endif |
7 | 4406 { |
4407 pipe_error = (pipe(fd_toshell) < 0); | |
4408 if (!pipe_error) /* pipe create OK */ | |
4409 { | |
4410 pipe_error = (pipe(fd_fromshell) < 0); | |
4411 if (pipe_error) /* pipe create failed */ | |
4412 { | |
4413 close(fd_toshell[0]); | |
4414 close(fd_toshell[1]); | |
4415 } | |
4416 } | |
4417 if (pipe_error) | |
4418 { | |
4419 MSG_PUTS(_("\nCannot create pipes\n")); | |
4420 out_flush(); | |
4421 } | |
4422 } | |
4423 } | |
4424 | |
4425 if (!pipe_error) /* pty or pipe opened or not used */ | |
4426 { | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4427 SIGSET_DECL(curset) |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4428 |
7 | 4429 # ifdef __BEOS__ |
4430 beos_cleanup_read_thread(); | |
4431 # endif | |
602 | 4432 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4433 BLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4434 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
|
4435 if (pid == -1) |
7 | 4436 { |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4437 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4438 |
7 | 4439 MSG_PUTS(_("\nCannot fork\n")); |
167 | 4440 if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4441 # ifdef FEAT_GUI |
167 | 4442 || (gui.in_use && show_shell_mess) |
4443 # endif | |
4444 ) | |
7 | 4445 { |
167 | 4446 # ifdef FEAT_GUI |
7 | 4447 if (pty_master_fd >= 0) /* close the pseudo tty */ |
4448 { | |
4449 close(pty_master_fd); | |
4450 close(pty_slave_fd); | |
4451 } | |
4452 else /* close the pipes */ | |
167 | 4453 # endif |
7 | 4454 { |
4455 close(fd_toshell[0]); | |
4456 close(fd_toshell[1]); | |
4457 close(fd_fromshell[0]); | |
4458 close(fd_fromshell[1]); | |
4459 } | |
4460 } | |
4461 } | |
4462 else if (pid == 0) /* child */ | |
4463 { | |
4464 reset_signals(); /* handle signals normally */ | |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4465 UNBLOCK_SIGNALS(&curset); |
7 | 4466 |
4467 if (!show_shell_mess || (options & SHELL_EXPAND)) | |
4468 { | |
4469 int fd; | |
4470 | |
4471 /* | |
4472 * Don't want to show any message from the shell. Can't just | |
4473 * close stdout and stderr though, because some systems will | |
4474 * break if you try to write to them after that, so we must | |
4475 * use dup() to replace them with something else -- webb | |
4476 * Connect stdin to /dev/null too, so ":n `cat`" doesn't hang, | |
4477 * waiting for input. | |
4478 */ | |
4479 fd = open("/dev/null", O_RDWR | O_EXTRA, 0); | |
4480 fclose(stdin); | |
4481 fclose(stdout); | |
4482 fclose(stderr); | |
4483 | |
4484 /* | |
4485 * If any of these open()'s and dup()'s fail, we just continue | |
4486 * anyway. It's not fatal, and on most systems it will make | |
4487 * no difference at all. On a few it will cause the execvp() | |
4488 * to exit with a non-zero status even when the completion | |
4489 * could be done, which is nothing too serious. If the open() | |
4490 * or dup() failed we'd just do the same thing ourselves | |
4491 * anyway -- webb | |
4492 */ | |
4493 if (fd >= 0) | |
4494 { | |
1757 | 4495 ignored = dup(fd); /* To replace stdin (fd 0) */ |
4496 ignored = dup(fd); /* To replace stdout (fd 1) */ | |
4497 ignored = dup(fd); /* To replace stderr (fd 2) */ | |
7 | 4498 |
4499 /* Don't need this now that we've duplicated it */ | |
4500 close(fd); | |
4501 } | |
4502 } | |
167 | 4503 else if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4504 # ifdef FEAT_GUI |
167 | 4505 || gui.in_use |
4506 # endif | |
4507 ) | |
7 | 4508 { |
4509 | |
167 | 4510 # ifdef HAVE_SETSID |
602 | 4511 /* Create our own process group, so that the child and all its |
4512 * children can be kill()ed. Don't do this when using pipes, | |
1698 | 4513 * because stdin is not a tty, we would lose /dev/tty. */ |
602 | 4514 if (p_stmp) |
1799 | 4515 { |
602 | 4516 (void)setsid(); |
1799 | 4517 # if defined(SIGHUP) |
4518 /* When doing "!xterm&" and 'shell' is bash: the shell | |
4519 * will exit and send SIGHUP to all processes in its | |
4520 * group, killing the just started process. Ignore SIGHUP | |
4521 * to avoid that. (suggested by Simon Schubert) | |
4522 */ | |
4523 signal(SIGHUP, SIG_IGN); | |
4524 # endif | |
4525 } | |
167 | 4526 # endif |
4527 # ifdef FEAT_GUI | |
602 | 4528 if (pty_slave_fd >= 0) |
4529 { | |
4530 /* push stream discipline modules */ | |
4531 if (options & SHELL_COOKED) | |
4532 SetupSlavePTY(pty_slave_fd); | |
7 | 4533 # ifdef TIOCSCTTY |
602 | 4534 /* Try to become controlling tty (probably doesn't work, |
4535 * unless run by root) */ | |
4536 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); | |
7 | 4537 # endif |
602 | 4538 } |
167 | 4539 # endif |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
4540 set_default_child_environment(); |
167 | 4541 |
557 | 4542 /* |
4543 * stderr is only redirected when using the GUI, so that a | |
4544 * program like gpg can still access the terminal to get a | |
4545 * passphrase using stderr. | |
4546 */ | |
167 | 4547 # ifdef FEAT_GUI |
7 | 4548 if (pty_master_fd >= 0) |
4549 { | |
4550 close(pty_master_fd); /* close master side of pty */ | |
4551 | |
4552 /* set up stdin/stdout/stderr for the child */ | |
4553 close(0); | |
1757 | 4554 ignored = dup(pty_slave_fd); |
7 | 4555 close(1); |
1757 | 4556 ignored = dup(pty_slave_fd); |
557 | 4557 if (gui.in_use) |
4558 { | |
4559 close(2); | |
1757 | 4560 ignored = dup(pty_slave_fd); |
557 | 4561 } |
7 | 4562 |
4563 close(pty_slave_fd); /* has been dupped, close it now */ | |
4564 } | |
4565 else | |
167 | 4566 # endif |
7 | 4567 { |
4568 /* set up stdin for the child */ | |
4569 close(fd_toshell[1]); | |
4570 close(0); | |
1757 | 4571 ignored = dup(fd_toshell[0]); |
7 | 4572 close(fd_toshell[0]); |
4573 | |
4574 /* set up stdout for the child */ | |
4575 close(fd_fromshell[0]); | |
4576 close(1); | |
1757 | 4577 ignored = dup(fd_fromshell[1]); |
7 | 4578 close(fd_fromshell[1]); |
4579 | |
557 | 4580 # ifdef FEAT_GUI |
4581 if (gui.in_use) | |
4582 { | |
4583 /* set up stderr for the child */ | |
4584 close(2); | |
1757 | 4585 ignored = dup(1); |
557 | 4586 } |
4587 # endif | |
7 | 4588 } |
4589 } | |
167 | 4590 |
7 | 4591 /* |
4592 * There is no type cast for the argv, because the type may be | |
4593 * different on different machines. This may cause a warning | |
4594 * message with strict compilers, don't worry about it. | |
4595 * Call _exit() instead of exit() to avoid closing the connection | |
4596 * to the X server (esp. with GTK, which uses atexit()). | |
4597 */ | |
4598 execvp(argv[0], argv); | |
4599 _exit(EXEC_FAILED); /* exec failed, return failure code */ | |
4600 } | |
4601 else /* parent */ | |
4602 { | |
4603 /* | |
4604 * While child is running, ignore terminating signals. | |
167 | 4605 * Do catch CTRL-C, so that "got_int" is set. |
7 | 4606 */ |
4607 catch_signals(SIG_IGN, SIG_ERR); | |
167 | 4608 catch_int_signal(); |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
4609 UNBLOCK_SIGNALS(&curset); |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4610 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4611 ++dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
4612 # endif |
7 | 4613 /* |
4614 * For the GUI we redirect stdin, stdout and stderr to our window. | |
167 | 4615 * This is also used to pipe stdin/stdout to/from the external |
4616 * command. | |
7 | 4617 */ |
167 | 4618 if ((options & (SHELL_READ|SHELL_WRITE)) |
4619 # ifdef FEAT_GUI | |
4620 || (gui.in_use && show_shell_mess) | |
4621 # endif | |
4622 ) | |
7 | 4623 { |
167 | 4624 # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ |
7 | 4625 char_u buffer[BUFLEN + 1]; |
167 | 4626 # ifdef FEAT_MBYTE |
7 | 4627 int buffer_off = 0; /* valid bytes in buffer[] */ |
167 | 4628 # endif |
7 | 4629 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ |
4630 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4631 int len; | |
4632 int p_more_save; | |
4633 int old_State; | |
4634 int c; | |
4635 int toshell_fd; | |
4636 int fromshell_fd; | |
167 | 4637 garray_T ga; |
4638 int noread_cnt; | |
1823 | 4639 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) |
4640 struct timeval start_tv; | |
4641 # endif | |
167 | 4642 |
4643 # ifdef FEAT_GUI | |
7 | 4644 if (pty_master_fd >= 0) |
4645 { | |
4646 fromshell_fd = pty_master_fd; | |
4647 toshell_fd = dup(pty_master_fd); | |
4648 } | |
4649 else | |
167 | 4650 # endif |
7 | 4651 { |
4652 close(fd_toshell[0]); | |
4653 close(fd_fromshell[1]); | |
4654 toshell_fd = fd_toshell[1]; | |
4655 fromshell_fd = fd_fromshell[0]; | |
4656 } | |
4657 | |
4658 /* | |
4659 * Write to the child if there are typed characters. | |
4660 * Read from the child if there are characters available. | |
4661 * Repeat the reading a few times if more characters are | |
4662 * available. Need to check for typed keys now and then, but | |
4663 * not too often (delays when no chars are available). | |
4664 * This loop is quit if no characters can be read from the pty | |
4665 * (WaitForChar detected special condition), or there are no | |
4666 * characters available and the child has exited. | |
4667 * Only check if the child has exited when there is no more | |
4668 * output. The child may exit before all the output has | |
4669 * been printed. | |
4670 * | |
4671 * Currently this busy loops! | |
4672 * This can probably dead-lock when the write blocks! | |
4673 */ | |
4674 p_more_save = p_more; | |
4675 p_more = FALSE; | |
4676 old_State = State; | |
4677 State = EXTERNCMD; /* don't redraw at window resize */ | |
4678 | |
602 | 4679 if ((options & SHELL_WRITE) && toshell_fd >= 0) |
167 | 4680 { |
4681 /* Fork a process that will write the lines to the | |
4682 * external program. */ | |
4683 if ((wpid = fork()) == -1) | |
4684 { | |
4685 MSG_PUTS(_("\nCannot fork\n")); | |
4686 } | |
3048 | 4687 else if (wpid == 0) /* child */ |
167 | 4688 { |
4689 linenr_T lnum = curbuf->b_op_start.lnum; | |
4690 int written = 0; | |
944 | 4691 char_u *lp = ml_get(lnum); |
167 | 4692 size_t l; |
4693 | |
177 | 4694 close(fromshell_fd); |
167 | 4695 for (;;) |
4696 { | |
944 | 4697 l = STRLEN(lp + written); |
167 | 4698 if (l == 0) |
4699 len = 0; | |
944 | 4700 else if (lp[written] == NL) |
167 | 4701 /* NL -> NUL translation */ |
4702 len = write(toshell_fd, "", (size_t)1); | |
4703 else | |
4704 { | |
3263 | 4705 char_u *s = vim_strchr(lp + written, NL); |
4706 | |
944 | 4707 len = write(toshell_fd, (char *)lp + written, |
1877 | 4708 s == NULL ? l |
4709 : (size_t)(s - (lp + written))); | |
167 | 4710 } |
1877 | 4711 if (len == (int)l) |
167 | 4712 { |
4713 /* Finished a line, add a NL, unless this line | |
4714 * should not have one. */ | |
4715 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4716 || (!curbuf->b_p_bin |
4717 && curbuf->b_p_fixeol) | |
2707 | 4718 || (lnum != curbuf->b_no_eol_lnum |
167 | 4719 && (lnum != |
4720 curbuf->b_ml.ml_line_count | |
4721 || curbuf->b_p_eol))) | |
1757 | 4722 ignored = write(toshell_fd, "\n", |
4723 (size_t)1); | |
167 | 4724 ++lnum; |
4725 if (lnum > curbuf->b_op_end.lnum) | |
4726 { | |
4727 /* finished all the lines, close pipe */ | |
4728 close(toshell_fd); | |
4729 toshell_fd = -1; | |
4730 break; | |
4731 } | |
944 | 4732 lp = ml_get(lnum); |
167 | 4733 written = 0; |
4734 } | |
4735 else if (len > 0) | |
4736 written += len; | |
4737 } | |
4738 _exit(0); | |
4739 } | |
3048 | 4740 else /* parent */ |
167 | 4741 { |
4742 close(toshell_fd); | |
4743 toshell_fd = -1; | |
4744 } | |
4745 } | |
4746 | |
4747 if (options & SHELL_READ) | |
4748 ga_init2(&ga, 1, BUFLEN); | |
4749 | |
4750 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4751 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4752 ELAPSED_INIT(start_tv); |
1823 | 4753 # endif |
7 | 4754 for (;;) |
4755 { | |
4756 /* | |
4757 * Check if keys have been typed, write them to the child | |
592 | 4758 * if there are any. |
4759 * Don't do this if we are expanding wild cards (would eat | |
4760 * typeahead). | |
4761 * Don't do this when filtering and terminal is in cooked | |
4762 * mode, the shell command will handle the I/O. Avoids | |
4763 * that a typed password is echoed for ssh or gpg command. | |
602 | 4764 * Don't get characters when the child has already |
4765 * finished (wait_pid == 0). | |
167 | 4766 * Don't read characters unless we didn't get output for a |
1823 | 4767 * while (noread_cnt > 4), avoids that ":r !ls" eats |
4768 * typeahead. | |
7 | 4769 */ |
4770 len = 0; | |
4771 if (!(options & SHELL_EXPAND) | |
592 | 4772 && ((options & |
4773 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4774 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
1823 | 4775 # ifdef FEAT_GUI |
592 | 4776 || gui.in_use |
1823 | 4777 # endif |
592 | 4778 ) |
602 | 4779 && wait_pid == 0 |
1823 | 4780 && (ta_len > 0 || noread_cnt > 4)) |
7 | 4781 { |
1823 | 4782 if (ta_len == 0) |
4783 { | |
4784 /* Get extra characters when we don't have any. | |
4785 * Reset the counter and timer. */ | |
4786 noread_cnt = 0; | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4787 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4788 ELAPSED_INIT(start_tv); |
1823 | 4789 # endif |
4790 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4791 } | |
4792 if (ta_len > 0 || len > 0) | |
4793 { | |
7 | 4794 /* |
4795 * For pipes: | |
4796 * Check for CTRL-C: send interrupt signal to child. | |
4797 * Check for CTRL-D: EOF, close pipe to child. | |
4798 */ | |
4799 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) | |
4800 { | |
4801 /* | |
4802 * Send SIGINT to the child's group or all | |
4803 * processes in our group. | |
4804 */ | |
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
|
4805 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
|
4806 |
7 | 4807 if (pty_master_fd < 0 && toshell_fd >= 0 |
4808 && ta_buf[ta_len] == Ctrl_D) | |
4809 { | |
4810 close(toshell_fd); | |
4811 toshell_fd = -1; | |
4812 } | |
4813 } | |
4814 | |
4815 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4816 for (i = ta_len; i < ta_len + len; ++i) | |
4817 { | |
4818 if (ta_buf[i] == CSI && len - i > 2) | |
4819 { | |
4820 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4821 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4822 { | |
4823 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4824 (size_t)(len - i - 2)); | |
4825 if (c == K_DEL || c == K_KDEL) | |
4826 ta_buf[i] = DEL; | |
4827 else | |
4828 ta_buf[i] = Ctrl_H; | |
4829 len -= 2; | |
4830 } | |
4831 } | |
4832 else if (ta_buf[i] == '\r') | |
4833 ta_buf[i] = '\n'; | |
167 | 4834 # ifdef FEAT_MBYTE |
7 | 4835 if (has_mbyte) |
1903 | 4836 i += (*mb_ptr2len_len)(ta_buf + i, |
4837 ta_len + len - i) - 1; | |
167 | 4838 # endif |
7 | 4839 } |
4840 | |
4841 /* | |
4842 * For pipes: echo the typed characters. | |
4843 * For a pty this does not seem to work. | |
4844 */ | |
4845 if (pty_master_fd < 0) | |
4846 { | |
4847 for (i = ta_len; i < ta_len + len; ++i) | |
4848 { | |
4849 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4850 msg_putchar(ta_buf[i]); | |
167 | 4851 # ifdef FEAT_MBYTE |
7 | 4852 else if (has_mbyte) |
4853 { | |
474 | 4854 int l = (*mb_ptr2len)(ta_buf + i); |
7 | 4855 |
4856 msg_outtrans_len(ta_buf + i, l); | |
4857 i += l - 1; | |
4858 } | |
167 | 4859 # endif |
7 | 4860 else |
4861 msg_outtrans_len(ta_buf + i, 1); | |
4862 } | |
4863 windgoto(msg_row, msg_col); | |
4864 out_flush(); | |
4865 } | |
4866 | |
4867 ta_len += len; | |
4868 | |
4869 /* | |
4870 * Write the characters to the child, unless EOF has | |
4871 * been typed for pipes. Write one character at a | |
1698 | 4872 * time, to avoid losing too much typeahead. |
167 | 4873 * When writing buffer lines, drop the typed |
4874 * characters (only check for CTRL-C). | |
7 | 4875 */ |
167 | 4876 if (options & SHELL_WRITE) |
4877 ta_len = 0; | |
4878 else if (toshell_fd >= 0) | |
7 | 4879 { |
4880 len = write(toshell_fd, (char *)ta_buf, (size_t)1); | |
4881 if (len > 0) | |
4882 { | |
4883 ta_len -= len; | |
4884 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4885 } | |
4886 } | |
1823 | 4887 } |
7 | 4888 } |
4889 | |
167 | 4890 if (got_int) |
4891 { | |
4892 /* CTRL-C sends a signal to the child, we ignore it | |
4893 * ourselves */ | |
4894 # ifdef HAVE_SETSID | |
4895 kill(-pid, SIGINT); | |
4896 # else | |
4897 kill(0, SIGINT); | |
4898 # endif | |
4899 if (wpid > 0) | |
4900 kill(wpid, SIGINT); | |
4901 got_int = FALSE; | |
4902 } | |
4903 | |
7 | 4904 /* |
4905 * Check if the child has any characters to be printed. | |
4906 * Read them and write them to our window. Repeat this as | |
4907 * long as there is something to do, avoid the 10ms wait | |
4908 * for mch_inchar(), or sending typeahead characters to | |
4909 * the external process. | |
4910 * TODO: This should handle escape sequences, compatible | |
4911 * to some terminal (vt52?). | |
4912 */ | |
167 | 4913 ++noread_cnt; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
4914 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL)) |
7 | 4915 { |
2664 | 4916 len = read_eintr(fromshell_fd, buffer |
167 | 4917 # ifdef FEAT_MBYTE |
7 | 4918 + buffer_off, (size_t)(BUFLEN - buffer_off) |
167 | 4919 # else |
7 | 4920 , (size_t)BUFLEN |
167 | 4921 # endif |
7 | 4922 ); |
4923 if (len <= 0) /* end of file or error */ | |
4924 goto finished; | |
167 | 4925 |
4926 noread_cnt = 0; | |
4927 if (options & SHELL_READ) | |
4928 { | |
4929 /* Do NUL -> NL translation, append NL separated | |
4930 * lines to the current buffer. */ | |
4931 for (i = 0; i < len; ++i) | |
4932 { | |
4933 if (buffer[i] == NL) | |
4934 append_ga_line(&ga); | |
4935 else if (buffer[i] == NUL) | |
4936 ga_append(&ga, NL); | |
4937 else | |
4938 ga_append(&ga, buffer[i]); | |
4939 } | |
4940 } | |
4941 # ifdef FEAT_MBYTE | |
4942 else if (has_mbyte) | |
7 | 4943 { |
4944 int l; | |
4945 | |
167 | 4946 len += buffer_off; |
4947 buffer[len] = NUL; | |
4948 | |
7 | 4949 /* Check if the last character in buffer[] is |
4950 * incomplete, keep these bytes for the next | |
4951 * round. */ | |
4952 for (p = buffer; p < buffer + len; p += l) | |
4953 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9873
diff
changeset
|
4954 l = MB_CPTR2LEN(p); |
7 | 4955 if (l == 0) |
4956 l = 1; /* NUL byte? */ | |
4957 else if (MB_BYTE2LEN(*p) != l) | |
4958 break; | |
4959 } | |
4960 if (p == buffer) /* no complete character */ | |
4961 { | |
4962 /* avoid getting stuck at an illegal byte */ | |
4963 if (len >= 12) | |
4964 ++p; | |
4965 else | |
4966 { | |
4967 buffer_off = len; | |
4968 continue; | |
4969 } | |
4970 } | |
4971 c = *p; | |
4972 *p = NUL; | |
4973 msg_puts(buffer); | |
4974 if (p < buffer + len) | |
4975 { | |
4976 *p = c; | |
4977 buffer_off = (buffer + len) - p; | |
4978 mch_memmove(buffer, p, buffer_off); | |
4979 continue; | |
4980 } | |
4981 buffer_off = 0; | |
4982 } | |
167 | 4983 # endif /* FEAT_MBYTE */ |
7 | 4984 else |
4985 { | |
4986 buffer[len] = NUL; | |
4987 msg_puts(buffer); | |
4988 } | |
4989 | |
4990 windgoto(msg_row, msg_col); | |
4991 cursor_on(); | |
4992 out_flush(); | |
4993 if (got_int) | |
4994 break; | |
1823 | 4995 |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4996 # ifdef ELAPSED_FUNC |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4997 if (wait_pid == 0) |
1823 | 4998 { |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4999 long msec = ELAPSED_FUNC(start_tv); |
1823 | 5000 |
5001 /* Avoid that we keep looping here without | |
5002 * checking for a CTRL-C for a long time. Don't | |
5003 * break out too often to avoid losing typeahead. */ | |
5004 if (msec > 2000) | |
5005 { | |
5006 noread_cnt = 5; | |
5007 break; | |
5008 } | |
5009 } | |
5010 # endif | |
7 | 5011 } |
5012 | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5013 /* 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
|
5014 * 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
|
5015 * buffered. */ |
602 | 5016 if (wait_pid == pid) |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5017 { |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5018 if (noread_cnt < 5) |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5019 continue; |
602 | 5020 break; |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
5021 } |
602 | 5022 |
7 | 5023 /* |
5024 * Check if the child still exists, before checking for | |
1698 | 5025 * typed characters (otherwise we would lose typeahead). |
7 | 5026 */ |
167 | 5027 # ifdef __NeXT__ |
3048 | 5028 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); |
167 | 5029 # else |
7 | 5030 wait_pid = waitpid(pid, &status, WNOHANG); |
167 | 5031 # endif |
7 | 5032 if ((wait_pid == (pid_t)-1 && errno == ECHILD) |
5033 || (wait_pid == pid && WIFEXITED(status))) | |
5034 { | |
602 | 5035 /* Don't break the loop yet, try reading more |
5036 * characters from "fromshell_fd" first. When using | |
5037 * pipes there might still be something to read and | |
5038 * then we'll break the loop at the "break" above. */ | |
7 | 5039 wait_pid = pid; |
5040 } | |
602 | 5041 else |
5042 wait_pid = 0; | |
4230 | 5043 |
4248 | 5044 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5045 /* Handle any X events, e.g. serving the clipboard. */ |
5046 clip_update(); | |
5047 # endif | |
7 | 5048 } |
5049 finished: | |
5050 p_more = p_more_save; | |
167 | 5051 if (options & SHELL_READ) |
5052 { | |
5053 if (ga.ga_len > 0) | |
5054 { | |
5055 append_ga_line(&ga); | |
5056 /* remember that the NL was missing */ | |
2707 | 5057 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
167 | 5058 } |
5059 else | |
2707 | 5060 curbuf->b_no_eol_lnum = 0; |
167 | 5061 ga_clear(&ga); |
5062 } | |
5063 | |
7 | 5064 /* |
5065 * Give all typeahead that wasn't used back to ui_inchar(). | |
5066 */ | |
5067 if (ta_len) | |
5068 ui_inchar_undo(ta_buf, ta_len); | |
5069 State = old_State; | |
5070 if (toshell_fd >= 0) | |
5071 close(toshell_fd); | |
5072 close(fromshell_fd); | |
5073 } | |
4248 | 5074 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 5075 else |
5076 { | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5077 long delay_msec = 1; |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5078 |
4230 | 5079 /* |
5080 * Similar to the loop above, but only handle X events, no | |
5081 * I/O. | |
5082 */ | |
5083 for (;;) | |
5084 { | |
5085 if (got_int) | |
5086 { | |
5087 /* CTRL-C sends a signal to the child, we ignore it | |
5088 * ourselves */ | |
5089 # ifdef HAVE_SETSID | |
5090 kill(-pid, SIGINT); | |
5091 # else | |
5092 kill(0, SIGINT); | |
5093 # endif | |
5094 got_int = FALSE; | |
5095 } | |
5096 # ifdef __NeXT__ | |
5097 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); | |
5098 # else | |
5099 wait_pid = waitpid(pid, &status, WNOHANG); | |
5100 # endif | |
5101 if ((wait_pid == (pid_t)-1 && errno == ECHILD) | |
5102 || (wait_pid == pid && WIFEXITED(status))) | |
5103 { | |
5104 wait_pid = pid; | |
5105 break; | |
5106 } | |
5107 | |
5108 /* Handle any X events, e.g. serving the clipboard. */ | |
5109 clip_update(); | |
5110 | |
10019
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5111 /* 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
|
5112 * less time. */ |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5113 mch_delay(delay_msec, TRUE); |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5114 if (++delay_msec > 10) |
782a8070c3a6
commit https://github.com/vim/vim/commit/0abe0522d0e52b50c6eab52323be558eb56fe95e
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
5115 delay_msec = 10; |
4230 | 5116 } |
5117 } | |
5118 # endif | |
7 | 5119 |
5120 /* | |
5121 * Wait until our child has exited. | |
5122 * Ignore wait() returning pids of other children and returning | |
5123 * because of some signal like SIGWINCH. | |
5124 * Don't wait if wait_pid was already set above, indicating the | |
5125 * child already exited. | |
5126 */ | |
3048 | 5127 if (wait_pid != pid) |
5128 wait_pid = wait4pid(pid, &status); | |
7 | 5129 |
2600 | 5130 # ifdef FEAT_GUI |
5131 /* Close slave side of pty. Only do this after the child has | |
5132 * exited, otherwise the child may hang when it tries to write on | |
5133 * the pty. */ | |
5134 if (pty_master_fd >= 0) | |
5135 close(pty_slave_fd); | |
5136 # endif | |
5137 | |
167 | 5138 /* Make sure the child that writes to the external program is |
5139 * dead. */ | |
5140 if (wpid > 0) | |
3048 | 5141 { |
167 | 5142 kill(wpid, SIGKILL); |
3048 | 5143 wait4pid(wpid, NULL); |
5144 } | |
167 | 5145 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5146 # ifdef FEAT_JOB_CHANNEL |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5147 --dont_check_job_ended; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5148 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5149 |
7 | 5150 /* |
5151 * Set to raw mode right now, otherwise a CTRL-C after | |
5152 * catch_signals() will kill Vim. | |
5153 */ | |
5154 if (tmode == TMODE_RAW) | |
5155 settmode(TMODE_RAW); | |
5156 did_settmode = TRUE; | |
5157 set_signals(); | |
5158 | |
5159 if (WIFEXITED(status)) | |
5160 { | |
129 | 5161 /* LINTED avoid "bitwise operation on signed value" */ |
7 | 5162 retval = WEXITSTATUS(status); |
4074 | 5163 if (retval != 0 && !emsg_silent) |
7 | 5164 { |
5165 if (retval == EXEC_FAILED) | |
5166 { | |
5167 MSG_PUTS(_("\nCannot execute shell ")); | |
5168 msg_outtrans(p_sh); | |
5169 msg_putchar('\n'); | |
5170 } | |
5171 else if (!(options & SHELL_SILENT)) | |
5172 { | |
5173 MSG_PUTS(_("\nshell returned ")); | |
5174 msg_outnum((long)retval); | |
5175 msg_putchar('\n'); | |
5176 } | |
5177 } | |
5178 } | |
5179 else | |
5180 MSG_PUTS(_("\nCommand terminated\n")); | |
5181 } | |
5182 } | |
5183 vim_free(argv); | |
2994 | 5184 vim_free(p_shcf_copy); |
7 | 5185 |
5186 error: | |
5187 if (!did_settmode) | |
5188 if (tmode == TMODE_RAW) | |
5189 settmode(TMODE_RAW); /* set to raw mode */ | |
5190 # ifdef FEAT_TITLE | |
5191 resettitle(); | |
5192 # endif | |
5193 vim_free(newcmd); | |
5194 | |
5195 return retval; | |
5196 | |
5197 #endif /* USE_SYSTEM */ | |
5198 } | |
5199 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5200 #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
|
5201 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5202 mch_job_start(char **argv, job_T *job, jobopt_T *options) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5203 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5204 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
|
5205 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
|
5206 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
|
5207 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
|
5208 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
|
5209 int pty_slave_fd = -1; |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
5210 channel_T *channel = NULL; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5211 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
|
5212 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
|
5213 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
|
5214 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
|
5215 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
|
5216 int use_file_for_err = options->jo_io[PART_ERR] == JIO_FILE; |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5217 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
|
5218 SIGSET_DECL(curset) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5219 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5220 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
|
5221 use_null_for_err = TRUE; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5222 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5223 /* default is to fail */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5224 job->jv_status = JOB_FAILED; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5225 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5226 if (options->jo_pty) |
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
|
5227 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_name); |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5228 |
8068
9c6740f2204f
commit https://github.com/vim/vim/commit/12dcf024e90ab511f04a08b20fe7eedbe92096d2
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5229 /* 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
|
5230 /* 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
|
5231 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5232 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5233 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
|
5234 |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5235 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
|
5236 if (fd_in[0] < 0) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5237 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5238 EMSG2(_(e_notopen), fname); |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5239 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5240 } |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5241 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5242 else if (!use_null_for_in && pty_master_fd < 0 && pipe(fd_in) < 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5243 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5244 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5245 if (use_file_for_out) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5246 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5247 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
|
5248 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5249 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
|
5250 if (fd_out[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5251 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5252 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5253 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5254 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5255 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5256 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
|
5257 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5258 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5259 if (use_file_for_err) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5260 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5261 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
|
5262 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5263 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
|
5264 if (fd_err[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5265 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5266 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5267 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5268 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5269 } |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5270 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
|
5271 && 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
|
5272 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5273 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5274 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
|
5275 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5276 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5277 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5278 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5279 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5280 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5281 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5282 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5283 channel = add_channel(); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5284 if (channel == NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5285 goto failed; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5286 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5287 |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5288 BLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5289 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
|
5290 if (pid == -1) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5291 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5292 /* failed to fork */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5293 UNBLOCK_SIGNALS(&curset); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5294 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5295 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5296 if (pid == 0) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5297 { |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5298 int null_fd = -1; |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5299 int stderr_works = TRUE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5300 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5301 /* child */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5302 reset_signals(); /* handle signals normally */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5303 UNBLOCK_SIGNALS(&curset); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5304 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5305 # ifdef HAVE_SETSID |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5306 /* 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
|
5307 * 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
|
5308 * 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
|
5309 (void)setsid(); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5310 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5311 |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5312 # ifdef FEAT_TERMINAL |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5313 if (options->jo_term_rows > 0) |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5314 set_child_environment( |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5315 (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
|
5316 (long)options->jo_term_cols, |
11826
bf8cfdcdbdd8
patch 8.0.0793: using wrong terminal name for terminal window
Christian Brabandt <cb@256bit.org>
parents:
11741
diff
changeset
|
5317 STRNCMP(T_NAME, "xterm", 5) == 0 |
bf8cfdcdbdd8
patch 8.0.0793: using wrong terminal name for terminal window
Christian Brabandt <cb@256bit.org>
parents:
11741
diff
changeset
|
5318 ? (char *)T_NAME : "xterm"); |
11713
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5319 else |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5320 # endif |
2ec27561dd76
patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents:
11557
diff
changeset
|
5321 set_default_child_environment(); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5322 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5323 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
|
5324 null_fd = open("/dev/null", O_RDWR | O_EXTRA, 0); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5325 |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5326 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
|
5327 { |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5328 /* push stream discipline modules */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5329 SetupSlavePTY(pty_slave_fd); |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5330 # ifdef TIOCSCTTY |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5331 /* 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
|
5332 * unless run by root) */ |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5333 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
|
5334 # endif |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5335 } |
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5336 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5337 /* 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
|
5338 close(0); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5339 if (use_null_for_in && null_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5340 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
|
5341 else if (fd_in[0] < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5342 ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5343 else |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5344 ignored = dup(fd_in[0]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5345 |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5346 /* 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
|
5347 close(2); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5348 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
|
5349 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5350 ignored = dup(null_fd); |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5351 stderr_works = FALSE; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5352 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5353 else if (use_out_for_err) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5354 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
|
5355 else if (fd_err[1] < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5356 ignored = dup(pty_slave_fd); |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5357 else |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5358 ignored = dup(fd_err[1]); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5359 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5360 /* 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
|
5361 close(1); |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5362 if (use_null_for_out && null_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5363 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
|
5364 else if (fd_out[1] < 0) |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5365 ignored = dup(pty_slave_fd); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5366 else |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5367 ignored = dup(fd_out[1]); |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5368 |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5369 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
|
5370 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
|
5371 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
|
5372 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
|
5373 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
|
5374 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
|
5375 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
|
5376 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
|
5377 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
|
5378 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
|
5379 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
|
5380 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
|
5381 if (pty_master_fd >= 0) |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5382 { |
11925
fe6675d67a10
patch 8.0.0842: using slave pty after closing it
Christian Brabandt <cb@256bit.org>
parents:
11919
diff
changeset
|
5383 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
|
5384 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
|
5385 } |
9074
3aab62b76363
commit https://github.com/vim/vim/commit/ea83bf06b92baeb6d68a10d8e8ffad289d31dae2
Christian Brabandt <cb@256bit.org>
parents:
9009
diff
changeset
|
5386 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5387 if (null_fd >= 0) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5388 close(null_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5389 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5390 /* See above for type of argv. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5391 execvp(argv[0], argv); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5392 |
8958
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5393 if (stderr_works) |
12392eb2923a
commit https://github.com/vim/vim/commit/4694a17d1ec08382f996990a7fac1ac60197ec81
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5394 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
|
5395 # ifdef EXITFREE |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5396 /* 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
|
5397 * 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
|
5398 # endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5399 _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
|
5400 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5401 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5402 /* parent */ |
10297
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5403 UNBLOCK_SIGNALS(&curset); |
c90f4cc9c3fe
commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents:
10279
diff
changeset
|
5404 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5405 job->jv_pid = pid; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5406 job->jv_status = JOB_STARTED; |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5407 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
|
5408 |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5409 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
|
5410 close(pty_slave_fd); /* duped above */ |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5411 /* close child stdin, stdout and stderr */ |
8671
8f6bc5626829
commit https://github.com/vim/vim/commit/be6aa46c4d8948e164f7d181dc19ed2fc4818395
Christian Brabandt <cb@256bit.org>
parents:
8611
diff
changeset
|
5412 if (!use_file_for_in && fd_in[0] >= 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5413 close(fd_in[0]); |
8671
8f6bc5626829
commit https://github.com/vim/vim/commit/be6aa46c4d8948e164f7d181dc19ed2fc4818395
Christian Brabandt <cb@256bit.org>
parents:
8611
diff
changeset
|
5414 if (!use_file_for_out && fd_out[1] >= 0) |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5415 close(fd_out[1]); |
8671
8f6bc5626829
commit https://github.com/vim/vim/commit/be6aa46c4d8948e164f7d181dc19ed2fc4818395
Christian Brabandt <cb@256bit.org>
parents:
8611
diff
changeset
|
5416 if (!use_out_for_err && !use_file_for_err && fd_err[1] >= 0) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5417 close(fd_err[1]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5418 if (channel != NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5419 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5420 channel_set_pipes(channel, |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5421 use_file_for_in || use_null_for_in |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5422 ? INVALID_FD : fd_in[1] < 0 ? pty_master_fd : fd_in[1], |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5423 use_file_for_out || use_null_for_out |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5424 ? INVALID_FD : fd_out[0] < 0 ? pty_master_fd : fd_out[0], |
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11717
diff
changeset
|
5425 use_out_for_err || use_file_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
|
5426 ? INVALID_FD : fd_err[0] < 0 ? pty_master_fd : fd_err[0]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5427 channel_set_job(channel, job, options); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5428 } |
11894
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5429 else |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5430 { |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5431 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
|
5432 close(fd_in[1]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5433 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
|
5434 close(fd_out[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5435 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
|
5436 close(fd_err[0]); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5437 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
|
5438 close(pty_master_fd); |
75a85e99f53e
patch 8.0.0827: Coverity: could leak pty file descriptor
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
5439 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5440 |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5441 /* success! */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5442 return; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5443 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5444 failed: |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5445 channel_unref(channel); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5446 if (fd_in[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5447 close(fd_in[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5448 if (fd_in[1] >= 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5449 close(fd_in[1]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5450 if (fd_out[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5451 close(fd_out[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5452 if (fd_out[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5453 close(fd_out[1]); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5454 if (fd_err[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5455 close(fd_err[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5456 if (fd_err[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5457 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
|
5458 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
|
5459 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
|
5460 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
|
5461 close(pty_slave_fd); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5462 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5463 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5464 char * |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5465 mch_job_status(job_T *job) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5466 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5467 # ifdef HAVE_UNION_WAIT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5468 union wait status; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5469 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5470 int status = -1; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5471 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5472 pid_t wait_pid = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5473 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5474 # ifdef __NeXT__ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5475 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
|
5476 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5477 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
|
5478 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5479 if (wait_pid == -1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5480 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5481 /* process must have exited */ |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5482 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5483 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5484 if (wait_pid == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5485 return "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5486 if (WIFEXITED(status)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5487 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5488 /* 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
|
5489 job->jv_exitval = WEXITSTATUS(status); |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5490 goto return_dead; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5491 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5492 if (WIFSIGNALED(status)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5493 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5494 job->jv_exitval = -1; |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5495 goto return_dead; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5496 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5497 return "run"; |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5498 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5499 return_dead: |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5500 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
|
5501 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5502 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
|
5503 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5504 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5505 return "dead"; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5506 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5507 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5508 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5509 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
|
5510 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5511 # ifdef HAVE_UNION_WAIT |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5512 union wait status; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5513 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5514 int status = -1; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5515 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5516 pid_t wait_pid = 0; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5517 job_T *job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5518 |
10353
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5519 # ifndef USE_SYSTEM |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5520 /* 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
|
5521 * 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
|
5522 * would then be wrong. */ |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5523 if (dont_check_job_ended > 0) |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5524 return NULL; |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5525 # endif |
72d92c31b9f7
commit https://github.com/vim/vim/commit/c4d4ac22f78fb1394c79eccc8a1e6812c0c7d8a7
Christian Brabandt <cb@256bit.org>
parents:
10328
diff
changeset
|
5526 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5527 # ifdef __NeXT__ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5528 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
|
5529 # else |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5530 wait_pid = waitpid(-1, &status, WNOHANG); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5531 # endif |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5532 if (wait_pid <= 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5533 /* no process ended */ |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5534 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5535 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
|
5536 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5537 if (job->jv_pid == wait_pid) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5538 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5539 if (WIFEXITED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5540 /* 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
|
5541 job->jv_exitval = WEXITSTATUS(status); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5542 else if (WIFSIGNALED(status)) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5543 job->jv_exitval = -1; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10375
diff
changeset
|
5544 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
|
5545 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5546 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
|
5547 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5548 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5549 return job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5550 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5551 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10266
diff
changeset
|
5552 return NULL; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5553 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5554 |
10320
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5555 /* |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5556 * Send a (deadly) signal to "job". |
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10309
diff
changeset
|
5557 * 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
|
5558 */ |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5559 int |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5560 mch_stop_job(job_T *job, char_u *how) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5561 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5562 int sig = -1; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5563 pid_t job_pid; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5564 |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5565 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
|
5566 sig = SIGTERM; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5567 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
|
5568 sig = SIGHUP; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5569 else if (STRCMP(how, "quit") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5570 sig = SIGQUIT; |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5571 else if (STRCMP(how, "int") == 0) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5572 sig = SIGINT; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5573 else if (STRCMP(how, "kill") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5574 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
|
5575 #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
|
5576 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
|
5577 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
|
5578 #endif |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5579 else if (isdigit(*how)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5580 sig = atoi((char *)how); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5581 else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5582 return FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5583 |
7999
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
5584 /* TODO: have an option to only kill the process, not the group? */ |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5585 job_pid = job->jv_pid; |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
5586 #ifdef HAVE_GETPGID |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5587 if (job_pid == getpgid(job_pid)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5588 job_pid = -job_pid; |
11115
3b36da20ad73
patch 8.0.0445: getpgid is not supported on all systems
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
5589 #endif |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5590 |
11727
cb1dc90d22cc
patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
5591 /* Never kill ourselves! */ |
cb1dc90d22cc
patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
5592 if (job_pid != 0) |
cb1dc90d22cc
patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
5593 kill(job_pid, sig); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5594 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5595 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5596 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5597 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5598 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5599 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5600 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5601 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5602 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5603 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5604 /* 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
|
5605 # ifdef __NeXT__ |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5606 (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
|
5607 # else |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5608 (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
|
5609 # endif |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5610 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5611 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5612 |
7 | 5613 /* |
5614 * Check for CTRL-C typed by reading all available characters. | |
5615 * In cooked mode we should get SIGINT, no need to check. | |
5616 */ | |
5617 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5618 mch_breakcheck(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5619 { |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5620 if ((curr_tmode == TMODE_RAW || force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5621 && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL)) |
7 | 5622 fill_input_buf(FALSE); |
5623 } | |
5624 | |
5625 /* | |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5626 * 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
|
5627 * from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5628 * "msec" == -1 will block forever. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5629 * 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
|
5630 * 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
|
5631 * already available. |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5632 * "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
|
5633 * 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
|
5634 * Returns TRUE when a character is available. |
7 | 5635 * When a GUI is being used, this will never get called -- webb |
5636 */ | |
5637 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5638 WaitForChar(long msec, int *interrupted, int ignore_input) |
7 | 5639 { |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5640 #ifdef FEAT_TIMERS |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5641 long due_time; |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5642 long remaining = msec; |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5643 int tb_change_cnt = typebuf.tb_change_cnt; |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5644 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5645 /* When waiting very briefly don't trigger timers. */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5646 if (msec >= 0 && msec < 10L) |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5647 return WaitForCharOrMouse(msec, NULL, ignore_input); |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5648 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5649 while (msec < 0 || remaining > 0) |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5650 { |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5651 /* Trigger timers and then get the time in msec until the next one is |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5652 * due. Wait up to that time. */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5653 due_time = check_due_timer(); |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5654 if (typebuf.tb_change_cnt != tb_change_cnt) |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5655 { |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5656 /* timer may have used feedkeys() */ |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5657 return FALSE; |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5658 } |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5659 if (due_time <= 0 || (msec > 0 && due_time > remaining)) |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5660 due_time = remaining; |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5661 if (WaitForCharOrMouse(due_time, interrupted, ignore_input)) |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5662 return TRUE; |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5663 if (interrupted != NULL && *interrupted) |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5664 /* Nothing available, but need to return so that side effects get |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5665 * handled, such as handling a message on a channel. */ |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5666 return FALSE; |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5667 if (msec > 0) |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5668 remaining -= due_time; |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5669 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5670 return FALSE; |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5671 #else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5672 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
|
5673 #endif |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5674 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5675 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5676 /* |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5677 * 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
|
5678 * or from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5679 * "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
|
5680 * for "ignore_input" see WaitForCharOr(). |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5681 * "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
|
5682 * 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
|
5683 * 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
|
5684 */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5685 static int |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5686 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
|
5687 { |
7 | 5688 #ifdef FEAT_MOUSE_GPM |
5689 int gpm_process_wanted; | |
5690 #endif | |
5691 #ifdef FEAT_XCLIPBOARD | |
5692 int rest; | |
5693 #endif | |
5694 int avail; | |
5695 | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5696 if (!ignore_input && input_available()) /* something in inbuf[] */ |
7 | 5697 return 1; |
5698 | |
5699 #if defined(FEAT_MOUSE_DEC) | |
5700 /* May need to query the mouse position. */ | |
5701 if (WantQueryMouse) | |
5702 { | |
227 | 5703 WantQueryMouse = FALSE; |
7 | 5704 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5); |
5705 } | |
5706 #endif | |
5707 | |
5708 /* | |
5709 * For FEAT_MOUSE_GPM and FEAT_XCLIPBOARD we loop here to process mouse | |
5710 * events. This is a bit complicated, because they might both be defined. | |
5711 */ | |
5712 #if defined(FEAT_MOUSE_GPM) || defined(FEAT_XCLIPBOARD) | |
5713 # ifdef FEAT_XCLIPBOARD | |
5714 rest = 0; | |
5715 if (do_xterm_trace()) | |
5716 rest = msec; | |
5717 # endif | |
5718 do | |
5719 { | |
5720 # ifdef FEAT_XCLIPBOARD | |
5721 if (rest != 0) | |
5722 { | |
5723 msec = XT_TRACE_DELAY; | |
5724 if (rest >= 0 && rest < XT_TRACE_DELAY) | |
5725 msec = rest; | |
5726 if (rest >= 0) | |
5727 rest -= msec; | |
5728 } | |
5729 # endif | |
5730 # ifdef FEAT_MOUSE_GPM | |
5731 gpm_process_wanted = 0; | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5732 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
|
5733 &gpm_process_wanted, interrupted); |
7 | 5734 # else |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5735 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 5736 # endif |
5737 if (!avail) | |
5738 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11933
diff
changeset
|
5739 if (!ignore_input && input_available()) |
7 | 5740 return 1; |
5741 # ifdef FEAT_XCLIPBOARD | |
5742 if (rest == 0 || !do_xterm_trace()) | |
5743 # endif | |
5744 break; | |
5745 } | |
5746 } | |
5747 while (FALSE | |
5748 # ifdef FEAT_MOUSE_GPM | |
5749 || (gpm_process_wanted && mch_gpm_process() == 0) | |
5750 # endif | |
5751 # ifdef FEAT_XCLIPBOARD | |
5752 || (!avail && rest != 0) | |
5753 # endif | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5754 ) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5755 ; |
7 | 5756 |
5757 #else | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5758 avail = RealWaitForChar(read_cmd_fd, msec, NULL, interrupted); |
7 | 5759 #endif |
5760 return avail; | |
5761 } | |
5762 | |
5541 | 5763 #ifndef VMS |
7 | 5764 /* |
5765 * Wait "msec" msec until a character is available from file descriptor "fd". | |
3046 | 5766 * "msec" == 0 will check for characters once. |
5767 * "msec" == -1 will block until a character is available. | |
7 | 5768 * When a GUI is being used, this will not be used for input -- webb |
5769 * 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
|
5770 * 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
|
5771 * "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
|
5772 * but something else needs to be done. |
7 | 5773 */ |
5774 #if defined(__BEOS__) | |
5775 int | |
5776 #else | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5777 static int |
7 | 5778 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5779 RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted) |
7 | 5780 { |
5781 int ret; | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5782 int result; |
14 | 5783 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) |
7 | 5784 static int busy = FALSE; |
5785 | |
5786 /* May retry getting characters after an event was handled. */ | |
5787 # define MAY_LOOP | |
5788 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5789 # ifdef ELAPSED_FUNC |
7 | 5790 /* Remember at what time we started, so that we know how much longer we |
5791 * should wait after being interrupted. */ | |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
5792 long start_msec = msec; |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5793 ELAPSED_TYPE start_tv; |
7 | 5794 |
9209
f8f41f4e0acd
commit https://github.com/vim/vim/commit/76b6dfe54ba9b85cd9d8e6539205c1679a187961
Christian Brabandt <cb@256bit.org>
parents:
9207
diff
changeset
|
5795 if (msec > 0) |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
5796 ELAPSED_INIT(start_tv); |
7 | 5797 # endif |
5798 | |
5799 /* Handle being called recursively. This may happen for the session | |
5800 * manager stuff, it may save the file, which does a breakcheck. */ | |
5801 if (busy) | |
5802 return 0; | |
5803 #endif | |
5804 | |
5805 #ifdef MAY_LOOP | |
407 | 5806 for (;;) |
7 | 5807 #endif |
5808 { | |
5809 #ifdef MAY_LOOP | |
5810 int finished = TRUE; /* default is to 'loop' just once */ | |
14 | 5811 # ifdef FEAT_MZSCHEME |
5812 int mzquantum_used = FALSE; | |
5813 # endif | |
7 | 5814 #endif |
5815 #ifndef HAVE_SELECT | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5816 /* 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
|
5817 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; |
7 | 5818 int nfd; |
5819 # ifdef FEAT_XCLIPBOARD | |
5820 int xterm_idx = -1; | |
5821 # endif | |
5822 # ifdef FEAT_MOUSE_GPM | |
5823 int gpm_idx = -1; | |
5824 # endif | |
5825 # ifdef USE_XSMP | |
5826 int xsmp_idx = -1; | |
5827 # endif | |
14 | 5828 int towait = (int)msec; |
5829 | |
5830 # ifdef FEAT_MZSCHEME | |
5831 mzvim_check_threads(); | |
5832 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
5833 { | |
5834 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ | |
5835 mzquantum_used = TRUE; | |
5836 } | |
5837 # endif | |
7 | 5838 fds[0].fd = fd; |
5839 fds[0].events = POLLIN; | |
5840 nfd = 1; | |
5841 | |
5842 # ifdef FEAT_XCLIPBOARD | |
6383 | 5843 may_restore_clipboard(); |
7 | 5844 if (xterm_Shell != (Widget)0) |
5845 { | |
5846 xterm_idx = nfd; | |
5847 fds[nfd].fd = ConnectionNumber(xterm_dpy); | |
5848 fds[nfd].events = POLLIN; | |
5849 nfd++; | |
5850 } | |
5851 # endif | |
5852 # ifdef FEAT_MOUSE_GPM | |
5853 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
5854 { | |
5855 gpm_idx = nfd; | |
5856 fds[nfd].fd = gpm_fd; | |
5857 fds[nfd].events = POLLIN; | |
5858 nfd++; | |
5859 } | |
5860 # endif | |
5861 # ifdef USE_XSMP | |
5862 if (xsmp_icefd != -1) | |
5863 { | |
5864 xsmp_idx = nfd; | |
5865 fds[nfd].fd = xsmp_icefd; | |
5866 fds[nfd].events = POLLIN; | |
5867 nfd++; | |
5868 } | |
5869 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5870 #ifdef FEAT_JOB_CHANNEL |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5871 nfd = channel_poll_setup(nfd, &fds); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
5872 #endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5873 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
5874 *interrupted = FALSE; |
7 | 5875 |
14 | 5876 ret = poll(fds, nfd, towait); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5877 |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5878 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
|
5879 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
|
5880 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5881 |
14 | 5882 # ifdef FEAT_MZSCHEME |
5883 if (ret == 0 && mzquantum_used) | |
1450 | 5884 /* MzThreads scheduling is required and timeout occurred */ |
14 | 5885 finished = FALSE; |
5886 # endif | |
7 | 5887 |
5888 # ifdef FEAT_XCLIPBOARD | |
5889 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) | |
5890 { | |
5891 xterm_update(); /* Maybe we should hand out clipboard */ | |
5892 if (--ret == 0 && !input_available()) | |
5893 /* Try again */ | |
5894 finished = FALSE; | |
5895 } | |
5896 # endif | |
5897 # ifdef FEAT_MOUSE_GPM | |
5898 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN)) | |
5899 { | |
5900 *check_for_gpm = 1; | |
5901 } | |
5902 # endif | |
5903 # ifdef USE_XSMP | |
5904 if (xsmp_idx >= 0 && (fds[xsmp_idx].revents & (POLLIN | POLLHUP))) | |
5905 { | |
5906 if (fds[xsmp_idx].revents & POLLIN) | |
5907 { | |
5908 busy = TRUE; | |
5909 xsmp_handle_requests(); | |
5910 busy = FALSE; | |
5911 } | |
5912 else if (fds[xsmp_idx].revents & POLLHUP) | |
5913 { | |
5914 if (p_verbose > 0) | |
292 | 5915 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 5916 xsmp_close(); |
5917 } | |
5918 if (--ret == 0) | |
14 | 5919 finished = FALSE; /* Try again */ |
7 | 5920 } |
5921 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5922 #ifdef FEAT_JOB_CHANNEL |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5923 if (ret > 0) |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5924 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
|
5925 #endif |
7 | 5926 |
5927 #else /* HAVE_SELECT */ | |
5928 | |
5929 struct timeval tv; | |
14 | 5930 struct timeval *tvp; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5931 fd_set rfds, wfds, efds; |
7 | 5932 int maxfd; |
14 | 5933 long towait = msec; |
5934 | |
5935 # ifdef FEAT_MZSCHEME | |
5936 mzvim_check_threads(); | |
5937 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
5938 { | |
5939 towait = p_mzq; /* don't wait longer than 'mzquantum' */ | |
5940 mzquantum_used = TRUE; | |
5941 } | |
5942 # endif | |
7 | 5943 |
14 | 5944 if (towait >= 0) |
7 | 5945 { |
14 | 5946 tv.tv_sec = towait / 1000; |
5947 tv.tv_usec = (towait % 1000) * (1000000/1000); | |
5948 tvp = &tv; | |
7 | 5949 } |
14 | 5950 else |
5951 tvp = NULL; | |
7 | 5952 |
5953 /* | |
5954 * Select on ready for reading and exceptional condition (end of file). | |
5955 */ | |
3046 | 5956 select_eintr: |
5957 FD_ZERO(&rfds); | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5958 FD_ZERO(&wfds); |
7 | 5959 FD_ZERO(&efds); |
5960 FD_SET(fd, &rfds); | |
5961 # if !defined(__QNX__) && !defined(__CYGWIN32__) | |
5962 /* For QNX select() always returns 1 if this is set. Why? */ | |
5963 FD_SET(fd, &efds); | |
5964 # endif | |
5965 maxfd = fd; | |
5966 | |
5967 # ifdef FEAT_XCLIPBOARD | |
6383 | 5968 may_restore_clipboard(); |
7 | 5969 if (xterm_Shell != (Widget)0) |
5970 { | |
5971 FD_SET(ConnectionNumber(xterm_dpy), &rfds); | |
5972 if (maxfd < ConnectionNumber(xterm_dpy)) | |
5973 maxfd = ConnectionNumber(xterm_dpy); | |
3748 | 5974 |
5975 /* An event may have already been read but not handled. In | |
5976 * particulary, XFlush may cause this. */ | |
5977 xterm_update(); | |
7 | 5978 } |
5979 # endif | |
5980 # ifdef FEAT_MOUSE_GPM | |
5981 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
5982 { | |
5983 FD_SET(gpm_fd, &rfds); | |
5984 FD_SET(gpm_fd, &efds); | |
5985 if (maxfd < gpm_fd) | |
5986 maxfd = gpm_fd; | |
5987 } | |
5988 # endif | |
5989 # ifdef USE_XSMP | |
5990 if (xsmp_icefd != -1) | |
5991 { | |
5992 FD_SET(xsmp_icefd, &rfds); | |
5993 FD_SET(xsmp_icefd, &efds); | |
5994 if (maxfd < xsmp_icefd) | |
5995 maxfd = xsmp_icefd; | |
5996 } | |
5997 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5998 # ifdef FEAT_JOB_CHANNEL |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5999 maxfd = channel_select_setup(maxfd, &rfds, &wfds); |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6000 # endif |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6001 if (interrupted != NULL) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6002 *interrupted = FALSE; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6003 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6004 ret = select(maxfd + 1, &rfds, &wfds, &efds, tvp); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6005 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
|
6006 if (result) |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6007 --ret; |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6008 else if (interrupted != NULL && ret > 0) |
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9189
diff
changeset
|
6009 *interrupted = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6010 |
3046 | 6011 # ifdef EINTR |
6012 if (ret == -1 && errno == EINTR) | |
3133 | 6013 { |
6014 /* Check whether window has been resized, EINTR may be caused by | |
6015 * SIGWINCH. */ | |
6016 if (do_resize) | |
6017 handle_resize(); | |
6018 | |
3046 | 6019 /* Interrupted by a signal, need to try again. We ignore msec |
6020 * here, because we do want to check even after a timeout if | |
6021 * characters are available. Needed for reading output of an | |
6022 * external command after the process has finished. */ | |
6023 goto select_eintr; | |
3133 | 6024 } |
3046 | 6025 # endif |
1076 | 6026 # ifdef __TANDEM |
6027 if (ret == -1 && errno == ENOTSUP) | |
6028 { | |
6029 FD_ZERO(&rfds); | |
6030 FD_ZERO(&efds); | |
6031 ret = 0; | |
6032 } | |
3046 | 6033 # endif |
14 | 6034 # ifdef FEAT_MZSCHEME |
6035 if (ret == 0 && mzquantum_used) | |
1450 | 6036 /* loop if MzThreads must be scheduled and timeout occurred */ |
14 | 6037 finished = FALSE; |
7 | 6038 # endif |
6039 | |
6040 # ifdef FEAT_XCLIPBOARD | |
6041 if (ret > 0 && xterm_Shell != (Widget)0 | |
6042 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) | |
6043 { | |
6044 xterm_update(); /* Maybe we should hand out clipboard */ | |
6045 /* continue looping when we only got the X event and the input | |
6046 * buffer is empty */ | |
6047 if (--ret == 0 && !input_available()) | |
6048 { | |
6049 /* Try again */ | |
6050 finished = FALSE; | |
6051 } | |
6052 } | |
6053 # endif | |
6054 # ifdef FEAT_MOUSE_GPM | |
6055 if (ret > 0 && gpm_flag && check_for_gpm != NULL && gpm_fd >= 0) | |
6056 { | |
6057 if (FD_ISSET(gpm_fd, &efds)) | |
6058 gpm_close(); | |
6059 else if (FD_ISSET(gpm_fd, &rfds)) | |
6060 *check_for_gpm = 1; | |
6061 } | |
6062 # endif | |
6063 # ifdef USE_XSMP | |
6064 if (ret > 0 && xsmp_icefd != -1) | |
6065 { | |
6066 if (FD_ISSET(xsmp_icefd, &efds)) | |
6067 { | |
6068 if (p_verbose > 0) | |
292 | 6069 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 6070 xsmp_close(); |
6071 if (--ret == 0) | |
6072 finished = FALSE; /* keep going if event was only one */ | |
6073 } | |
6074 else if (FD_ISSET(xsmp_icefd, &rfds)) | |
6075 { | |
6076 busy = TRUE; | |
6077 xsmp_handle_requests(); | |
6078 busy = FALSE; | |
6079 if (--ret == 0) | |
6080 finished = FALSE; /* keep going if event was only one */ | |
6081 } | |
6082 } | |
6083 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
6084 #ifdef FEAT_JOB_CHANNEL |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
6085 if (ret > 0) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
6086 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
|
6087 #endif |
7 | 6088 |
6089 #endif /* HAVE_SELECT */ | |
6090 | |
6091 #ifdef MAY_LOOP | |
6092 if (finished || msec == 0) | |
6093 break; | |
6094 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6095 # ifdef FEAT_CLIENTSERVER |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6096 if (server_waiting()) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6097 break; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6098 # endif |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
6099 |
7 | 6100 /* We're going to loop around again, find out for how long */ |
6101 if (msec > 0) | |
6102 { | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6103 # ifdef ELAPSED_FUNC |
7 | 6104 /* Compute remaining wait time. */ |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
6105 msec = start_msec - ELAPSED_FUNC(start_tv); |
7 | 6106 # else |
6107 /* Guess we got interrupted halfway. */ | |
6108 msec = msec / 2; | |
6109 # endif | |
6110 if (msec <= 0) | |
6111 break; /* waited long enough */ | |
6112 } | |
6113 #endif | |
6114 } | |
6115 | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
6116 return result; |
7 | 6117 } |
6118 | |
6119 #ifndef NO_EXPANDPATH | |
6120 /* | |
444 | 6121 * Expand a path into all matching files and/or directories. Handles "*", |
6122 * "?", "[a-z]", "**", etc. | |
6123 * "path" has backslashes before chars that are not to be expanded. | |
6124 * Returns the number of matches found. | |
7 | 6125 */ |
6126 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6127 mch_expandpath( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6128 garray_T *gap, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6129 char_u *path, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6130 int flags) /* EW_* flags */ |
7 | 6131 { |
444 | 6132 return unix_expandpath(gap, path, 0, flags, FALSE); |
7 | 6133 } |
6134 #endif | |
6135 | |
6136 /* | |
6137 * mch_expand_wildcards() - this code does wild-card pattern matching using | |
6138 * the shell | |
6139 * | |
6140 * return OK for success, FAIL for error (you may lose some memory) and put | |
6141 * an error message in *file. | |
6142 * | |
6143 * num_pat is number of input patterns | |
6144 * pat is array of pointers to input patterns | |
6145 * num_file is pointer to number of matched file names | |
6146 * file is pointer to array of pointers to matched file names | |
6147 */ | |
6148 | |
6149 #ifndef SEEK_SET | |
6150 # define SEEK_SET 0 | |
6151 #endif | |
6152 #ifndef SEEK_END | |
6153 # define SEEK_END 2 | |
6154 #endif | |
6155 | |
822 | 6156 #define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
628 | 6157 |
7 | 6158 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6159 mch_expand_wildcards( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6160 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6161 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6162 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6163 char_u ***file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6164 int flags) /* EW_* flags */ |
7 | 6165 { |
6166 int i; | |
6167 size_t len; | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6168 long llen; |
7 | 6169 char_u *p; |
6170 int dir; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9381
diff
changeset
|
6171 |
1508 | 6172 /* |
6173 * This is the non-OS/2 implementation (really Unix). | |
6174 */ | |
7 | 6175 int j; |
6176 char_u *tempname; | |
6177 char_u *command; | |
6178 FILE *fd; | |
6179 char_u *buffer; | |
1508 | 6180 #define STYLE_ECHO 0 /* use "echo", the default */ |
6181 #define STYLE_GLOB 1 /* use "glob", for csh */ | |
6182 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
6183 #define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
6184 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
6185 * directly */ | |
7 | 6186 int shell_style = STYLE_ECHO; |
6187 int check_spaces; | |
6188 static int did_find_nul = FALSE; | |
6189 int ampersent = FALSE; | |
1508 | 6190 /* vimglob() function to define for Posix shell */ |
1620 | 6191 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; |
7 | 6192 |
6193 *num_file = 0; /* default: no files found */ | |
6194 *file = NULL; | |
6195 | |
6196 /* | |
6197 * If there are no wildcards, just copy the names to allocated memory. | |
6198 * Saves a lot of time, because we don't have to start a new shell. | |
6199 */ | |
6200 if (!have_wildcard(num_pat, pat)) | |
6201 return save_patterns(num_pat, pat, num_file, file); | |
6202 | |
428 | 6203 # ifdef HAVE_SANDBOX |
6204 /* Don't allow any shell command in the sandbox. */ | |
6205 if (sandbox != 0 && check_secure()) | |
6206 return FAIL; | |
6207 # endif | |
6208 | |
7 | 6209 /* |
6210 * Don't allow the use of backticks in secure and restricted mode. | |
6211 */ | |
428 | 6212 if (secure || restricted) |
7 | 6213 for (i = 0; i < num_pat; ++i) |
6214 if (vim_strchr(pat[i], '`') != NULL | |
6215 && (check_restricted() || check_secure())) | |
6216 return FAIL; | |
6217 | |
6218 /* | |
6219 * get a name for the temp file | |
6220 */ | |
6721 | 6221 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 6222 { |
6223 EMSG(_(e_notmp)); | |
6224 return FAIL; | |
6225 } | |
6226 | |
6227 /* | |
6228 * Let the shell expand the patterns and write the result into the temp | |
1508 | 6229 * file. |
6230 * STYLE_BT: NL separated | |
6231 * If expanding `cmd` execute it directly. | |
6232 * STYLE_GLOB: NUL separated | |
6233 * If we use *csh, "glob" will work better than "echo". | |
6234 * STYLE_PRINT: NL or NUL separated | |
6235 * If we use *zsh, "print -N" will work better than "glob". | |
6236 * STYLE_VIMGLOB: NL separated | |
6237 * If we use *sh*, we define "vimglob()". | |
6238 * STYLE_ECHO: space separated. | |
6239 * A shell we don't know, stay safe and use "echo". | |
7 | 6240 */ |
6241 if (num_pat == 1 && *pat[0] == '`' | |
6242 && (len = STRLEN(pat[0])) > 2 | |
6243 && *(pat[0] + len - 1) == '`') | |
6244 shell_style = STYLE_BT; | |
6245 else if ((len = STRLEN(p_sh)) >= 3) | |
6246 { | |
6247 if (STRCMP(p_sh + len - 3, "csh") == 0) | |
6248 shell_style = STYLE_GLOB; | |
6249 else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
6250 shell_style = STYLE_PRINT; | |
6251 } | |
1508 | 6252 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), |
6253 "sh") != NULL) | |
6254 shell_style = STYLE_VIMGLOB; | |
6255 | |
6256 /* Compute the length of the command. We need 2 extra bytes: for the | |
6257 * optional '&' and for the NUL. | |
6258 * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
7 | 6259 len = STRLEN(tempname) + 29; |
1508 | 6260 if (shell_style == STYLE_VIMGLOB) |
6261 len += STRLEN(sh_vimglob_func); | |
6262 | |
147 | 6263 for (i = 0; i < num_pat; ++i) |
6264 { | |
6265 /* Count the length of the patterns in the same way as they are put in | |
6266 * "command" below. */ | |
6267 #ifdef USE_SYSTEM | |
7 | 6268 len += STRLEN(pat[i]) + 3; /* add space and two quotes */ |
147 | 6269 #else |
6270 ++len; /* add space */ | |
628 | 6271 for (j = 0; pat[i][j] != NUL; ++j) |
6272 { | |
6273 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
6274 ++len; /* may add a backslash */ | |
6275 ++len; | |
6276 } | |
147 | 6277 #endif |
6278 } | |
7 | 6279 command = alloc(len); |
6280 if (command == NULL) | |
6281 { | |
6282 /* out of memory */ | |
6283 vim_free(tempname); | |
6284 return FAIL; | |
6285 } | |
6286 | |
6287 /* | |
6288 * Build the shell command: | |
6289 * - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell | |
6290 * recognizes this). | |
6291 * - Add the shell command to print the expanded names. | |
6292 * - Add the temp file name. | |
6293 * - Add the file name patterns. | |
6294 */ | |
6295 if (shell_style == STYLE_BT) | |
6296 { | |
628 | 6297 /* change `command; command& ` to (command; command ) */ |
6298 STRCPY(command, "("); | |
6299 STRCAT(command, pat[0] + 1); /* exclude first backtick */ | |
7 | 6300 p = command + STRLEN(command) - 1; |
628 | 6301 *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
|
6302 while (p > command && VIM_ISWHITE(*p)) |
7 | 6303 --p; |
6304 if (*p == '&') /* remove trailing '&' */ | |
6305 { | |
6306 ampersent = TRUE; | |
6307 *p = ' '; | |
6308 } | |
6309 STRCAT(command, ">"); | |
6310 } | |
6311 else | |
6312 { | |
6313 if (flags & EW_NOTFOUND) | |
6314 STRCPY(command, "set nonomatch; "); | |
6315 else | |
6316 STRCPY(command, "unset nonomatch; "); | |
6317 if (shell_style == STYLE_GLOB) | |
6318 STRCAT(command, "glob >"); | |
6319 else if (shell_style == STYLE_PRINT) | |
6320 STRCAT(command, "print -N >"); | |
1508 | 6321 else if (shell_style == STYLE_VIMGLOB) |
6322 STRCAT(command, sh_vimglob_func); | |
7 | 6323 else |
6324 STRCAT(command, "echo >"); | |
6325 } | |
1508 | 6326 |
7 | 6327 STRCAT(command, tempname); |
1508 | 6328 |
7 | 6329 if (shell_style != STYLE_BT) |
6330 for (i = 0; i < num_pat; ++i) | |
6331 { | |
6332 /* When using system() always add extra quotes, because the shell | |
628 | 6333 * is started twice. Otherwise put a backslash before special |
1450 | 6334 * characters, except inside ``. */ |
7 | 6335 #ifdef USE_SYSTEM |
6336 STRCAT(command, " \""); | |
6337 STRCAT(command, pat[i]); | |
6338 STRCAT(command, "\""); | |
6339 #else | |
233 | 6340 int intick = FALSE; |
6341 | |
7 | 6342 p = command + STRLEN(command); |
6343 *p++ = ' '; | |
628 | 6344 for (j = 0; pat[i][j] != NUL; ++j) |
233 | 6345 { |
6346 if (pat[i][j] == '`') | |
6347 intick = !intick; | |
628 | 6348 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) |
6349 { | |
644 | 6350 /* Remove a backslash, take char literally. But keep |
652 | 6351 * backslash inside backticks, before a special character |
6352 * and before a backtick. */ | |
644 | 6353 if (intick |
652 | 6354 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL |
6355 || pat[i][j + 1] == '`') | |
644 | 6356 *p++ = '\\'; |
648 | 6357 ++j; |
628 | 6358 } |
6174 | 6359 else if (!intick |
6360 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') | |
6361 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
628 | 6362 /* Put a backslash before a special character, but not |
6174 | 6363 * when inside ``. And not for $var when EW_KEEPDOLLAR is |
6364 * set. */ | |
628 | 6365 *p++ = '\\'; |
648 | 6366 |
6367 /* Copy one character. */ | |
6368 *p++ = pat[i][j]; | |
233 | 6369 } |
7 | 6370 *p = NUL; |
6371 #endif | |
6372 } | |
6373 if (flags & EW_SILENT) | |
6374 show_shell_mess = FALSE; | |
6375 if (ampersent) | |
1508 | 6376 STRCAT(command, "&"); /* put the '&' after the redirection */ |
7 | 6377 |
6378 /* | |
6379 * Using zsh -G: If a pattern has no matches, it is just deleted from | |
6380 * the argument list, otherwise zsh gives an error message and doesn't | |
6381 * expand any other pattern. | |
6382 */ | |
6383 if (shell_style == STYLE_PRINT) | |
6384 extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ | |
6385 | |
6386 /* | |
6387 * If we use -f then shell variables set in .cshrc won't get expanded. | |
6388 * vi can do it, so we will too, but it is only necessary if there is a "$" | |
6389 * in one of the patterns, otherwise we can still use the fast option. | |
6390 */ | |
6391 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) | |
6392 extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ | |
6393 | |
6394 /* | |
6395 * execute the shell command | |
6396 */ | |
6397 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); | |
6398 | |
6399 /* When running in the background, give it some time to create the temp | |
6400 * file, but don't wait for it to finish. */ | |
6401 if (ampersent) | |
6402 mch_delay(10L, TRUE); | |
6403 | |
6404 extra_shell_arg = NULL; /* cleanup */ | |
6405 show_shell_mess = TRUE; | |
6406 vim_free(command); | |
6407 | |
1508 | 6408 if (i != 0) /* mch_call_shell() failed */ |
7 | 6409 { |
6410 mch_remove(tempname); | |
6411 vim_free(tempname); | |
6412 /* | |
6413 * With interactive completion, the error message is not printed. | |
6414 * However with USE_SYSTEM, I don't know how to turn off error messages | |
6415 * from the shell, so screen may still get messed up -- webb. | |
6416 */ | |
6417 #ifndef USE_SYSTEM | |
6418 if (!(flags & EW_SILENT)) | |
6419 #endif | |
6420 { | |
6421 redraw_later_clear(); /* probably messed up screen */ | |
6422 msg_putchar('\n'); /* clear bottom line quickly */ | |
6423 cmdline_row = Rows - 1; /* continue on last line */ | |
6424 #ifdef USE_SYSTEM | |
6425 if (!(flags & EW_SILENT)) | |
6426 #endif | |
6427 { | |
6428 MSG(_(e_wildexpand)); | |
6429 msg_start(); /* don't overwrite this message */ | |
6430 } | |
6431 } | |
6432 /* If a `cmd` expansion failed, don't list `cmd` as a match, even when | |
6433 * EW_NOTFOUND is given */ | |
6434 if (shell_style == STYLE_BT) | |
6435 return FAIL; | |
6436 goto notfound; | |
6437 } | |
6438 | |
6439 /* | |
6440 * read the names from the file into memory | |
6441 */ | |
6442 fd = fopen((char *)tempname, READBIN); | |
6443 if (fd == NULL) | |
6444 { | |
6445 /* Something went wrong, perhaps a file name with a special char. */ | |
6446 if (!(flags & EW_SILENT)) | |
6447 { | |
6448 MSG(_(e_wildexpand)); | |
6449 msg_start(); /* don't overwrite this message */ | |
6450 } | |
6451 vim_free(tempname); | |
6452 goto notfound; | |
6453 } | |
6454 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
|
6455 llen = ftell(fd); /* get size of temp file */ |
7 | 6456 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
|
6457 if (llen < 0) |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6458 /* 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
|
6459 buffer = NULL; |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6460 else |
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6461 buffer = alloc(llen + 1); |
7 | 6462 if (buffer == NULL) |
6463 { | |
6464 /* out of memory */ | |
6465 mch_remove(tempname); | |
6466 vim_free(tempname); | |
6467 fclose(fd); | |
6468 return FAIL; | |
6469 } | |
11281
2e6a0ea76a0d
patch 8.0.0526: Coverity complains about possible negative value
Christian Brabandt <cb@256bit.org>
parents:
11252
diff
changeset
|
6470 len = llen; |
7 | 6471 i = fread((char *)buffer, 1, len, fd); |
6472 fclose(fd); | |
6473 mch_remove(tempname); | |
1877 | 6474 if (i != (int)len) |
7 | 6475 { |
6476 /* unexpected read error */ | |
6477 EMSG2(_(e_notread), tempname); | |
6478 vim_free(tempname); | |
6479 vim_free(buffer); | |
6480 return FAIL; | |
6481 } | |
6482 vim_free(tempname); | |
6483 | |
1508 | 6484 # if defined(__CYGWIN__) || defined(__CYGWIN32__) |
7 | 6485 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ |
6486 p = buffer; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
6487 for (i = 0; i < (int)len; ++i) |
7 | 6488 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) |
6489 *p++ = buffer[i]; | |
6490 len = p - buffer; | |
6491 # endif | |
6492 | |
6493 | |
6494 /* file names are separated with Space */ | |
6495 if (shell_style == STYLE_ECHO) | |
6496 { | |
6497 buffer[len] = '\n'; /* make sure the buffer ends in NL */ | |
6498 p = buffer; | |
6499 for (i = 0; *p != '\n'; ++i) /* count number of entries */ | |
6500 { | |
6501 while (*p != ' ' && *p != '\n') | |
6502 ++p; | |
6503 p = skipwhite(p); /* skip to next entry */ | |
6504 } | |
6505 } | |
6506 /* file names are separated with NL */ | |
1508 | 6507 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) |
7 | 6508 { |
6509 buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
6510 p = buffer; | |
6511 for (i = 0; *p != NUL; ++i) /* count number of entries */ | |
6512 { | |
6513 while (*p != '\n' && *p != NUL) | |
6514 ++p; | |
6515 if (*p != NUL) | |
6516 ++p; | |
6517 p = skipwhite(p); /* skip leading white space */ | |
6518 } | |
6519 } | |
6520 /* file names are separated with NUL */ | |
6521 else | |
6522 { | |
6523 /* | |
6524 * Some versions of zsh use spaces instead of NULs to separate | |
6525 * results. Only do this when there is no NUL before the end of the | |
6526 * buffer, otherwise we would never be able to use file names with | |
6527 * embedded spaces when zsh does use NULs. | |
6528 * When we found a NUL once, we know zsh is OK, set did_find_nul and | |
6529 * don't check for spaces again. | |
6530 */ | |
6531 check_spaces = FALSE; | |
6532 if (shell_style == STYLE_PRINT && !did_find_nul) | |
6533 { | |
6534 /* If there is a NUL, set did_find_nul, else set check_spaces */ | |
2768 | 6535 buffer[len] = NUL; |
5533 | 6536 if (len && (int)STRLEN(buffer) < (int)len) |
7 | 6537 did_find_nul = TRUE; |
6538 else | |
6539 check_spaces = TRUE; | |
6540 } | |
6541 | |
6542 /* | |
6543 * Make sure the buffer ends with a NUL. For STYLE_PRINT there | |
6544 * already is one, for STYLE_GLOB it needs to be added. | |
6545 */ | |
6546 if (len && buffer[len - 1] == NUL) | |
6547 --len; | |
6548 else | |
6549 buffer[len] = NUL; | |
6550 i = 0; | |
6551 for (p = buffer; p < buffer + len; ++p) | |
6552 if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ | |
6553 { | |
6554 ++i; | |
6555 *p = NUL; | |
6556 } | |
6557 if (len) | |
6558 ++i; /* count last entry */ | |
6559 } | |
6560 if (i == 0) | |
6561 { | |
6562 /* | |
6563 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I". | |
6564 * /bin/sh will happily expand it to nothing rather than returning an | |
6565 * error; and hey, it's good to check anyway -- webb. | |
6566 */ | |
6567 vim_free(buffer); | |
6568 goto notfound; | |
6569 } | |
6570 *num_file = i; | |
6571 *file = (char_u **)alloc(sizeof(char_u *) * i); | |
6572 if (*file == NULL) | |
6573 { | |
6574 /* out of memory */ | |
6575 vim_free(buffer); | |
6576 return FAIL; | |
6577 } | |
6578 | |
6579 /* | |
6580 * Isolate the individual file names. | |
6581 */ | |
6582 p = buffer; | |
6583 for (i = 0; i < *num_file; ++i) | |
6584 { | |
6585 (*file)[i] = p; | |
6586 /* Space or NL separates */ | |
1508 | 6587 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT |
6588 || shell_style == STYLE_VIMGLOB) | |
7 | 6589 { |
652 | 6590 while (!(shell_style == STYLE_ECHO && *p == ' ') |
6591 && *p != '\n' && *p != NUL) | |
7 | 6592 ++p; |
6593 if (p == buffer + len) /* last entry */ | |
6594 *p = NUL; | |
6595 else | |
6596 { | |
6597 *p++ = NUL; | |
6598 p = skipwhite(p); /* skip to next entry */ | |
6599 } | |
6600 } | |
6601 else /* NUL separates */ | |
6602 { | |
6603 while (*p && p < buffer + len) /* skip entry */ | |
6604 ++p; | |
6605 ++p; /* skip NUL */ | |
6606 } | |
6607 } | |
6608 | |
6609 /* | |
6610 * Move the file names to allocated memory. | |
6611 */ | |
6612 for (j = 0, i = 0; i < *num_file; ++i) | |
6613 { | |
6614 /* Require the files to exist. Helps when using /bin/sh */ | |
6615 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) | |
6616 continue; | |
6617 | |
6618 /* check if this entry should be included */ | |
6619 dir = (mch_isdir((*file)[i])); | |
6620 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) | |
6621 continue; | |
6622 | |
715 | 6623 /* Skip files that are not executable if we check for that. */ |
6695 | 6624 if (!dir && (flags & EW_EXEC) |
6625 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) | |
715 | 6626 continue; |
6627 | |
7 | 6628 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); |
6629 if (p) | |
6630 { | |
6631 STRCPY(p, (*file)[i]); | |
6632 if (dir) | |
1479 | 6633 add_pathsep(p); /* add '/' to a directory name */ |
7 | 6634 (*file)[j++] = p; |
6635 } | |
6636 } | |
6637 vim_free(buffer); | |
6638 *num_file = j; | |
6639 | |
6640 if (*num_file == 0) /* rejected all entries */ | |
6641 { | |
6642 vim_free(*file); | |
6643 *file = NULL; | |
6644 goto notfound; | |
6645 } | |
6646 | |
6647 return OK; | |
6648 | |
6649 notfound: | |
6650 if (flags & EW_NOTFOUND) | |
6651 return save_patterns(num_pat, pat, num_file, file); | |
6652 return FAIL; | |
6653 } | |
6654 | |
6655 #endif /* VMS */ | |
6656 | |
6657 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6658 save_patterns( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6659 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6660 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6661 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6662 char_u ***file) |
7 | 6663 { |
6664 int i; | |
99 | 6665 char_u *s; |
7 | 6666 |
6667 *file = (char_u **)alloc(num_pat * sizeof(char_u *)); | |
6668 if (*file == NULL) | |
6669 return FAIL; | |
6670 for (i = 0; i < num_pat; i++) | |
99 | 6671 { |
6672 s = vim_strsave(pat[i]); | |
6673 if (s != NULL) | |
6674 /* Be compatible with expand_filename(): halve the number of | |
6675 * backslashes. */ | |
6676 backslash_halve(s); | |
6677 (*file)[i] = s; | |
6678 } | |
7 | 6679 *num_file = num_pat; |
6680 return OK; | |
6681 } | |
6682 | |
6683 /* | |
6684 * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can | |
6685 * expand. | |
6686 */ | |
6687 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6688 mch_has_exp_wildcard(char_u *p) |
7 | 6689 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
6690 for ( ; *p; MB_PTR_ADV(p)) |
7 | 6691 { |
6692 if (*p == '\\' && p[1] != NUL) | |
6693 ++p; | |
6694 else | |
6695 if (vim_strchr((char_u *) | |
6696 #ifdef VMS | |
6697 "*?%" | |
6698 #else | |
6699 "*?[{'" | |
6700 #endif | |
6701 , *p) != NULL) | |
6702 return TRUE; | |
6703 } | |
6704 return FALSE; | |
6705 } | |
6706 | |
6707 /* | |
6708 * Return TRUE if the string "p" contains a wildcard. | |
6709 * Don't recognize '~' at the end as a wildcard. | |
6710 */ | |
6711 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6712 mch_has_wildcard(char_u *p) |
7 | 6713 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11115
diff
changeset
|
6714 for ( ; *p; MB_PTR_ADV(p)) |
7 | 6715 { |
6716 if (*p == '\\' && p[1] != NUL) | |
6717 ++p; | |
6718 else | |
6719 if (vim_strchr((char_u *) | |
6720 #ifdef VMS | |
6721 "*?%$" | |
6722 #else | |
6723 "*?[{`'$" | |
6724 #endif | |
6725 , *p) != NULL | |
6726 || (*p == '~' && p[1] != NUL)) | |
6727 return TRUE; | |
6728 } | |
6729 return FALSE; | |
6730 } | |
6731 | |
6732 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6733 have_wildcard(int num, char_u **file) |
7 | 6734 { |
6735 int i; | |
6736 | |
6737 for (i = 0; i < num; i++) | |
6738 if (mch_has_wildcard(file[i])) | |
6739 return 1; | |
6740 return 0; | |
6741 } | |
6742 | |
6743 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6744 have_dollars(int num, char_u **file) |
7 | 6745 { |
6746 int i; | |
6747 | |
6748 for (i = 0; i < num; i++) | |
6749 if (vim_strchr(file[i], '$') != NULL) | |
6750 return TRUE; | |
6751 return FALSE; | |
6752 } | |
6753 | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
6754 #if !defined(HAVE_RENAME) || defined(PROTO) |
7 | 6755 /* |
6756 * Scaled-down version of rename(), which is missing in Xenix. | |
6757 * This version can only move regular files and will fail if the | |
6758 * destination exists. | |
6759 */ | |
6760 int | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
6761 mch_rename(const char *src, const char *dest) |
7 | 6762 { |
6763 struct stat st; | |
6764 | |
6765 if (stat(dest, &st) >= 0) /* fail if destination exists */ | |
6766 return -1; | |
6767 if (link(src, dest) != 0) /* link file to new name */ | |
6768 return -1; | |
6769 if (mch_remove(src) == 0) /* delete link to old name */ | |
6770 return 0; | |
6771 return -1; | |
6772 } | |
6773 #endif /* !HAVE_RENAME */ | |
6774 | |
6775 #ifdef FEAT_MOUSE_GPM | |
6776 /* | |
6777 * Initializes connection with gpm (if it isn't already opened) | |
6778 * Return 1 if succeeded (or connection already opened), 0 if failed | |
6779 */ | |
6780 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6781 gpm_open(void) |
7 | 6782 { |
6783 static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ | |
6784 | |
6785 if (!gpm_flag) | |
6786 { | |
6787 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); | |
6788 gpm_connect.defaultMask = ~GPM_HARD; | |
6789 /* Default handling for mouse move*/ | |
6790 gpm_connect.minMod = 0; /* Handle any modifier keys */ | |
6791 gpm_connect.maxMod = 0xffff; | |
6792 if (Gpm_Open(&gpm_connect, 0) > 0) | |
6793 { | |
6794 /* gpm library tries to handling TSTP causes | |
6795 * problems. Anyways, we close connection to Gpm whenever | |
6796 * we are going to suspend or starting an external process | |
1450 | 6797 * so we shouldn't have problem with this |
7 | 6798 */ |
1832 | 6799 # ifdef SIGTSTP |
7 | 6800 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); |
1832 | 6801 # endif |
7 | 6802 return 1; /* succeed */ |
6803 } | |
6804 if (gpm_fd == -2) | |
6805 Gpm_Close(); /* We don't want to talk to xterm via gpm */ | |
6806 return 0; | |
6807 } | |
6808 return 1; /* already open */ | |
6809 } | |
6810 | |
6811 /* | |
6812 * Closes connection to gpm | |
6813 */ | |
6814 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6815 gpm_close(void) |
7 | 6816 { |
6817 if (gpm_flag && gpm_fd >= 0) /* if Open */ | |
6818 Gpm_Close(); | |
6819 } | |
6820 | |
6821 /* Reads gpm event and adds special keys to input buf. Returns length of | |
6822 * generated key sequence. | |
5782 | 6823 * This function is styled after gui_send_mouse_event(). |
7 | 6824 */ |
6825 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6826 mch_gpm_process(void) |
7 | 6827 { |
6828 int button; | |
6829 static Gpm_Event gpm_event; | |
6830 char_u string[6]; | |
6831 int_u vim_modifiers; | |
6832 int row,col; | |
6833 unsigned char buttons_mask; | |
6834 unsigned char gpm_modifiers; | |
6835 static unsigned char old_buttons = 0; | |
6836 | |
6837 Gpm_GetEvent(&gpm_event); | |
6838 | |
6839 #ifdef FEAT_GUI | |
6840 /* Don't put events in the input queue now. */ | |
6841 if (hold_gui_events) | |
6842 return 0; | |
6843 #endif | |
6844 | |
6845 row = gpm_event.y - 1; | |
6846 col = gpm_event.x - 1; | |
6847 | |
6848 string[0] = ESC; /* Our termcode */ | |
6849 string[1] = 'M'; | |
6850 string[2] = 'G'; | |
6851 switch (GPM_BARE_EVENTS(gpm_event.type)) | |
6852 { | |
6853 case GPM_DRAG: | |
6854 string[3] = MOUSE_DRAG; | |
6855 break; | |
6856 case GPM_DOWN: | |
6857 buttons_mask = gpm_event.buttons & ~old_buttons; | |
6858 old_buttons = gpm_event.buttons; | |
6859 switch (buttons_mask) | |
6860 { | |
6861 case GPM_B_LEFT: | |
6862 button = MOUSE_LEFT; | |
6863 break; | |
6864 case GPM_B_MIDDLE: | |
6865 button = MOUSE_MIDDLE; | |
6866 break; | |
6867 case GPM_B_RIGHT: | |
6868 button = MOUSE_RIGHT; | |
6869 break; | |
6870 default: | |
6871 return 0; | |
6872 /*Don't know what to do. Can more than one button be | |
6873 * reported in one event? */ | |
6874 } | |
6875 string[3] = (char_u)(button | 0x20); | |
6876 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); | |
6877 break; | |
6878 case GPM_UP: | |
6879 string[3] = MOUSE_RELEASE; | |
6880 old_buttons &= ~gpm_event.buttons; | |
6881 break; | |
6882 default: | |
6883 return 0; | |
6884 } | |
6885 /*This code is based on gui_x11_mouse_cb in gui_x11.c */ | |
6886 gpm_modifiers = gpm_event.modifiers; | |
6887 vim_modifiers = 0x0; | |
6888 /* I ignore capslock stats. Aren't we all just hate capslock mixing with | |
6889 * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and | |
6890 * K_CAPSSHIFT is defined 8, so it probably isn't even reported | |
6891 */ | |
6892 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) | |
6893 vim_modifiers |= MOUSE_SHIFT; | |
6894 | |
6895 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL))) | |
6896 vim_modifiers |= MOUSE_CTRL; | |
6897 if (gpm_modifiers & ((1 << KG_ALT) | (1 << KG_ALTGR))) | |
6898 vim_modifiers |= MOUSE_ALT; | |
6899 string[3] |= vim_modifiers; | |
6900 string[4] = (char_u)(col + ' ' + 1); | |
6901 string[5] = (char_u)(row + ' ' + 1); | |
6902 add_to_input_buf(string, 6); | |
6903 return 6; | |
6904 } | |
6905 #endif /* FEAT_MOUSE_GPM */ | |
6906 | |
1620 | 6907 #ifdef FEAT_SYSMOUSE |
6908 /* | |
6909 * Initialize connection with sysmouse. | |
6910 * Let virtual console inform us with SIGUSR2 for pending sysmouse | |
6911 * output, any sysmouse output than will be processed via sig_sysmouse(). | |
6912 * Return OK if succeeded, FAIL if failed. | |
6913 */ | |
6914 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6915 sysmouse_open(void) |
1620 | 6916 { |
6917 struct mouse_info mouse; | |
6918 | |
6919 mouse.operation = MOUSE_MODE; | |
6920 mouse.u.mode.mode = 0; | |
6921 mouse.u.mode.signal = SIGUSR2; | |
6922 if (ioctl(1, CONS_MOUSECTL, &mouse) != -1) | |
6923 { | |
6924 signal(SIGUSR2, (RETSIGTYPE (*)())sig_sysmouse); | |
6925 mouse.operation = MOUSE_SHOW; | |
6926 ioctl(1, CONS_MOUSECTL, &mouse); | |
6927 return OK; | |
6928 } | |
6929 return FAIL; | |
6930 } | |
6931 | |
6932 /* | |
6933 * Stop processing SIGUSR2 signals, and also make sure that | |
6934 * virtual console do not send us any sysmouse related signal. | |
6935 */ | |
6936 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6937 sysmouse_close(void) |
1620 | 6938 { |
6939 struct mouse_info mouse; | |
6940 | |
6941 signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL); | |
6942 mouse.operation = MOUSE_MODE; | |
6943 mouse.u.mode.mode = 0; | |
6944 mouse.u.mode.signal = 0; | |
6945 ioctl(1, CONS_MOUSECTL, &mouse); | |
6946 } | |
6947 | |
6948 /* | |
6949 * Gets info from sysmouse and adds special keys to input buf. | |
6950 */ | |
6951 static RETSIGTYPE | |
6952 sig_sysmouse SIGDEFARG(sigarg) | |
6953 { | |
6954 struct mouse_info mouse; | |
6955 struct video_info video; | |
6956 char_u string[6]; | |
6957 int row, col; | |
6958 int button; | |
6959 int buttons; | |
6960 static int oldbuttons = 0; | |
6961 | |
6962 #ifdef FEAT_GUI | |
6963 /* Don't put events in the input queue now. */ | |
6964 if (hold_gui_events) | |
6965 return; | |
6966 #endif | |
6967 | |
6968 mouse.operation = MOUSE_GETINFO; | |
6969 if (ioctl(1, FBIO_GETMODE, &video.vi_mode) != -1 | |
6970 && ioctl(1, FBIO_MODEINFO, &video) != -1 | |
6971 && ioctl(1, CONS_MOUSECTL, &mouse) != -1 | |
6972 && video.vi_cheight > 0 && video.vi_cwidth > 0) | |
6973 { | |
6974 row = mouse.u.data.y / video.vi_cheight; | |
6975 col = mouse.u.data.x / video.vi_cwidth; | |
6976 buttons = mouse.u.data.buttons; | |
6977 string[0] = ESC; /* Our termcode */ | |
6978 string[1] = 'M'; | |
6979 string[2] = 'S'; | |
6980 if (oldbuttons == buttons && buttons != 0) | |
6981 { | |
6982 button = MOUSE_DRAG; | |
6983 } | |
6984 else | |
6985 { | |
6986 switch (buttons) | |
6987 { | |
6988 case 0: | |
6989 button = MOUSE_RELEASE; | |
6990 break; | |
6991 case 1: | |
6992 button = MOUSE_LEFT; | |
6993 break; | |
6994 case 2: | |
6995 button = MOUSE_MIDDLE; | |
6996 break; | |
6997 case 4: | |
6998 button = MOUSE_RIGHT; | |
6999 break; | |
7000 default: | |
7001 return; | |
7002 } | |
7003 oldbuttons = buttons; | |
7004 } | |
7005 string[3] = (char_u)(button); | |
7006 string[4] = (char_u)(col + ' ' + 1); | |
7007 string[5] = (char_u)(row + ' ' + 1); | |
7008 add_to_input_buf(string, 6); | |
7009 } | |
7010 return; | |
7011 } | |
7012 #endif /* FEAT_SYSMOUSE */ | |
7013 | |
7 | 7014 #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
|
7015 typedef char_u * (*STRPROCSTR)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7016 typedef char_u * (*INTPROCSTR)(int); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7017 typedef int (*STRPROCINT)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7018 typedef int (*INTPROCINT)(int); |
7 | 7019 |
7020 /* | |
7021 * Call a DLL routine which takes either a string or int param | |
7022 * and returns an allocated string. | |
7023 */ | |
7024 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7025 mch_libcall( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7026 char_u *libname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7027 char_u *funcname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7028 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
|
7029 int argint, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7030 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
|
7031 int *number_result) |
7 | 7032 { |
7033 # if defined(USE_DLOPEN) | |
7034 void *hinstLib; | |
12 | 7035 char *dlerr = NULL; |
7 | 7036 # else |
7037 shl_t hinstLib; | |
7038 # endif | |
7039 STRPROCSTR ProcAdd; | |
7040 INTPROCSTR ProcAddI; | |
7041 char_u *retval_str = NULL; | |
7042 int retval_int = 0; | |
7043 int success = FALSE; | |
7044 | |
900 | 7045 /* |
7046 * Get a handle to the DLL module. | |
7047 */ | |
7 | 7048 # if defined(USE_DLOPEN) |
900 | 7049 /* First clear any error, it's not cleared by the dlopen() call. */ |
7050 (void)dlerror(); | |
7051 | |
7 | 7052 hinstLib = dlopen((char *)libname, RTLD_LAZY |
7053 # ifdef RTLD_LOCAL | |
7054 | RTLD_LOCAL | |
7055 # endif | |
7056 ); | |
12 | 7057 if (hinstLib == NULL) |
7058 { | |
7059 /* "dlerr" must be used before dlclose() */ | |
7060 dlerr = (char *)dlerror(); | |
7061 if (dlerr != NULL) | |
7062 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7063 } | |
7 | 7064 # else |
7065 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); | |
7066 # endif | |
7067 | |
7068 /* If the handle is valid, try to get the function address. */ | |
7069 if (hinstLib != NULL) | |
7070 { | |
7071 # ifdef HAVE_SETJMP_H | |
7072 /* | |
7073 * Catch a crash when calling the library function. For example when | |
7074 * using a number where a string pointer is expected. | |
7075 */ | |
7076 mch_startjmp(); | |
7077 if (SETJMP(lc_jump_env) != 0) | |
7078 { | |
7079 success = FALSE; | |
857 | 7080 # if defined(USE_DLOPEN) |
12 | 7081 dlerr = NULL; |
857 | 7082 # endif |
7 | 7083 mch_didjmp(); |
7084 } | |
7085 else | |
7086 # endif | |
7087 { | |
7088 retval_str = NULL; | |
7089 retval_int = 0; | |
7090 | |
7091 if (argstring != NULL) | |
7092 { | |
7093 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7094 *(void **)(&ProcAdd) = dlsym(hinstLib, (const char *)funcname); |
12 | 7095 dlerr = (char *)dlerror(); |
7 | 7096 # else |
7097 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7098 TYPE_PROCEDURE, (void *)&ProcAdd) < 0) | |
7099 ProcAdd = NULL; | |
7100 # endif | |
12 | 7101 if ((success = (ProcAdd != NULL |
7102 # if defined(USE_DLOPEN) | |
7103 && dlerr == NULL | |
7104 # endif | |
7105 ))) | |
7 | 7106 { |
7107 if (string_result == NULL) | |
7108 retval_int = ((STRPROCINT)ProcAdd)(argstring); | |
7109 else | |
7110 retval_str = (ProcAdd)(argstring); | |
7111 } | |
7112 } | |
7113 else | |
7114 { | |
7115 # if defined(USE_DLOPEN) | |
10620
2198b53b9ffe
patch 8.0.0199: compiler warnings for libcall
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
7116 *(void **)(&ProcAddI) = dlsym(hinstLib, (const char *)funcname); |
12 | 7117 dlerr = (char *)dlerror(); |
7 | 7118 # else |
7119 if (shl_findsym(&hinstLib, (const char *)funcname, | |
7120 TYPE_PROCEDURE, (void *)&ProcAddI) < 0) | |
7121 ProcAddI = NULL; | |
7122 # endif | |
12 | 7123 if ((success = (ProcAddI != NULL |
7124 # if defined(USE_DLOPEN) | |
7125 && dlerr == NULL | |
7126 # endif | |
7127 ))) | |
7 | 7128 { |
7129 if (string_result == NULL) | |
7130 retval_int = ((INTPROCINT)ProcAddI)(argint); | |
7131 else | |
7132 retval_str = (ProcAddI)(argint); | |
7133 } | |
7134 } | |
7135 | |
7136 /* Save the string before we free the library. */ | |
7137 /* Assume that a "1" or "-1" result is an illegal pointer. */ | |
7138 if (string_result == NULL) | |
7139 *number_result = retval_int; | |
7140 else if (retval_str != NULL | |
7141 && retval_str != (char_u *)1 | |
7142 && retval_str != (char_u *)-1) | |
7143 *string_result = vim_strsave(retval_str); | |
7144 } | |
7145 | |
7146 # ifdef HAVE_SETJMP_H | |
7147 mch_endjmp(); | |
7148 # ifdef SIGHASARG | |
7149 if (lc_signal != 0) | |
7150 { | |
7151 int i; | |
7152 | |
7153 /* try to find the name of this signal */ | |
7154 for (i = 0; signal_info[i].sig != -1; i++) | |
7155 if (lc_signal == signal_info[i].sig) | |
7156 break; | |
7157 EMSG2("E368: got SIG%s in libcall()", signal_info[i].name); | |
7158 } | |
7159 # endif | |
7160 # endif | |
7161 | |
12 | 7162 # if defined(USE_DLOPEN) |
7163 /* "dlerr" must be used before dlclose() */ | |
7164 if (dlerr != NULL) | |
7165 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7166 | |
7 | 7167 /* Free the DLL module. */ |
7168 (void)dlclose(hinstLib); | |
7169 # else | |
7170 (void)shl_unload(hinstLib); | |
7171 # endif | |
7172 } | |
7173 | |
7174 if (!success) | |
7175 { | |
7176 EMSG2(_(e_libcall), funcname); | |
7177 return FAIL; | |
7178 } | |
7179 | |
7180 return OK; | |
7181 } | |
7182 #endif | |
7183 | |
7184 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) | |
7185 static int xterm_trace = -1; /* default: disabled */ | |
7186 static int xterm_button; | |
7187 | |
7188 /* | |
7189 * Setup a dummy window for X selections in a terminal. | |
7190 */ | |
7191 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7192 setup_term_clip(void) |
7 | 7193 { |
7194 int z = 0; | |
7195 char *strp = ""; | |
7196 Widget AppShell; | |
7197 | |
7198 if (!x_connect_to_server()) | |
7199 return; | |
7200 | |
7201 open_app_context(); | |
7202 if (app_context != NULL && xterm_Shell == (Widget)0) | |
7203 { | |
7204 int (*oldhandler)(); | |
7205 #if defined(HAVE_SETJMP_H) | |
7206 int (*oldIOhandler)(); | |
7207 #endif | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7208 # ifdef ELAPSED_FUNC |
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7209 ELAPSED_TYPE start_tv; |
7 | 7210 |
7211 if (p_verbose > 0) | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7212 ELAPSED_INIT(start_tv); |
7 | 7213 # endif |
7214 | |
7215 /* Ignore X errors while opening the display */ | |
7216 oldhandler = XSetErrorHandler(x_error_check); | |
7217 | |
7218 #if defined(HAVE_SETJMP_H) | |
7219 /* Ignore X IO errors while opening the display */ | |
7220 oldIOhandler = XSetIOErrorHandler(x_IOerror_check); | |
7221 mch_startjmp(); | |
7222 if (SETJMP(lc_jump_env) != 0) | |
7223 { | |
7224 mch_didjmp(); | |
7225 xterm_dpy = NULL; | |
7226 } | |
7227 else | |
7228 #endif | |
7229 { | |
7230 xterm_dpy = XtOpenDisplay(app_context, xterm_display, | |
7231 "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); | |
7232 #if defined(HAVE_SETJMP_H) | |
7233 mch_endjmp(); | |
7234 #endif | |
7235 } | |
7236 | |
7237 #if defined(HAVE_SETJMP_H) | |
7238 /* Now handle X IO errors normally. */ | |
7239 (void)XSetIOErrorHandler(oldIOhandler); | |
7240 #endif | |
7241 /* Now handle X errors normally. */ | |
7242 (void)XSetErrorHandler(oldhandler); | |
7243 | |
7244 if (xterm_dpy == NULL) | |
7245 { | |
7246 if (p_verbose > 0) | |
292 | 7247 verb_msg((char_u *)_("Opening the X display failed")); |
7 | 7248 return; |
7249 } | |
7250 | |
7251 /* Catch terminating error of the X server connection. */ | |
7252 (void)XSetIOErrorHandler(x_IOerror_handler); | |
7253 | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7254 # ifdef ELAPSED_FUNC |
7 | 7255 if (p_verbose > 0) |
292 | 7256 { |
7257 verbose_enter(); | |
10406
42911b233245
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
7258 xopen_message(ELAPSED_FUNC(start_tv)); |
292 | 7259 verbose_leave(); |
7260 } | |
7 | 7261 # endif |
7262 | |
7263 /* Create a Shell to make converters work. */ | |
7264 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", | |
7265 applicationShellWidgetClass, xterm_dpy, | |
7266 NULL); | |
7267 if (AppShell == (Widget)0) | |
7268 return; | |
7269 xterm_Shell = XtVaCreatePopupShell("VIM", | |
7270 topLevelShellWidgetClass, AppShell, | |
7271 XtNmappedWhenManaged, 0, | |
7272 XtNwidth, 1, | |
7273 XtNheight, 1, | |
7274 NULL); | |
7275 if (xterm_Shell == (Widget)0) | |
7276 return; | |
7277 | |
7278 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
|
7279 x11_setup_selection(xterm_Shell); |
7 | 7280 if (x11_display == NULL) |
7281 x11_display = xterm_dpy; | |
7282 | |
7283 XtRealizeWidget(xterm_Shell); | |
7284 XSync(xterm_dpy, False); | |
7285 xterm_update(); | |
7286 } | |
7287 if (xterm_Shell != (Widget)0) | |
7288 { | |
7289 clip_init(TRUE); | |
7290 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) | |
7291 x11_window = (Window)atol(strp); | |
7292 /* Check if $WINDOWID is valid. */ | |
7293 if (test_x11_window(xterm_dpy) == FAIL) | |
7294 x11_window = 0; | |
7295 if (x11_window != 0) | |
7296 xterm_trace = 0; | |
7297 } | |
7298 } | |
7299 | |
7300 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7301 start_xterm_trace(int button) |
7 | 7302 { |
7303 if (x11_window == 0 || xterm_trace < 0 || xterm_Shell == (Widget)0) | |
7304 return; | |
7305 xterm_trace = 1; | |
7306 xterm_button = button; | |
7307 do_xterm_trace(); | |
7308 } | |
7309 | |
7310 | |
7311 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7312 stop_xterm_trace(void) |
7 | 7313 { |
7314 if (xterm_trace < 0) | |
7315 return; | |
7316 xterm_trace = 0; | |
7317 } | |
7318 | |
7319 /* | |
7320 * Query the xterm pointer and generate mouse termcodes if necessary | |
7321 * return TRUE if dragging is active, else FALSE | |
7322 */ | |
7323 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7324 do_xterm_trace(void) |
7 | 7325 { |
7326 Window root, child; | |
7327 int root_x, root_y; | |
7328 int win_x, win_y; | |
7329 int row, col; | |
7330 int_u mask_return; | |
7331 char_u buf[50]; | |
7332 char_u *strp; | |
7333 long got_hints; | |
7334 static char_u *mouse_code; | |
7335 static char_u mouse_name[2] = {KS_MOUSE, KE_FILLER}; | |
7336 static int prev_row = 0, prev_col = 0; | |
7337 static XSizeHints xterm_hints; | |
7338 | |
7339 if (xterm_trace <= 0) | |
7340 return FALSE; | |
7341 | |
7342 if (xterm_trace == 1) | |
7343 { | |
7344 /* Get the hints just before tracking starts. The font size might | |
1510 | 7345 * have changed recently. */ |
7346 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) | |
7347 || !(got_hints & PResizeInc) | |
7 | 7348 || xterm_hints.width_inc <= 1 |
7349 || xterm_hints.height_inc <= 1) | |
7350 { | |
7351 xterm_trace = -1; /* Not enough data -- disable tracing */ | |
7352 return FALSE; | |
7353 } | |
7354 | |
7355 /* Rely on the same mouse code for the duration of this */ | |
7356 mouse_code = find_termcode(mouse_name); | |
7357 prev_row = mouse_row; | |
7009 | 7358 prev_col = mouse_col; |
7 | 7359 xterm_trace = 2; |
7360 | |
7361 /* Find the offset of the chars, there might be a scrollbar on the | |
7362 * left of the window and/or a menu on the top (eterm etc.) */ | |
7363 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7364 &win_x, &win_y, &mask_return); | |
7365 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) | |
7366 - (xterm_hints.height_inc / 2); | |
7367 if (xterm_hints.y <= xterm_hints.height_inc / 2) | |
7368 xterm_hints.y = 2; | |
7369 xterm_hints.x = win_x - (xterm_hints.width_inc * mouse_col) | |
7370 - (xterm_hints.width_inc / 2); | |
7371 if (xterm_hints.x <= xterm_hints.width_inc / 2) | |
7372 xterm_hints.x = 2; | |
7373 return TRUE; | |
7374 } | |
2768 | 7375 if (mouse_code == NULL || STRLEN(mouse_code) > 45) |
7 | 7376 { |
7377 xterm_trace = 0; | |
7378 return FALSE; | |
7379 } | |
7380 | |
7381 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7382 &win_x, &win_y, &mask_return); | |
7383 | |
7384 row = check_row((win_y - xterm_hints.y) / xterm_hints.height_inc); | |
7385 col = check_col((win_x - xterm_hints.x) / xterm_hints.width_inc); | |
7386 if (row == prev_row && col == prev_col) | |
7387 return TRUE; | |
7388 | |
7389 STRCPY(buf, mouse_code); | |
7390 strp = buf + STRLEN(buf); | |
7391 *strp++ = (xterm_button | MOUSE_DRAG) & ~0x20; | |
7392 *strp++ = (char_u)(col + ' ' + 1); | |
7393 *strp++ = (char_u)(row + ' ' + 1); | |
7394 *strp = 0; | |
7395 add_to_input_buf(buf, STRLEN(buf)); | |
7396 | |
7397 prev_row = row; | |
7398 prev_col = col; | |
7399 return TRUE; | |
7400 } | |
7401 | |
7402 # if defined(FEAT_GUI) || defined(PROTO) | |
7403 /* | |
7404 * Destroy the display, window and app_context. Required for GTK. | |
7405 */ | |
7406 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7407 clear_xterm_clip(void) |
7 | 7408 { |
7409 if (xterm_Shell != (Widget)0) | |
7410 { | |
7411 XtDestroyWidget(xterm_Shell); | |
7412 xterm_Shell = (Widget)0; | |
7413 } | |
7414 if (xterm_dpy != NULL) | |
7415 { | |
1605 | 7416 # if 0 |
7 | 7417 /* Lesstif and Solaris crash here, lose some memory */ |
7418 XtCloseDisplay(xterm_dpy); | |
1605 | 7419 # endif |
7 | 7420 if (x11_display == xterm_dpy) |
7421 x11_display = NULL; | |
7422 xterm_dpy = NULL; | |
7423 } | |
1605 | 7424 # if 0 |
7 | 7425 if (app_context != (XtAppContext)NULL) |
7426 { | |
7427 /* Lesstif and Solaris crash here, lose some memory */ | |
7428 XtDestroyApplicationContext(app_context); | |
7429 app_context = (XtAppContext)NULL; | |
7430 } | |
1605 | 7431 # endif |
7 | 7432 } |
7433 # endif | |
7434 | |
7435 /* | |
4230 | 7436 * Catch up with GUI or X events. |
7437 */ | |
7438 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7439 clip_update(void) |
4230 | 7440 { |
7441 # ifdef FEAT_GUI | |
7442 if (gui.in_use) | |
7443 gui_mch_update(); | |
7444 else | |
7445 # endif | |
7446 if (xterm_Shell != (Widget)0) | |
7447 xterm_update(); | |
7448 } | |
7449 | |
7450 /* | |
7 | 7451 * Catch up with any queued X events. This may put keyboard input into the |
7452 * input buffer, call resize call-backs, trigger timers etc. If there is | |
7453 * nothing in the X event queue (& no timers pending), then we return | |
7454 * immediately. | |
7455 */ | |
7456 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7457 xterm_update(void) |
7 | 7458 { |
7459 XEvent event; | |
7460 | |
6683 | 7461 for (;;) |
7 | 7462 { |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7463 XtInputMask mask = XtAppPending(app_context); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7464 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7465 if (mask == 0 || vim_is_input_buf_full()) |
6683 | 7466 break; |
7467 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7468 if (mask & XtIMXEvent) |
7 | 7469 { |
6683 | 7470 /* 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
|
7471 XtAppNextEvent(app_context, &event); |
6683 | 7472 #ifdef FEAT_CLIENTSERVER |
7473 { | |
7474 XPropertyEvent *e = (XPropertyEvent *)&event; | |
7475 | |
7476 if (e->type == PropertyNotify && e->window == commWindow | |
7 | 7477 && 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
|
7478 serverEventProc(xterm_dpy, &event, 0); |
6683 | 7479 } |
7480 #endif | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7481 XtDispatchEvent(&event); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7482 } |
6683 | 7483 else |
7484 { | |
7485 /* 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
|
7486 XtAppProcessEvent(app_context, mask); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7487 } |
7 | 7488 } |
7489 } | |
7490 | |
7491 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7492 clip_xterm_own_selection(VimClipboard *cbd) |
7 | 7493 { |
7494 if (xterm_Shell != (Widget)0) | |
7495 return clip_x11_own_selection(xterm_Shell, cbd); | |
7496 return FAIL; | |
7497 } | |
7498 | |
7499 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7500 clip_xterm_lose_selection(VimClipboard *cbd) |
7 | 7501 { |
7502 if (xterm_Shell != (Widget)0) | |
7503 clip_x11_lose_selection(xterm_Shell, cbd); | |
7504 } | |
7505 | |
7506 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7507 clip_xterm_request_selection(VimClipboard *cbd) |
7 | 7508 { |
7509 if (xterm_Shell != (Widget)0) | |
7510 clip_x11_request_selection(xterm_Shell, xterm_dpy, cbd); | |
7511 } | |
7512 | |
7513 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7514 clip_xterm_set_selection(VimClipboard *cbd) |
7 | 7515 { |
7516 clip_x11_set_selection(cbd); | |
7517 } | |
7518 #endif | |
7519 | |
7520 | |
7521 #if defined(USE_XSMP) || defined(PROTO) | |
7522 /* | |
7523 * Code for X Session Management Protocol. | |
7524 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7525 static void xsmp_handle_save_yourself(SmcConn smc_conn, SmPointer client_data, int save_type, Bool shutdown, int interact_style, Bool fast); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7526 static void xsmp_die(SmcConn smc_conn, SmPointer client_data); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7527 static void xsmp_save_complete(SmcConn smc_conn, SmPointer client_data); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7528 static void xsmp_shutdown_cancelled(SmcConn smc_conn, SmPointer client_data); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7529 static void xsmp_ice_connection(IceConn iceConn, IcePointer clientData, Bool opening, IcePointer *watchData); |
7 | 7530 |
7531 | |
7532 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7533 static void xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data); |
7 | 7534 |
7535 /* | |
7536 * This is our chance to ask the user if they want to save, | |
7537 * or abort the logout | |
7538 */ | |
7539 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7540 xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data UNUSED) |
7 | 7541 { |
7542 cmdmod_T save_cmdmod; | |
7543 int cancel_shutdown = False; | |
7544 | |
7545 save_cmdmod = cmdmod; | |
7546 cmdmod.confirm = TRUE; | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7420
diff
changeset
|
7547 if (check_changed_any(FALSE, FALSE)) |
7 | 7548 /* Mustn't logout */ |
7549 cancel_shutdown = True; | |
7550 cmdmod = save_cmdmod; | |
7551 setcursor(); /* position cursor */ | |
7552 out_flush(); | |
7553 | |
7554 /* Done interaction */ | |
7555 SmcInteractDone(smc_conn, cancel_shutdown); | |
7556 | |
7557 /* Finish off | |
7558 * Only end save-yourself here if we're not cancelling shutdown; | |
7559 * we'll get a cancelled callback later in which we'll end it. | |
7560 * Hopefully get around glitchy SMs (like GNOME-1) | |
7561 */ | |
7562 if (!cancel_shutdown) | |
7563 { | |
7564 xsmp.save_yourself = False; | |
7565 SmcSaveYourselfDone(smc_conn, True); | |
7566 } | |
7567 } | |
7568 # endif | |
7569 | |
7570 /* | |
7571 * Callback that starts save-yourself. | |
7572 */ | |
7573 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7574 xsmp_handle_save_yourself( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7575 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7576 SmPointer client_data UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7577 int save_type UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7578 Bool shutdown, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7579 int interact_style UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7580 Bool fast UNUSED) |
7 | 7581 { |
7582 /* Handle already being in saveyourself */ | |
7583 if (xsmp.save_yourself) | |
7584 SmcSaveYourselfDone(smc_conn, True); | |
7585 xsmp.save_yourself = True; | |
7586 xsmp.shutdown = shutdown; | |
7587 | |
7588 /* First up, preserve all files */ | |
7589 out_flush(); | |
7590 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
7591 | |
7592 if (p_verbose > 0) | |
292 | 7593 verb_msg((char_u *)_("XSMP handling save-yourself request")); |
7 | 7594 |
7595 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7596 /* Now see if we can ask about unsaved files */ | |
7597 if (shutdown && !fast && gui.in_use) | |
7598 /* Need to interact with user, but need SM's permission */ | |
7599 SmcInteractRequest(smc_conn, SmDialogError, | |
7600 xsmp_handle_interaction, client_data); | |
7601 else | |
7602 # endif | |
7603 { | |
7604 /* Can stop the cycle here */ | |
7605 SmcSaveYourselfDone(smc_conn, True); | |
7606 xsmp.save_yourself = False; | |
7607 } | |
7608 } | |
7609 | |
7610 | |
7611 /* | |
7612 * Callback to warn us of imminent death. | |
7613 */ | |
7614 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7615 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED) |
7 | 7616 { |
7617 xsmp_close(); | |
7618 | |
7619 /* quit quickly leaving swapfiles for modified buffers behind */ | |
7620 getout_preserve_modified(0); | |
7621 } | |
7622 | |
7623 | |
7624 /* | |
7625 * Callback to tell us that save-yourself has completed. | |
7626 */ | |
7627 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7628 xsmp_save_complete( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7629 SmcConn smc_conn UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7630 SmPointer client_data UNUSED) |
7 | 7631 { |
7632 xsmp.save_yourself = False; | |
7633 } | |
7634 | |
7635 | |
7636 /* | |
7637 * Callback to tell us that an instigated shutdown was cancelled | |
7638 * (maybe even by us) | |
7639 */ | |
7640 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7641 xsmp_shutdown_cancelled( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7642 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7643 SmPointer client_data UNUSED) |
7 | 7644 { |
7645 if (xsmp.save_yourself) | |
7646 SmcSaveYourselfDone(smc_conn, True); | |
7647 xsmp.save_yourself = False; | |
7648 xsmp.shutdown = False; | |
7649 } | |
7650 | |
7651 | |
7652 /* | |
7653 * Callback to tell us that a new ICE connection has been established. | |
7654 */ | |
7655 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7656 xsmp_ice_connection( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7657 IceConn iceConn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7658 IcePointer clientData UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7659 Bool opening, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7660 IcePointer *watchData UNUSED) |
7 | 7661 { |
7662 /* Intercept creation of ICE connection fd */ | |
7663 if (opening) | |
7664 { | |
7665 xsmp_icefd = IceConnectionNumber(iceConn); | |
7666 IceRemoveConnectionWatch(xsmp_ice_connection, NULL); | |
7667 } | |
7668 } | |
7669 | |
7670 | |
7671 /* Handle any ICE processing that's required; return FAIL if SM lost */ | |
7672 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7673 xsmp_handle_requests(void) |
7 | 7674 { |
7675 Bool rep; | |
7676 | |
7677 if (IceProcessMessages(xsmp.iceconn, NULL, &rep) | |
7678 == IceProcessMessagesIOError) | |
7679 { | |
7680 /* Lost ICE */ | |
7681 if (p_verbose > 0) | |
292 | 7682 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 7683 xsmp_close(); |
7684 return FAIL; | |
7685 } | |
7686 else | |
7687 return OK; | |
7688 } | |
7689 | |
7690 static int dummy; | |
7691 | |
7692 /* Set up X Session Management Protocol */ | |
7693 void | |
7694 xsmp_init(void) | |
7695 { | |
7696 char errorstring[80]; | |
7697 SmcCallbacks smcallbacks; | |
7698 #if 0 | |
7699 SmPropValue smname; | |
7700 SmProp smnameprop; | |
7701 SmProp *smprops[1]; | |
7702 #endif | |
7703 | |
7704 if (p_verbose > 0) | |
292 | 7705 verb_msg((char_u *)_("XSMP opening connection")); |
7 | 7706 |
7707 xsmp.save_yourself = xsmp.shutdown = False; | |
7708 | |
7709 /* Set up SM callbacks - must have all, even if they're not used */ | |
7710 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; | |
7711 smcallbacks.save_yourself.client_data = NULL; | |
7712 smcallbacks.die.callback = xsmp_die; | |
7713 smcallbacks.die.client_data = NULL; | |
7714 smcallbacks.save_complete.callback = xsmp_save_complete; | |
7715 smcallbacks.save_complete.client_data = NULL; | |
7716 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; | |
7717 smcallbacks.shutdown_cancelled.client_data = NULL; | |
7718 | |
7719 /* Set up a watch on ICE connection creations. The "dummy" argument is | |
7720 * apparently required for FreeBSD (we get a BUS error when using NULL). */ | |
7721 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) | |
7722 { | |
7723 if (p_verbose > 0) | |
292 | 7724 verb_msg((char_u *)_("XSMP ICE connection watch failed")); |
7 | 7725 return; |
7726 } | |
7727 | |
7728 /* Create an SM connection */ | |
7729 xsmp.smcconn = SmcOpenConnection( | |
7730 NULL, | |
7731 NULL, | |
7732 SmProtoMajor, | |
7733 SmProtoMinor, | |
7734 SmcSaveYourselfProcMask | SmcDieProcMask | |
7735 | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
7736 &smcallbacks, | |
7737 NULL, | |
1605 | 7738 &xsmp.clientid, |
7 | 7739 sizeof(errorstring), |
7740 errorstring); | |
7741 if (xsmp.smcconn == NULL) | |
7742 { | |
7743 char errorreport[132]; | |
273 | 7744 |
292 | 7745 if (p_verbose > 0) |
7746 { | |
7747 vim_snprintf(errorreport, sizeof(errorreport), | |
273 | 7748 _("XSMP SmcOpenConnection failed: %s"), errorstring); |
292 | 7749 verb_msg((char_u *)errorreport); |
7750 } | |
7 | 7751 return; |
7752 } | |
7753 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); | |
7754 | |
7755 #if 0 | |
7756 /* ID ourselves */ | |
7757 smname.value = "vim"; | |
7758 smname.length = 3; | |
7759 smnameprop.name = "SmProgram"; | |
7760 smnameprop.type = "SmARRAY8"; | |
7761 smnameprop.num_vals = 1; | |
7762 smnameprop.vals = &smname; | |
7763 | |
7764 smprops[0] = &smnameprop; | |
7765 SmcSetProperties(xsmp.smcconn, 1, smprops); | |
7766 #endif | |
7767 } | |
7768 | |
7769 | |
7770 /* Shut down XSMP comms. */ | |
7771 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7772 xsmp_close(void) |
7 | 7773 { |
7774 if (xsmp_icefd != -1) | |
7775 { | |
7776 SmcCloseConnection(xsmp.smcconn, 0, NULL); | |
1737 | 7777 if (xsmp.clientid != NULL) |
7778 free(xsmp.clientid); | |
1605 | 7779 xsmp.clientid = NULL; |
7 | 7780 xsmp_icefd = -1; |
7781 } | |
7782 } | |
7783 #endif /* USE_XSMP */ | |
7784 | |
7785 | |
7786 #ifdef EBCDIC | |
7787 /* Translate character to its CTRL- value */ | |
7788 char CtrlTable[] = | |
7789 { | |
7790 /* 00 - 5E */ | |
7791 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7792 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7793 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7794 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7795 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7796 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7797 /* ^ */ 0x1E, | |
7798 /* - */ 0x1F, | |
7799 /* 61 - 6C */ | |
7800 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7801 /* _ */ 0x1F, | |
7802 /* 6E - 80 */ | |
7803 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7804 /* a */ 0x01, | |
7805 /* b */ 0x02, | |
7806 /* c */ 0x03, | |
7807 /* d */ 0x37, | |
7808 /* e */ 0x2D, | |
7809 /* f */ 0x2E, | |
7810 /* g */ 0x2F, | |
7811 /* h */ 0x16, | |
7812 /* i */ 0x05, | |
7813 /* 8A - 90 */ | |
7814 0, 0, 0, 0, 0, 0, 0, | |
7815 /* j */ 0x15, | |
7816 /* k */ 0x0B, | |
7817 /* l */ 0x0C, | |
7818 /* m */ 0x0D, | |
7819 /* n */ 0x0E, | |
7820 /* o */ 0x0F, | |
7821 /* p */ 0x10, | |
7822 /* q */ 0x11, | |
7823 /* r */ 0x12, | |
7824 /* 9A - A1 */ | |
7825 0, 0, 0, 0, 0, 0, 0, 0, | |
7826 /* s */ 0x13, | |
7827 /* t */ 0x3C, | |
7828 /* u */ 0x3D, | |
7829 /* v */ 0x32, | |
7830 /* w */ 0x26, | |
7831 /* x */ 0x18, | |
7832 /* y */ 0x19, | |
7833 /* z */ 0x3F, | |
7834 /* AA - AC */ | |
7835 0, 0, 0, | |
7836 /* [ */ 0x27, | |
7837 /* AE - BC */ | |
7838 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7839 /* ] */ 0x1D, | |
7840 /* BE - C0 */ 0, 0, 0, | |
7841 /* A */ 0x01, | |
7842 /* B */ 0x02, | |
7843 /* C */ 0x03, | |
7844 /* D */ 0x37, | |
7845 /* E */ 0x2D, | |
7846 /* F */ 0x2E, | |
7847 /* G */ 0x2F, | |
7848 /* H */ 0x16, | |
7849 /* I */ 0x05, | |
7850 /* CA - D0 */ 0, 0, 0, 0, 0, 0, 0, | |
7851 /* J */ 0x15, | |
7852 /* K */ 0x0B, | |
7853 /* L */ 0x0C, | |
7854 /* M */ 0x0D, | |
7855 /* N */ 0x0E, | |
7856 /* O */ 0x0F, | |
7857 /* P */ 0x10, | |
7858 /* Q */ 0x11, | |
7859 /* R */ 0x12, | |
7860 /* DA - DF */ 0, 0, 0, 0, 0, 0, | |
7861 /* \ */ 0x1C, | |
7862 /* E1 */ 0, | |
7863 /* S */ 0x13, | |
7864 /* T */ 0x3C, | |
7865 /* U */ 0x3D, | |
7866 /* V */ 0x32, | |
7867 /* W */ 0x26, | |
7868 /* X */ 0x18, | |
7869 /* Y */ 0x19, | |
7870 /* Z */ 0x3F, | |
7871 /* EA - FF*/ 0, 0, 0, 0, 0, 0, | |
7872 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7873 }; | |
7874 | |
7875 char MetaCharTable[]= | |
7876 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
7877 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, | |
7878 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, | |
7879 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, | |
7880 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0 | |
7881 }; | |
7882 | |
7883 | |
7884 /* TODO: Use characters NOT numbers!!! */ | |
7885 char CtrlCharTable[]= | |
7886 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
7887 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, | |
7888 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, | |
7889 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, | |
7890 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233, | |
7891 }; | |
7892 | |
7893 | |
7894 #endif |