Mercurial > vim
annotate src/os_unix.c @ 8956:d9e671c5afe6 v7.4.1763
commit https://github.com/vim/vim/commit/ba53435144f46eaaa53c63a62e748b3feee9742c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 21 09:20:26 2016 +0200
patch 7.4.1763
Problem: Coverity: useless assignment.
Solution: Add #if 0.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 21 Apr 2016 09:30:06 +0200 |
parents | c07caeb90a35 |
children | 12392eb2923a |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
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 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
178 static int WaitForChar(long); |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
179 static int WaitForCharOrMouse(long, int *break_loop); |
5541 | 180 #if defined(__BEOS__) || defined(VMS) |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
181 int RealWaitForChar(int, long, int *, int *break_loop); |
7 | 182 #else |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
183 static int RealWaitForChar(int, long, int *, int *break_loop); |
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)()); |
7 | 214 #ifndef __EMX__ |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
215 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
|
216 static int have_dollars(int, char_u **); |
7 | 217 #endif |
218 | |
219 #ifndef __EMX__ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
220 static int save_patterns(int num_pat, char_u **pat, int *num_file, char_u ***file); |
7 | 221 #endif |
222 | |
223 #ifndef SIG_ERR | |
1879 | 224 # define SIG_ERR ((RETSIGTYPE (*)())-1) |
7 | 225 #endif |
226 | |
1832 | 227 /* volatile because it is used in signal handler sig_winch(). */ |
228 static volatile int do_resize = FALSE; | |
7 | 229 #ifndef __EMX__ |
230 static char_u *extra_shell_arg = NULL; | |
231 static int show_shell_mess = TRUE; | |
232 #endif | |
1832 | 233 /* volatile because it is used in signal handler deathtrap(). */ |
234 static volatile int deadly_signal = 0; /* The signal we caught */ | |
235 /* volatile because it is used in signal handler deathtrap(). */ | |
236 static volatile int in_mch_delay = FALSE; /* sleeping in mch_delay() */ | |
7 | 237 |
238 static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ | |
239 | |
240 #ifdef USE_XSMP | |
241 typedef struct | |
242 { | |
243 SmcConn smcconn; /* The SM connection ID */ | |
244 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
|
245 char *clientid; /* The client ID for the current smc session */ |
7 | 246 Bool save_yourself; /* If we're in the middle of a save_yourself */ |
247 Bool shutdown; /* If we're in shutdown mode */ | |
248 } xsmp_config_T; | |
249 | |
250 static xsmp_config_T xsmp; | |
251 #endif | |
252 | |
253 #ifdef SYS_SIGLIST_DECLARED | |
254 /* | |
255 * I have seen | |
256 * extern char *_sys_siglist[NSIG]; | |
257 * on Irix, Linux, NetBSD and Solaris. It contains a nice list of strings | |
258 * that describe the signals. That is nearly what we want here. But | |
259 * autoconf does only check for sys_siglist (without the underscore), I | |
260 * do not want to change everything today.... jw. | |
261 * This is why AC_DECL_SYS_SIGLIST is commented out in configure.in | |
262 */ | |
263 #endif | |
264 | |
265 static struct signalinfo | |
266 { | |
267 int sig; /* Signal number, eg. SIGSEGV etc */ | |
268 char *name; /* Signal name (not char_u!). */ | |
269 char deadly; /* Catch as a deadly signal? */ | |
270 } signal_info[] = | |
271 { | |
272 #ifdef SIGHUP | |
273 {SIGHUP, "HUP", TRUE}, | |
274 #endif | |
275 #ifdef SIGQUIT | |
276 {SIGQUIT, "QUIT", TRUE}, | |
277 #endif | |
278 #ifdef SIGILL | |
279 {SIGILL, "ILL", TRUE}, | |
280 #endif | |
281 #ifdef SIGTRAP | |
282 {SIGTRAP, "TRAP", TRUE}, | |
283 #endif | |
284 #ifdef SIGABRT | |
285 {SIGABRT, "ABRT", TRUE}, | |
286 #endif | |
287 #ifdef SIGEMT | |
288 {SIGEMT, "EMT", TRUE}, | |
289 #endif | |
290 #ifdef SIGFPE | |
291 {SIGFPE, "FPE", TRUE}, | |
292 #endif | |
293 #ifdef SIGBUS | |
294 {SIGBUS, "BUS", TRUE}, | |
295 #endif | |
4074 | 296 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) |
297 /* MzScheme uses SEGV in its garbage collector */ | |
7 | 298 {SIGSEGV, "SEGV", TRUE}, |
299 #endif | |
300 #ifdef SIGSYS | |
301 {SIGSYS, "SYS", TRUE}, | |
302 #endif | |
303 #ifdef SIGALRM | |
304 {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ | |
305 #endif | |
306 #ifdef SIGTERM | |
307 {SIGTERM, "TERM", TRUE}, | |
308 #endif | |
2701 | 309 #if defined(SIGVTALRM) && !defined(FEAT_RUBY) |
7 | 310 {SIGVTALRM, "VTALRM", TRUE}, |
311 #endif | |
1560 | 312 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) |
313 /* MzScheme uses SIGPROF for its own needs; On Linux with profiling | |
314 * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ | |
7 | 315 {SIGPROF, "PROF", TRUE}, |
316 #endif | |
317 #ifdef SIGXCPU | |
318 {SIGXCPU, "XCPU", TRUE}, | |
319 #endif | |
320 #ifdef SIGXFSZ | |
321 {SIGXFSZ, "XFSZ", TRUE}, | |
322 #endif | |
323 #ifdef SIGUSR1 | |
324 {SIGUSR1, "USR1", TRUE}, | |
325 #endif | |
1620 | 326 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) |
327 /* Used for sysmouse handling */ | |
7 | 328 {SIGUSR2, "USR2", TRUE}, |
329 #endif | |
330 #ifdef SIGINT | |
331 {SIGINT, "INT", FALSE}, | |
332 #endif | |
333 #ifdef SIGWINCH | |
334 {SIGWINCH, "WINCH", FALSE}, | |
335 #endif | |
336 #ifdef SIGTSTP | |
337 {SIGTSTP, "TSTP", FALSE}, | |
338 #endif | |
339 #ifdef SIGPIPE | |
340 {SIGPIPE, "PIPE", FALSE}, | |
341 #endif | |
342 {-1, "Unknown!", FALSE} | |
343 }; | |
344 | |
1935 | 345 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
346 mch_chdir(char *path) |
1935 | 347 { |
348 if (p_verbose >= 5) | |
349 { | |
350 verbose_enter(); | |
351 smsg((char_u *)"chdir(%s)", path); | |
352 verbose_leave(); | |
353 } | |
354 # ifdef VMS | |
355 return chdir(vms_fixfilename(path)); | |
356 # else | |
357 return chdir(path); | |
358 # endif | |
359 } | |
360 | |
1757 | 361 /* |
362 * Write s[len] to the screen. | |
363 */ | |
7 | 364 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
365 mch_write(char_u *s, int len) |
7 | 366 { |
1757 | 367 ignored = (int)write(1, (char *)s, len); |
7 | 368 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
|
369 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); |
7 | 370 } |
371 | |
372 /* | |
1450 | 373 * mch_inchar(): low level input function. |
7 | 374 * Get a characters from the keyboard. |
375 * Return the number of characters that are available. | |
376 * If wtime == 0 do not wait for characters. | |
377 * If wtime == n wait a short time for characters. | |
378 * If wtime == -1 wait forever for characters. | |
379 */ | |
380 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
381 mch_inchar( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
382 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
383 int maxlen, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
384 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
|
385 int tb_change_cnt) |
7 | 386 { |
387 int len; | |
388 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
389 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
390 parse_queued_messages(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
391 #endif |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
392 |
7 | 393 /* Check if window changed size while we were busy, perhaps the ":set |
394 * columns=99" command was used. */ | |
395 while (do_resize) | |
396 handle_resize(); | |
397 | |
398 if (wtime >= 0) | |
399 { | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
400 while (!WaitForChar(wtime)) /* no character available */ |
7 | 401 { |
7239
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
402 if (do_resize) |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
403 handle_resize(); |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
404 #ifdef FEAT_CLIENTSERVER |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
405 else if (!server_waiting()) |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
406 #else |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
407 else |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
408 #endif |
89c6f7c6704a
commit https://github.com/vim/vim/commit/5d8afebb5bf7fb1e8ce06062451dc6a1f9a53ac0
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
409 /* return if not interrupted by resize or server */ |
7 | 410 return 0; |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
411 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
412 parse_queued_messages(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
413 #endif |
7 | 414 } |
415 } | |
416 else /* wtime == -1 */ | |
417 { | |
418 /* | |
419 * If there is no character available within 'updatetime' seconds | |
216 | 420 * flush all the swap files to disk. |
7 | 421 * Also done when interrupted by SIGWINCH. |
422 */ | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
423 if (!WaitForChar(p_ut)) |
7 | 424 { |
425 #ifdef FEAT_AUTOCMD | |
609 | 426 if (trigger_cursorhold() && maxlen >= 3 |
427 && !typebuf_changed(tb_change_cnt)) | |
7 | 428 { |
216 | 429 buf[0] = K_SPECIAL; |
430 buf[1] = KS_EXTRA; | |
431 buf[2] = (int)KE_CURSORHOLD; | |
432 return 3; | |
7 | 433 } |
216 | 434 #endif |
369 | 435 before_blocking(); |
7 | 436 } |
437 } | |
438 | |
439 for (;;) /* repeat until we got a character */ | |
440 { | |
441 while (do_resize) /* window changed size */ | |
442 handle_resize(); | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
443 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
444 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
445 parse_queued_messages(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
446 #endif |
7 | 447 /* |
2436 | 448 * We want to be interrupted by the winch signal |
449 * or by an event on the monitored file descriptors. | |
7 | 450 */ |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
451 if (!WaitForChar(-1L)) |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
452 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
453 if (do_resize) /* interrupted by SIGWINCH signal */ |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
454 handle_resize(); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
455 return 0; |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2074
diff
changeset
|
456 } |
7 | 457 |
458 /* If input was put directly in typeahead buffer bail out here. */ | |
459 if (typebuf_changed(tb_change_cnt)) | |
460 return 0; | |
461 | |
462 /* | |
463 * For some terminals we only get one character at a time. | |
464 * We want the get all available characters, so we could keep on | |
465 * trying until none is available | |
466 * For some other terminals this is quite slow, that's why we don't do | |
467 * it. | |
468 */ | |
469 len = read_from_input_buf(buf, (long)maxlen); | |
470 if (len > 0) | |
471 { | |
472 return len; | |
473 } | |
474 } | |
475 } | |
476 | |
477 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
478 handle_resize(void) |
7 | 479 { |
480 do_resize = FALSE; | |
481 shell_resized(); | |
482 } | |
483 | |
484 /* | |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
485 * Return non-zero if a character is available. |
7 | 486 */ |
487 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
488 mch_char_avail(void) |
7 | 489 { |
490 return WaitForChar(0L); | |
491 } | |
492 | |
493 #if defined(HAVE_TOTAL_MEM) || defined(PROTO) | |
494 # ifdef HAVE_SYS_RESOURCE_H | |
1879 | 495 # include <sys/resource.h> |
7 | 496 # endif |
497 # if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTL) | |
498 # include <sys/sysctl.h> | |
499 # endif | |
500 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) | |
501 # include <sys/sysinfo.h> | |
502 # endif | |
503 | |
504 /* | |
1110 | 505 * Return total amount of memory available in Kbyte. |
506 * Doesn't change when memory has been allocated. | |
7 | 507 */ |
508 long_u | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
509 mch_total_mem(int special UNUSED) |
7 | 510 { |
511 # ifdef __EMX__ | |
1110 | 512 return ulimit(3, 0L) >> 10; /* always 32MB? */ |
7 | 513 # else |
514 long_u mem = 0; | |
1110 | 515 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ |
7 | 516 |
517 # ifdef HAVE_SYSCTL | |
518 int mib[2], physmem; | |
519 size_t len; | |
520 | |
521 /* BSD way of getting the amount of RAM available. */ | |
522 mib[0] = CTL_HW; | |
523 mib[1] = HW_USERMEM; | |
524 len = sizeof(physmem); | |
525 if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0) | |
526 mem = (long_u)physmem; | |
527 # endif | |
528 | |
529 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) | |
530 if (mem == 0) | |
531 { | |
532 struct sysinfo sinfo; | |
533 | |
534 /* Linux way of getting amount of RAM available */ | |
535 if (sysinfo(&sinfo) == 0) | |
1110 | 536 { |
537 # ifdef HAVE_SYSINFO_MEM_UNIT | |
538 /* avoid overflow as much as possible */ | |
539 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) | |
540 { | |
541 sinfo.mem_unit = sinfo.mem_unit >> 1; | |
542 --shiftright; | |
543 } | |
544 mem = sinfo.totalram * sinfo.mem_unit; | |
545 # else | |
7 | 546 mem = sinfo.totalram; |
1110 | 547 # endif |
548 } | |
7 | 549 } |
550 # endif | |
551 | |
552 # ifdef HAVE_SYSCONF | |
553 if (mem == 0) | |
554 { | |
555 long pagesize, pagecount; | |
556 | |
557 /* Solaris way of getting amount of RAM available */ | |
558 pagesize = sysconf(_SC_PAGESIZE); | |
559 pagecount = sysconf(_SC_PHYS_PAGES); | |
560 if (pagesize > 0 && pagecount > 0) | |
1110 | 561 { |
562 /* avoid overflow as much as possible */ | |
563 while (shiftright > 0 && (pagesize & 1) == 0) | |
564 { | |
1204 | 565 pagesize = (long_u)pagesize >> 1; |
1110 | 566 --shiftright; |
567 } | |
7 | 568 mem = (long_u)pagesize * pagecount; |
1110 | 569 } |
7 | 570 } |
571 # endif | |
572 | |
573 /* Return the minimum of the physical memory and the user limit, because | |
574 * using more than the user limit may cause Vim to be terminated. */ | |
575 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) | |
576 { | |
577 struct rlimit rlp; | |
578 | |
579 if (getrlimit(RLIMIT_DATA, &rlp) == 0 | |
580 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
581 # ifdef RLIM_INFINITY | |
582 && rlp.rlim_cur != RLIM_INFINITY | |
583 # endif | |
1110 | 584 && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright) |
7 | 585 ) |
1110 | 586 { |
587 mem = (long_u)rlp.rlim_cur; | |
588 shiftright = 10; | |
589 } | |
7 | 590 } |
591 # endif | |
592 | |
593 if (mem > 0) | |
1110 | 594 return mem >> shiftright; |
595 return (long_u)0x1fffff; | |
7 | 596 # endif |
597 } | |
598 #endif | |
599 | |
600 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
601 mch_delay(long msec, int ignoreinput) |
7 | 602 { |
603 int old_tmode; | |
14 | 604 #ifdef FEAT_MZSCHEME |
605 long total = msec; /* remember original value */ | |
606 #endif | |
7 | 607 |
608 if (ignoreinput) | |
609 { | |
610 /* Go to cooked mode without echo, to allow SIGINT interrupting us | |
1530 | 611 * here. But we don't want QUIT to kill us (CTRL-\ used in a |
612 * shell may produce SIGQUIT). */ | |
613 in_mch_delay = TRUE; | |
7 | 614 old_tmode = curr_tmode; |
615 if (curr_tmode == TMODE_RAW) | |
616 settmode(TMODE_SLEEP); | |
617 | |
618 /* | |
619 * Everybody sleeps in a different way... | |
620 * Prefer nanosleep(), some versions of usleep() can only sleep up to | |
621 * one second. | |
622 */ | |
14 | 623 #ifdef FEAT_MZSCHEME |
624 do | |
625 { | |
626 /* if total is large enough, wait by portions in p_mzq */ | |
627 if (total > p_mzq) | |
628 msec = p_mzq; | |
629 else | |
630 msec = total; | |
631 total -= msec; | |
632 #endif | |
7 | 633 #ifdef HAVE_NANOSLEEP |
634 { | |
635 struct timespec ts; | |
636 | |
637 ts.tv_sec = msec / 1000; | |
638 ts.tv_nsec = (msec % 1000) * 1000000; | |
639 (void)nanosleep(&ts, NULL); | |
640 } | |
641 #else | |
642 # ifdef HAVE_USLEEP | |
643 while (msec >= 1000) | |
644 { | |
645 usleep((unsigned int)(999 * 1000)); | |
646 msec -= 999; | |
647 } | |
648 usleep((unsigned int)(msec * 1000)); | |
649 # else | |
650 # ifndef HAVE_SELECT | |
651 poll(NULL, 0, (int)msec); | |
652 # else | |
653 # ifdef __EMX__ | |
654 _sleep2(msec); | |
655 # else | |
656 { | |
657 struct timeval tv; | |
658 | |
659 tv.tv_sec = msec / 1000; | |
660 tv.tv_usec = (msec % 1000) * 1000; | |
661 /* | |
662 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get | |
663 * a patch from Sun to fix this. Reported by Gunnar Pedersen. | |
664 */ | |
665 select(0, NULL, NULL, NULL, &tv); | |
666 } | |
667 # endif /* __EMX__ */ | |
668 # endif /* HAVE_SELECT */ | |
669 # endif /* HAVE_NANOSLEEP */ | |
670 #endif /* HAVE_USLEEP */ | |
14 | 671 #ifdef FEAT_MZSCHEME |
672 } | |
673 while (total > 0); | |
674 #endif | |
7 | 675 |
676 settmode(old_tmode); | |
1530 | 677 in_mch_delay = FALSE; |
7 | 678 } |
679 else | |
680 WaitForChar(msec); | |
681 } | |
682 | |
180 | 683 #if defined(HAVE_STACK_LIMIT) \ |
7 | 684 || (!defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGSTACK)) |
685 # define HAVE_CHECK_STACK_GROWTH | |
686 /* | |
687 * Support for checking for an almost-out-of-stack-space situation. | |
688 */ | |
689 | |
690 /* | |
691 * Return a pointer to an item on the stack. Used to find out if the stack | |
692 * grows up or down. | |
693 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
694 static void check_stack_growth(char *p); |
7 | 695 static int stack_grows_downwards; |
696 | |
697 /* | |
698 * Find out if the stack grows upwards or downwards. | |
699 * "p" points to a variable on the stack of the caller. | |
700 */ | |
701 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
702 check_stack_growth(char *p) |
7 | 703 { |
704 int i; | |
705 | |
706 stack_grows_downwards = (p > (char *)&i); | |
707 } | |
708 #endif | |
709 | |
180 | 710 #if defined(HAVE_STACK_LIMIT) || defined(PROTO) |
7 | 711 static char *stack_limit = NULL; |
712 | |
713 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
714 # include <pthread.h> | |
715 # include <pthread_np.h> | |
716 #endif | |
717 | |
718 /* | |
719 * Find out until how var the stack can grow without getting into trouble. | |
720 * Called when starting up and when switching to the signal stack in | |
721 * deathtrap(). | |
722 */ | |
723 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
724 get_stack_limit(void) |
7 | 725 { |
726 struct rlimit rlp; | |
727 int i; | |
728 long lim; | |
729 | |
730 /* Set the stack limit to 15/16 of the allowable size. Skip this when the | |
731 * limit doesn't fit in a long (rlim_cur might be "long long"). */ | |
732 if (getrlimit(RLIMIT_STACK, &rlp) == 0 | |
733 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) | |
734 # ifdef RLIM_INFINITY | |
735 && rlp.rlim_cur != RLIM_INFINITY | |
736 # endif | |
737 ) | |
738 { | |
739 lim = (long)rlp.rlim_cur; | |
740 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) | |
741 { | |
742 pthread_attr_t attr; | |
743 size_t size; | |
744 | |
745 /* On FreeBSD the initial thread always has a fixed stack size, no | |
746 * matter what the limits are set to. Normally it's 1 Mbyte. */ | |
747 pthread_attr_init(&attr); | |
748 if (pthread_attr_get_np(pthread_self(), &attr) == 0) | |
749 { | |
750 pthread_attr_getstacksize(&attr, &size); | |
751 if (lim > (long)size) | |
752 lim = (long)size; | |
753 } | |
754 pthread_attr_destroy(&attr); | |
755 } | |
756 #endif | |
757 if (stack_grows_downwards) | |
758 { | |
759 stack_limit = (char *)((long)&i - (lim / 16L * 15L)); | |
760 if (stack_limit >= (char *)&i) | |
761 /* overflow, set to 1/16 of current stack position */ | |
762 stack_limit = (char *)((long)&i / 16L); | |
763 } | |
764 else | |
765 { | |
766 stack_limit = (char *)((long)&i + (lim / 16L * 15L)); | |
767 if (stack_limit <= (char *)&i) | |
768 stack_limit = NULL; /* overflow */ | |
769 } | |
770 } | |
771 } | |
772 | |
773 /* | |
774 * Return FAIL when running out of stack space. | |
775 * "p" must point to any variable local to the caller that's on the stack. | |
776 */ | |
777 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
778 mch_stackcheck(char *p) |
7 | 779 { |
780 if (stack_limit != NULL) | |
781 { | |
782 if (stack_grows_downwards) | |
783 { | |
784 if (p < stack_limit) | |
785 return FAIL; | |
786 } | |
787 else if (p > stack_limit) | |
788 return FAIL; | |
789 } | |
790 return OK; | |
791 } | |
792 #endif | |
793 | |
794 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
795 /* | |
796 * Support for using the signal stack. | |
797 * This helps when we run out of stack space, which causes a SIGSEGV. The | |
798 * signal handler then must run on another stack, since the normal stack is | |
799 * completely full. | |
800 */ | |
801 | |
5421 | 802 #if defined(HAVE_AVAILABILITYMACROS_H) |
5411 | 803 # include <AvailabilityMacros.h> |
804 #endif | |
805 | |
7 | 806 #ifndef SIGSTKSZ |
807 # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ | |
808 #endif | |
809 | |
810 # ifdef HAVE_SIGALTSTACK | |
811 static stack_t sigstk; /* for sigaltstack() */ | |
812 # else | |
813 static struct sigstack sigstk; /* for sigstack() */ | |
814 # endif | |
815 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
816 static void init_signal_stack(void); |
7 | 817 static char *signal_stack; |
818 | |
819 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
820 init_signal_stack(void) |
7 | 821 { |
822 if (signal_stack != NULL) | |
823 { | |
824 # ifdef HAVE_SIGALTSTACK | |
1375 | 825 # if defined(__APPLE__) && (!defined(MAC_OS_X_VERSION_MAX_ALLOWED) \ |
826 || MAC_OS_X_VERSION_MAX_ALLOWED <= 1040) | |
7 | 827 /* missing prototype. Adding it to osdef?.h.in doesn't work, because |
828 * "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
|
829 extern int sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss); |
7 | 830 # endif |
831 | |
832 # ifdef HAVE_SS_BASE | |
833 sigstk.ss_base = signal_stack; | |
834 # else | |
835 sigstk.ss_sp = signal_stack; | |
836 # endif | |
837 sigstk.ss_size = SIGSTKSZ; | |
838 sigstk.ss_flags = 0; | |
839 (void)sigaltstack(&sigstk, NULL); | |
840 # else | |
841 sigstk.ss_sp = signal_stack; | |
842 if (stack_grows_downwards) | |
843 sigstk.ss_sp += SIGSTKSZ - 1; | |
844 sigstk.ss_onstack = 0; | |
845 (void)sigstack(&sigstk, NULL); | |
846 # endif | |
847 } | |
848 } | |
849 #endif | |
850 | |
851 /* | |
1832 | 852 * We need correct prototypes for a signal function, otherwise mean compilers |
7 | 853 * will barf when the second argument to signal() is ``wrong''. |
854 * Let me try it with a few tricky defines from my own osdef.h (jw). | |
855 */ | |
856 #if defined(SIGWINCH) | |
857 static RETSIGTYPE | |
858 sig_winch SIGDEFARG(sigarg) | |
859 { | |
860 /* this is not required on all systems, but it doesn't hurt anybody */ | |
861 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
862 do_resize = TRUE; | |
863 SIGRETURN; | |
864 } | |
865 #endif | |
866 | |
867 #if defined(SIGINT) | |
868 static RETSIGTYPE | |
869 catch_sigint SIGDEFARG(sigarg) | |
870 { | |
871 /* this is not required on all systems, but it doesn't hurt anybody */ | |
872 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
873 got_int = TRUE; | |
874 SIGRETURN; | |
875 } | |
876 #endif | |
877 | |
878 #if defined(SIGPWR) | |
879 static RETSIGTYPE | |
880 catch_sigpwr SIGDEFARG(sigarg) | |
881 { | |
37 | 882 /* this is not required on all systems, but it doesn't hurt anybody */ |
883 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
7 | 884 /* |
885 * I'm not sure we get the SIGPWR signal when the system is really going | |
886 * down or when the batteries are almost empty. Just preserve the swap | |
887 * files and don't exit, that can't do any harm. | |
888 */ | |
889 ml_sync_all(FALSE, FALSE); | |
890 SIGRETURN; | |
891 } | |
892 #endif | |
893 | |
894 #ifdef SET_SIG_ALARM | |
895 /* | |
896 * signal function for alarm(). | |
897 */ | |
898 static RETSIGTYPE | |
899 sig_alarm SIGDEFARG(sigarg) | |
900 { | |
901 /* doesn't do anything, just to break a system call */ | |
902 sig_alarm_called = TRUE; | |
903 SIGRETURN; | |
904 } | |
905 #endif | |
906 | |
188 | 907 #if (defined(HAVE_SETJMP_H) \ |
908 && ((defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) \ | |
909 || defined(FEAT_LIBCALL))) \ | |
910 || defined(PROTO) | |
7 | 911 /* |
912 * A simplistic version of setjmp() that only allows one level of using. | |
913 * Don't call twice before calling mch_endjmp()!. | |
914 * Usage: | |
915 * mch_startjmp(); | |
916 * if (SETJMP(lc_jump_env) != 0) | |
917 * { | |
918 * mch_didjmp(); | |
919 * EMSG("crash!"); | |
920 * } | |
921 * else | |
922 * { | |
923 * do_the_work; | |
924 * mch_endjmp(); | |
925 * } | |
926 * Note: Can't move SETJMP() here, because a function calling setjmp() must | |
927 * not return before the saved environment is used. | |
928 * Returns OK for normal return, FAIL when the protected code caused a | |
929 * problem and LONGJMP() was used. | |
930 */ | |
931 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
932 mch_startjmp(void) |
7 | 933 { |
934 #ifdef SIGHASARG | |
935 lc_signal = 0; | |
936 #endif | |
937 lc_active = TRUE; | |
938 } | |
939 | |
940 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
941 mch_endjmp(void) |
7 | 942 { |
943 lc_active = FALSE; | |
944 } | |
945 | |
946 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
947 mch_didjmp(void) |
7 | 948 { |
949 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
950 /* On FreeBSD the signal stack has to be reset after using siglongjmp(), | |
951 * otherwise catching the signal only works once. */ | |
952 init_signal_stack(); | |
953 # endif | |
954 } | |
955 #endif | |
956 | |
957 /* | |
958 * This function handles deadly signals. | |
5338 | 959 * It tries to preserve any swap files and exit properly. |
7 | 960 * (partly from Elvis). |
5338 | 961 * NOTE: Avoid unsafe functions, such as allocating memory, they can result in |
962 * a deadlock. | |
7 | 963 */ |
964 static RETSIGTYPE | |
965 deathtrap SIGDEFARG(sigarg) | |
966 { | |
967 static int entered = 0; /* count the number of times we got here. | |
968 Note: when memory has been corrupted | |
969 this may get an arbitrary value! */ | |
970 #ifdef SIGHASARG | |
971 int i; | |
972 #endif | |
973 | |
974 #if defined(HAVE_SETJMP_H) | |
975 /* | |
976 * Catch a crash in protected code. | |
977 * Restores the environment saved in lc_jump_env, which looks like | |
978 * SETJMP() returns 1. | |
979 */ | |
980 if (lc_active) | |
981 { | |
982 # if defined(SIGHASARG) | |
983 lc_signal = sigarg; | |
984 # endif | |
985 lc_active = FALSE; /* don't jump again */ | |
986 LONGJMP(lc_jump_env, 1); | |
987 /* NOTREACHED */ | |
988 } | |
989 #endif | |
990 | |
36 | 991 #ifdef SIGHASARG |
1530 | 992 # ifdef SIGQUIT |
993 /* While in mch_delay() we go to cooked mode to allow a CTRL-C to | |
994 * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when | |
995 * pressing CTRL-\, but we don't want Vim to exit then. */ | |
996 if (in_mch_delay && sigarg == SIGQUIT) | |
997 SIGRETURN; | |
998 # endif | |
999 | |
37 | 1000 /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return |
1001 * here. This avoids that a non-reentrant function is interrupted, e.g., | |
1002 * free(). Calling free() again may then cause a crash. */ | |
1003 if (entered == 0 | |
1004 && (0 | |
1005 # ifdef SIGHUP | |
1006 || sigarg == SIGHUP | |
1007 # endif | |
1008 # ifdef SIGQUIT | |
1009 || sigarg == SIGQUIT | |
1010 # endif | |
1011 # ifdef SIGTERM | |
1012 || sigarg == SIGTERM | |
1013 # endif | |
1014 # ifdef SIGPWR | |
1015 || sigarg == SIGPWR | |
1016 # endif | |
1017 # ifdef SIGUSR1 | |
1018 || sigarg == SIGUSR1 | |
1019 # endif | |
1020 # ifdef SIGUSR2 | |
1021 || sigarg == SIGUSR2 | |
1022 # endif | |
1023 ) | |
413 | 1024 && !vim_handle_signal(sigarg)) |
36 | 1025 SIGRETURN; |
1026 #endif | |
1027 | |
7 | 1028 /* Remember how often we have been called. */ |
1029 ++entered; | |
1030 | |
1031 #ifdef FEAT_EVAL | |
1032 /* Set the v:dying variable. */ | |
1033 set_vim_var_nr(VV_DYING, (long)entered); | |
1034 #endif | |
1035 | |
180 | 1036 #ifdef HAVE_STACK_LIMIT |
7 | 1037 /* Since we are now using the signal stack, need to reset the stack |
1038 * limit. Otherwise using a regexp will fail. */ | |
1039 get_stack_limit(); | |
1040 #endif | |
1041 | |
758 | 1042 #if 0 |
1043 /* This is for opening gdb the moment Vim crashes. | |
1044 * You need to manually adjust the file name and Vim executable name. | |
1045 * Suggested by SungHyun Nam. */ | |
1046 { | |
1047 # define VI_GDB_FILE "/tmp/vimgdb" | |
1048 # define VIM_NAME "/usr/bin/vim" | |
1049 FILE *fp = fopen(VI_GDB_FILE, "w"); | |
1050 if (fp) | |
1051 { | |
1052 fprintf(fp, | |
1053 "file %s\n" | |
1054 "attach %d\n" | |
1055 "set height 1000\n" | |
1056 "bt full\n" | |
1057 , VIM_NAME, getpid()); | |
1058 fclose(fp); | |
1059 system("xterm -e gdb -x "VI_GDB_FILE); | |
1060 unlink(VI_GDB_FILE); | |
1061 } | |
1062 } | |
1063 #endif | |
1064 | |
7 | 1065 #ifdef SIGHASARG |
1066 /* try to find the name of this signal */ | |
1067 for (i = 0; signal_info[i].sig != -1; i++) | |
1068 if (sigarg == signal_info[i].sig) | |
1069 break; | |
1070 deadly_signal = sigarg; | |
1071 #endif | |
1072 | |
1073 full_screen = FALSE; /* don't write message to the GUI, it might be | |
1074 * part of the problem... */ | |
1075 /* | |
1076 * If something goes wrong after entering here, we may get here again. | |
1077 * When this happens, give a message and try to exit nicely (resetting the | |
1078 * terminal mode, etc.) | |
1079 * When this happens twice, just exit, don't even try to give a message, | |
1080 * stack may be corrupt or something weird. | |
1081 * When this still happens again (or memory was corrupted in such a way | |
1082 * that "entered" was clobbered) use _exit(), don't try freeing resources. | |
1083 */ | |
1084 if (entered >= 3) | |
1085 { | |
1086 reset_signals(); /* don't catch any signals anymore */ | |
1087 may_core_dump(); | |
1088 if (entered >= 4) | |
1089 _exit(8); | |
1090 exit(7); | |
1091 } | |
1092 if (entered == 2) | |
1093 { | |
5338 | 1094 /* No translation, it may call malloc(). */ |
1095 OUT_STR("Vim: Double signal, exiting\n"); | |
7 | 1096 out_flush(); |
1097 getout(1); | |
1098 } | |
1099 | |
5338 | 1100 /* No translation, it may call malloc(). */ |
7 | 1101 #ifdef SIGHASARG |
5338 | 1102 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", |
7 | 1103 signal_info[i].name); |
1104 #else | |
5338 | 1105 sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); |
1106 #endif | |
1107 | |
1108 /* Preserve files and exit. This sets the really_exiting flag to prevent | |
1109 * calling free(). */ | |
1110 preserve_exit(); | |
7 | 1111 |
33 | 1112 #ifdef NBDEBUG |
1113 reset_signals(); | |
1114 may_core_dump(); | |
1115 abort(); | |
1116 #endif | |
1117 | |
7 | 1118 SIGRETURN; |
1119 } | |
1120 | |
1832 | 1121 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1122 /* |
1123 * On Solaris with multi-threading, suspending might not work immediately. | |
1124 * Catch the SIGCONT signal, which will be used as an indication whether the | |
1125 * suspending has been done or not. | |
1832 | 1126 * |
1127 * On Linux, signal is not always handled immediately either. | |
1128 * See https://bugs.launchpad.net/bugs/291373 | |
1129 * | |
2701 | 1130 * volatile because it is used in signal handler sigcont_handler(). |
7 | 1131 */ |
1832 | 1132 static volatile int sigcont_received; |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1133 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
7 | 1134 |
1135 /* | |
1136 * signal handler for SIGCONT | |
1137 */ | |
1138 static RETSIGTYPE | |
1139 sigcont_handler SIGDEFARG(sigarg) | |
1140 { | |
1141 sigcont_received = TRUE; | |
1142 SIGRETURN; | |
1143 } | |
1144 #endif | |
1145 | |
2586 | 1146 # 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
|
1147 static void loose_clipboard(void); |
4230 | 1148 # ifdef USE_SYSTEM |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1149 static void save_clipboard(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1150 static void restore_clipboard(void); |
4209 | 1151 |
1152 static void *clip_star_save = NULL; | |
1153 static void *clip_plus_save = NULL; | |
4230 | 1154 # endif |
2586 | 1155 |
1156 /* | |
1157 * Called when Vim is going to sleep or execute a shell command. | |
1158 * We can't respond to requests for the X selections. Lose them, otherwise | |
1159 * other applications will hang. But first copy the text to cut buffer 0. | |
1160 */ | |
1161 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1162 loose_clipboard(void) |
2586 | 1163 { |
1164 if (clip_star.owned || clip_plus.owned) | |
1165 { | |
1166 x11_export_final_selection(); | |
1167 if (clip_star.owned) | |
1168 clip_lose_selection(&clip_star); | |
1169 if (clip_plus.owned) | |
1170 clip_lose_selection(&clip_plus); | |
1171 if (x11_display != NULL) | |
1172 XFlush(x11_display); | |
1173 } | |
1174 } | |
4209 | 1175 |
4230 | 1176 # ifdef USE_SYSTEM |
4209 | 1177 /* |
1178 * Save clipboard text to restore later. | |
1179 */ | |
1180 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1181 save_clipboard(void) |
4209 | 1182 { |
1183 if (clip_star.owned) | |
1184 clip_star_save = get_register('*', TRUE); | |
1185 if (clip_plus.owned) | |
1186 clip_plus_save = get_register('+', TRUE); | |
1187 } | |
1188 | |
1189 /* | |
1190 * Restore clipboard text if no one own the X selection. | |
1191 */ | |
1192 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1193 restore_clipboard(void) |
4209 | 1194 { |
1195 if (clip_star_save != NULL) | |
1196 { | |
1197 if (!clip_gen_owner_exists(&clip_star)) | |
1198 put_register('*', clip_star_save); | |
1199 else | |
1200 free_register(clip_star_save); | |
1201 clip_star_save = NULL; | |
1202 } | |
1203 if (clip_plus_save != NULL) | |
1204 { | |
1205 if (!clip_gen_owner_exists(&clip_plus)) | |
1206 put_register('+', clip_plus_save); | |
1207 else | |
1208 free_register(clip_plus_save); | |
1209 clip_plus_save = NULL; | |
1210 } | |
1211 } | |
4230 | 1212 # endif |
2586 | 1213 #endif |
1214 | |
7 | 1215 /* |
1216 * If the machine has job control, use it to suspend the program, | |
1217 * otherwise fake it by starting a new shell. | |
1218 */ | |
1219 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1220 mch_suspend(void) |
7 | 1221 { |
1222 /* BeOS does have SIGTSTP, but it doesn't work. */ | |
1223 #if defined(SIGTSTP) && !defined(__BEOS__) | |
1224 out_flush(); /* needed to make cursor visible on some systems */ | |
1225 settmode(TMODE_COOK); | |
1226 out_flush(); /* needed to disable mouse on some systems */ | |
1227 | |
1228 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2586 | 1229 loose_clipboard(); |
7 | 1230 # endif |
1231 | |
1832 | 1232 # if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1233 sigcont_received = FALSE; |
1234 # endif | |
1235 kill(0, SIGTSTP); /* send ourselves a STOP signal */ | |
1832 | 1236 # if defined(_REENTRANT) && defined(SIGCONT) |
1237 /* | |
1238 * Wait for the SIGCONT signal to be handled. It generally happens | |
1239 * immediately, but somehow not all the time. Do not call pause() | |
1240 * because there would be race condition which would hang Vim if | |
1241 * signal happened in between the test of sigcont_received and the | |
1242 * call to pause(). If signal is not yet received, call sleep(0) | |
1243 * to just yield CPU. Signal should then be received. If somehow | |
1244 * it's still not received, sleep 1, 2, 3 ms. Don't bother waiting | |
1245 * further if signal is not received after 1+2+3+4 ms (not expected | |
1246 * to happen). | |
1247 */ | |
1248 { | |
1932 | 1249 long wait_time; |
1250 for (wait_time = 0; !sigcont_received && wait_time <= 3L; wait_time++) | |
1832 | 1251 /* Loop is not entered most of the time */ |
1932 | 1252 mch_delay(wait_time, FALSE); |
1832 | 1253 } |
7 | 1254 # endif |
1255 | |
1256 # ifdef FEAT_TITLE | |
1257 /* | |
1258 * Set oldtitle to NULL, so the current title is obtained again. | |
1259 */ | |
1260 vim_free(oldtitle); | |
1261 oldtitle = NULL; | |
1262 # endif | |
1263 settmode(TMODE_RAW); | |
1264 need_check_timestamps = TRUE; | |
1265 did_check_timestamps = FALSE; | |
1266 #else | |
1267 suspend_shell(); | |
1268 #endif | |
1269 } | |
1270 | |
1271 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1272 mch_init(void) |
7 | 1273 { |
1274 Columns = 80; | |
1275 Rows = 24; | |
1276 | |
1277 out_flush(); | |
1278 set_signals(); | |
167 | 1279 |
765 | 1280 #ifdef MACOS_CONVERT |
167 | 1281 mac_conv_init(); |
1282 #endif | |
4168 | 1283 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
1284 win_clip_init(); | |
1285 #endif | |
7 | 1286 } |
1287 | |
1288 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1289 set_signals(void) |
7 | 1290 { |
1291 #if defined(SIGWINCH) | |
1292 /* | |
1293 * WINDOW CHANGE signal is handled with sig_winch(). | |
1294 */ | |
1295 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | |
1296 #endif | |
1297 | |
1298 /* | |
1299 * We want the STOP signal to work, to make mch_suspend() work. | |
1300 * For "rvim" the STOP signal is ignored. | |
1301 */ | |
1302 #ifdef SIGTSTP | |
1303 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); | |
1304 #endif | |
1832 | 1305 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1306 signal(SIGCONT, sigcont_handler); |
1307 #endif | |
1308 | |
1309 /* | |
1310 * We want to ignore breaking of PIPEs. | |
1311 */ | |
1312 #ifdef SIGPIPE | |
1313 signal(SIGPIPE, SIG_IGN); | |
1314 #endif | |
1315 | |
1316 #ifdef SIGINT | |
167 | 1317 catch_int_signal(); |
7 | 1318 #endif |
1319 | |
1320 /* | |
1321 * Ignore alarm signals (Perl's alarm() generates it). | |
1322 */ | |
1323 #ifdef SIGALRM | |
1324 signal(SIGALRM, SIG_IGN); | |
1325 #endif | |
1326 | |
1327 /* | |
1328 * Catch SIGPWR (power failure?) to preserve the swap files, so that no | |
1329 * work will be lost. | |
1330 */ | |
1331 #ifdef SIGPWR | |
1332 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); | |
1333 #endif | |
1334 | |
1335 /* | |
1336 * Arrange for other signals to gracefully shutdown Vim. | |
1337 */ | |
1338 catch_signals(deathtrap, SIG_ERR); | |
1339 | |
1340 #if defined(FEAT_GUI) && defined(SIGHUP) | |
1341 /* | |
1342 * When the GUI is running, ignore the hangup signal. | |
1343 */ | |
1344 if (gui.in_use) | |
1345 signal(SIGHUP, SIG_IGN); | |
1346 #endif | |
1347 } | |
1348 | |
167 | 1349 #if defined(SIGINT) || defined(PROTO) |
1350 /* | |
1351 * Catch CTRL-C (only works while in Cooked mode). | |
1352 */ | |
1353 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1354 catch_int_signal(void) |
167 | 1355 { |
1356 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); | |
1357 } | |
1358 #endif | |
1359 | |
7 | 1360 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1361 reset_signals(void) |
7 | 1362 { |
1363 catch_signals(SIG_DFL, SIG_DFL); | |
1832 | 1364 #if defined(_REENTRANT) && defined(SIGCONT) |
7 | 1365 /* SIGCONT isn't in the list, because its default action is ignore */ |
1366 signal(SIGCONT, SIG_DFL); | |
1367 #endif | |
1368 } | |
1369 | |
1370 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1371 catch_signals( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1372 RETSIGTYPE (*func_deadly)(), |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1373 RETSIGTYPE (*func_other)()) |
7 | 1374 { |
1375 int i; | |
1376 | |
1377 for (i = 0; signal_info[i].sig != -1; i++) | |
1378 if (signal_info[i].deadly) | |
1379 { | |
1380 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) | |
1381 struct sigaction sa; | |
1382 | |
1383 /* Setup to use the alternate stack for the signal function. */ | |
1384 sa.sa_handler = func_deadly; | |
1385 sigemptyset(&sa.sa_mask); | |
1386 # if defined(__linux__) && defined(_REENTRANT) | |
1387 /* On Linux, with glibc compiled for kernel 2.2, there is a bug in | |
1388 * thread handling in combination with using the alternate stack: | |
1389 * pthread library functions try to use the stack pointer to | |
1390 * identify the current thread, causing a SEGV signal, which | |
1391 * recursively calls deathtrap() and hangs. */ | |
1392 sa.sa_flags = 0; | |
1393 # else | |
1394 sa.sa_flags = SA_ONSTACK; | |
1395 # endif | |
1396 sigaction(signal_info[i].sig, &sa, NULL); | |
1397 #else | |
1398 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) | |
1399 struct sigvec sv; | |
1400 | |
1401 /* Setup to use the alternate stack for the signal function. */ | |
1402 sv.sv_handler = func_deadly; | |
1403 sv.sv_mask = 0; | |
1404 sv.sv_flags = SV_ONSTACK; | |
1405 sigvec(signal_info[i].sig, &sv, NULL); | |
1406 # else | |
1407 signal(signal_info[i].sig, func_deadly); | |
1408 # endif | |
1409 #endif | |
1410 } | |
1411 else if (func_other != SIG_ERR) | |
1412 signal(signal_info[i].sig, func_other); | |
1413 } | |
1414 | |
1415 /* | |
37 | 1416 * Handling of SIGHUP, SIGQUIT and SIGTERM: |
1146 | 1417 * "when" == a signal: when busy, postpone and return FALSE, otherwise |
1418 * return TRUE | |
1419 * "when" == SIGNAL_BLOCK: Going to be busy, block signals | |
1420 * "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
|
1421 * signal |
36 | 1422 * Returns TRUE when Vim should exit. |
1423 */ | |
1424 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1425 vim_handle_signal(int sig) |
36 | 1426 { |
37 | 1427 static int got_signal = 0; |
1428 static int blocked = TRUE; | |
1429 | |
1430 switch (sig) | |
36 | 1431 { |
37 | 1432 case SIGNAL_BLOCK: blocked = TRUE; |
1433 break; | |
1434 | |
1435 case SIGNAL_UNBLOCK: blocked = FALSE; | |
1436 if (got_signal != 0) | |
1437 { | |
1438 kill(getpid(), got_signal); | |
1439 got_signal = 0; | |
1440 } | |
1441 break; | |
1442 | |
1443 default: if (!blocked) | |
36 | 1444 return TRUE; /* exit! */ |
37 | 1445 got_signal = sig; |
1446 #ifdef SIGPWR | |
1447 if (sig != SIGPWR) | |
1448 #endif | |
1449 got_int = TRUE; /* break any loops */ | |
36 | 1450 break; |
1451 } | |
1452 return FALSE; | |
1453 } | |
1454 | |
1455 /* | |
7 | 1456 * Check_win checks whether we have an interactive stdout. |
1457 */ | |
1458 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1459 mch_check_win(int argc UNUSED, char **argv UNUSED) |
7 | 1460 { |
1461 if (isatty(1)) | |
1462 return OK; | |
1463 return FAIL; | |
1464 } | |
1465 | |
1466 /* | |
1467 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
1468 */ | |
1469 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1470 mch_input_isatty(void) |
7 | 1471 { |
1472 if (isatty(read_cmd_fd)) | |
1473 return TRUE; | |
1474 return FALSE; | |
1475 } | |
1476 | |
1477 #ifdef FEAT_X11 | |
1478 | |
1479 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) \ | |
1480 && (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE)) | |
1481 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1482 static void xopen_message(struct timeval *tvp); |
7 | 1483 |
1484 /* | |
1485 * Give a message about the elapsed time for opening the X window. | |
1486 */ | |
1487 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1488 xopen_message( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1489 struct timeval *tvp) /* must contain start time */ |
7 | 1490 { |
1491 struct timeval end_tv; | |
1492 | |
1493 /* Compute elapsed time. */ | |
1494 gettimeofday(&end_tv, NULL); | |
1495 smsg((char_u *)_("Opening the X display took %ld msec"), | |
1496 (end_tv.tv_sec - tvp->tv_sec) * 1000L | |
273 | 1497 + (end_tv.tv_usec - tvp->tv_usec) / 1000L); |
7 | 1498 } |
1499 # endif | |
1500 #endif | |
1501 | |
1502 #if defined(FEAT_X11) && (defined(FEAT_TITLE) || defined(FEAT_XCLIPBOARD)) | |
1503 /* | |
1504 * A few functions shared by X11 title and clipboard code. | |
1505 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1506 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
|
1507 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
|
1508 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
|
1509 static int test_x11_window(Display *dpy); |
7 | 1510 |
1511 static int got_x_error = FALSE; | |
1512 | |
1513 /* | |
1514 * X Error handler, otherwise X just exits! (very rude) -- webb | |
1515 */ | |
1516 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1517 x_error_handler(Display *dpy, XErrorEvent *error_event) |
7 | 1518 { |
42 | 1519 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); |
7 | 1520 STRCAT(IObuff, _("\nVim: Got X error\n")); |
1521 | |
1522 /* We cannot print a message and continue, because no X calls are allowed | |
1523 * here (causes my system to hang). Silently continuing might be an | |
1524 * alternative... */ | |
1525 preserve_exit(); /* preserve files and exit */ | |
1526 | |
1527 return 0; /* NOTREACHED */ | |
1528 } | |
1529 | |
1530 /* | |
1531 * Another X Error handler, just used to check for errors. | |
1532 */ | |
1533 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1534 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
7 | 1535 { |
1536 got_x_error = TRUE; | |
1537 return 0; | |
1538 } | |
1539 | |
1540 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) | |
1541 # if defined(HAVE_SETJMP_H) | |
1542 /* | |
1543 * An X IO Error handler, used to catch error while opening the display. | |
1544 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1545 static int x_IOerror_check(Display *dpy); |
7 | 1546 |
1547 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1548 x_IOerror_check(Display *dpy UNUSED) |
7 | 1549 { |
1550 /* This function should not return, it causes exit(). Longjump instead. */ | |
1551 LONGJMP(lc_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1552 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1553 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
|
1554 # endif |
7 | 1555 } |
1556 # endif | |
1557 | |
1558 /* | |
1559 * An X IO Error handler, used to catch terminal errors. | |
1560 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1561 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
|
1562 static void may_restore_clipboard(void); |
6383 | 1563 static int xterm_dpy_was_reset = FALSE; |
7 | 1564 |
1565 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1566 x_IOerror_handler(Display *dpy UNUSED) |
7 | 1567 { |
1568 xterm_dpy = NULL; | |
6383 | 1569 xterm_dpy_was_reset = TRUE; |
7 | 1570 x11_window = 0; |
1571 x11_display = NULL; | |
1572 xterm_Shell = (Widget)0; | |
1573 | |
1574 /* This function should not return, it causes exit(). Longjump instead. */ | |
1575 LONGJMP(x_jump_env, 1); | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
1576 # if defined(VMS) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
2074
1bb06e6512a2
updated for version 7.2.358
Bram Moolenaar <bram@zimbu.org>
parents:
1940
diff
changeset
|
1577 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
|
1578 # endif |
7 | 1579 } |
6383 | 1580 |
1581 /* | |
1582 * If the X11 connection was lost try to restore it. | |
1583 * Helps when the X11 server was stopped and restarted while Vim was inactive | |
6448 | 1584 * (e.g. through tmux). |
6383 | 1585 */ |
1586 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1587 may_restore_clipboard(void) |
6383 | 1588 { |
1589 if (xterm_dpy_was_reset) | |
1590 { | |
1591 xterm_dpy_was_reset = FALSE; | |
6458 | 1592 |
1593 # ifndef LESSTIF_VERSION | |
1594 /* This has been reported to avoid Vim getting stuck. */ | |
1595 if (app_context != (XtAppContext)NULL) | |
1596 { | |
1597 XtDestroyApplicationContext(app_context); | |
1598 app_context = (XtAppContext)NULL; | |
1599 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
1600 } | |
1601 # endif | |
1602 | |
6383 | 1603 setup_term_clip(); |
1604 get_x11_title(FALSE); | |
1605 } | |
1606 } | |
7 | 1607 #endif |
1608 | |
1609 /* | |
1610 * Return TRUE when connection to the X server is desired. | |
1611 */ | |
1612 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1613 x_connect_to_server(void) |
7 | 1614 { |
1615 #if defined(FEAT_CLIENTSERVER) | |
1616 if (x_force_connect) | |
1617 return TRUE; | |
1618 #endif | |
1619 if (x_no_connect) | |
1620 return FALSE; | |
1621 | |
1622 /* Check for a match with "exclude:" from 'clipboard'. */ | |
1623 if (clip_exclude_prog != NULL) | |
1624 { | |
6375 | 1625 if (vim_regexec_prog(&clip_exclude_prog, FALSE, T_NAME, (colnr_T)0)) |
7 | 1626 return FALSE; |
1627 } | |
1628 return TRUE; | |
1629 } | |
1630 | |
1631 /* | |
1632 * Test if "dpy" and x11_window are valid by getting the window title. | |
1633 * I don't actually want it yet, so there may be a simpler call to use, but | |
1634 * this will cause the error handler x_error_check() to be called if anything | |
1635 * is wrong, such as the window pointer being invalid (as can happen when the | |
1636 * user changes his DISPLAY, but not his WINDOWID) -- webb | |
1637 */ | |
1638 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1639 test_x11_window(Display *dpy) |
7 | 1640 { |
1641 int (*old_handler)(); | |
1642 XTextProperty text_prop; | |
1643 | |
1644 old_handler = XSetErrorHandler(x_error_check); | |
1645 got_x_error = FALSE; | |
1646 if (XGetWMName(dpy, x11_window, &text_prop)) | |
1647 XFree((void *)text_prop.value); | |
1648 XSync(dpy, False); | |
1649 (void)XSetErrorHandler(old_handler); | |
1650 | |
1651 if (p_verbose > 0 && got_x_error) | |
292 | 1652 verb_msg((char_u *)_("Testing the X display failed")); |
7 | 1653 |
1654 return (got_x_error ? FAIL : OK); | |
1655 } | |
1656 #endif | |
1657 | |
1658 #ifdef FEAT_TITLE | |
1659 | |
1660 #ifdef FEAT_X11 | |
1661 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
1662 static int get_x11_thing(int get_title, int test_only); |
7 | 1663 |
1664 /* | |
1665 * try to get x11 window and display | |
1666 * | |
1667 * return FAIL for failure, OK otherwise | |
1668 */ | |
1669 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1670 get_x11_windis(void) |
7 | 1671 { |
1672 char *winid; | |
1673 static int result = -1; | |
1674 #define XD_NONE 0 /* x11_display not set here */ | |
1675 #define XD_HERE 1 /* x11_display opened here */ | |
1676 #define XD_GUI 2 /* x11_display used from gui.dpy */ | |
1677 #define XD_XTERM 3 /* x11_display used from xterm_dpy */ | |
1678 static int x11_display_from = XD_NONE; | |
1679 static int did_set_error_handler = FALSE; | |
1680 | |
1681 if (!did_set_error_handler) | |
1682 { | |
1683 /* X just exits if it finds an error otherwise! */ | |
1684 (void)XSetErrorHandler(x_error_handler); | |
1685 did_set_error_handler = TRUE; | |
1686 } | |
1687 | |
574 | 1688 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
7 | 1689 if (gui.in_use) |
1690 { | |
1691 /* | |
1692 * If the X11 display was opened here before, for the window where Vim | |
1693 * was started, close that one now to avoid a memory leak. | |
1694 */ | |
1695 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1696 { | |
1697 XCloseDisplay(x11_display); | |
1698 x11_display_from = XD_NONE; | |
1699 } | |
1700 if (gui_get_x11_windis(&x11_window, &x11_display) == OK) | |
1701 { | |
1702 x11_display_from = XD_GUI; | |
1703 return OK; | |
1704 } | |
1705 x11_display = NULL; | |
1706 return FAIL; | |
1707 } | |
1708 else if (x11_display_from == XD_GUI) | |
1709 { | |
1710 /* GUI must have stopped somehow, clear x11_display */ | |
1711 x11_window = 0; | |
1712 x11_display = NULL; | |
1713 x11_display_from = XD_NONE; | |
1714 } | |
1715 #endif | |
1716 | |
1717 /* When started with the "-X" argument, don't try connecting. */ | |
1718 if (!x_connect_to_server()) | |
1719 return FAIL; | |
1720 | |
1721 /* | |
1722 * If WINDOWID not set, should try another method to find out | |
1723 * what the current window number is. The only code I know for | |
1724 * this is very complicated. | |
1725 * We assume that zero is invalid for WINDOWID. | |
1726 */ | |
1727 if (x11_window == 0 && (winid = getenv("WINDOWID")) != NULL) | |
1728 x11_window = (Window)atol(winid); | |
1729 | |
1730 #ifdef FEAT_XCLIPBOARD | |
1731 if (xterm_dpy != NULL && x11_window != 0) | |
1732 { | |
1450 | 1733 /* We may have checked it already, but Gnome terminal can move us to |
1734 * another window, so we need to check every time. */ | |
1735 if (x11_display_from != XD_XTERM) | |
1736 { | |
1737 /* | |
1738 * If the X11 display was opened here before, for the window where | |
1739 * Vim was started, close that one now to avoid a memory leak. | |
1740 */ | |
1741 if (x11_display_from == XD_HERE && x11_display != NULL) | |
1742 XCloseDisplay(x11_display); | |
1743 x11_display = xterm_dpy; | |
1744 x11_display_from = XD_XTERM; | |
1745 } | |
7 | 1746 if (test_x11_window(x11_display) == FAIL) |
1747 { | |
1748 /* probably bad $WINDOWID */ | |
1749 x11_window = 0; | |
1750 x11_display = NULL; | |
1751 x11_display_from = XD_NONE; | |
1752 return FAIL; | |
1753 } | |
1754 return OK; | |
1755 } | |
1756 #endif | |
1757 | |
1758 if (x11_window == 0 || x11_display == NULL) | |
1759 result = -1; | |
1760 | |
1761 if (result != -1) /* Have already been here and set this */ | |
1762 return result; /* Don't do all these X calls again */ | |
1763 | |
1764 if (x11_window != 0 && x11_display == NULL) | |
1765 { | |
1766 #ifdef SET_SIG_ALARM | |
1767 RETSIGTYPE (*sig_save)(); | |
1768 #endif | |
1769 #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
1770 struct timeval start_tv; | |
1771 | |
1772 if (p_verbose > 0) | |
1773 gettimeofday(&start_tv, NULL); | |
1774 #endif | |
1775 | |
1776 #ifdef SET_SIG_ALARM | |
1777 /* | |
1778 * Opening the Display may hang if the DISPLAY setting is wrong, or | |
1779 * the network connection is bad. Set an alarm timer to get out. | |
1780 */ | |
1781 sig_alarm_called = FALSE; | |
1782 sig_save = (RETSIGTYPE (*)())signal(SIGALRM, | |
1783 (RETSIGTYPE (*)())sig_alarm); | |
1784 alarm(2); | |
1785 #endif | |
1786 x11_display = XOpenDisplay(NULL); | |
1787 | |
1788 #ifdef SET_SIG_ALARM | |
1789 alarm(0); | |
1790 signal(SIGALRM, (RETSIGTYPE (*)())sig_save); | |
1791 if (p_verbose > 0 && sig_alarm_called) | |
292 | 1792 verb_msg((char_u *)_("Opening the X display timed out")); |
7 | 1793 #endif |
1794 if (x11_display != NULL) | |
1795 { | |
1796 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
1797 if (p_verbose > 0) | |
292 | 1798 { |
1799 verbose_enter(); | |
7 | 1800 xopen_message(&start_tv); |
292 | 1801 verbose_leave(); |
1802 } | |
7 | 1803 # endif |
1804 if (test_x11_window(x11_display) == FAIL) | |
1805 { | |
1806 /* Maybe window id is bad */ | |
1807 x11_window = 0; | |
1808 XCloseDisplay(x11_display); | |
1809 x11_display = NULL; | |
1810 } | |
1811 else | |
1812 x11_display_from = XD_HERE; | |
1813 } | |
1814 } | |
1815 if (x11_window == 0 || x11_display == NULL) | |
1816 return (result = FAIL); | |
2609 | 1817 |
1818 # ifdef FEAT_EVAL | |
1819 set_vim_var_nr(VV_WINDOWID, (long)x11_window); | |
1820 # endif | |
1821 | |
7 | 1822 return (result = OK); |
1823 } | |
1824 | |
1825 /* | |
1826 * Determine original x11 Window Title | |
1827 */ | |
1828 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1829 get_x11_title(int test_only) |
7 | 1830 { |
32 | 1831 return get_x11_thing(TRUE, test_only); |
7 | 1832 } |
1833 | |
1834 /* | |
1835 * Determine original x11 Window icon | |
1836 */ | |
1837 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1838 get_x11_icon(int test_only) |
7 | 1839 { |
1840 int retval = FALSE; | |
1841 | |
1842 retval = get_x11_thing(FALSE, test_only); | |
1843 | |
1844 /* could not get old icon, use terminal name */ | |
1845 if (oldicon == NULL && !test_only) | |
1846 { | |
1847 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 1848 oldicon = vim_strsave(T_NAME + 8); |
7 | 1849 else |
1940 | 1850 oldicon = vim_strsave(T_NAME); |
7 | 1851 } |
1852 | |
1853 return retval; | |
1854 } | |
1855 | |
1856 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1857 get_x11_thing( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1858 int get_title, /* get title string */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1859 int test_only) |
7 | 1860 { |
1861 XTextProperty text_prop; | |
1862 int retval = FALSE; | |
1863 Status status; | |
1864 | |
1865 if (get_x11_windis() == OK) | |
1866 { | |
1867 /* Get window/icon name if any */ | |
1868 if (get_title) | |
1869 status = XGetWMName(x11_display, x11_window, &text_prop); | |
1870 else | |
1871 status = XGetWMIconName(x11_display, x11_window, &text_prop); | |
1872 | |
1873 /* | |
1874 * If terminal is xterm, then x11_window may be a child window of the | |
1875 * outer xterm window that actually contains the window/icon name, so | |
1876 * keep traversing up the tree until a window with a title/icon is | |
1877 * found. | |
1878 */ | |
1879 /* Previously this was only done for xterm and alikes. I don't see a | |
1880 * reason why it would fail for other terminal emulators. | |
1881 * if (term_is_xterm) */ | |
1882 { | |
1883 Window root; | |
1884 Window parent; | |
1885 Window win = x11_window; | |
1886 Window *children; | |
1887 unsigned int num_children; | |
1888 | |
1889 while (!status || text_prop.value == NULL) | |
1890 { | |
1891 if (!XQueryTree(x11_display, win, &root, &parent, &children, | |
1892 &num_children)) | |
1893 break; | |
1894 if (children) | |
1895 XFree((void *)children); | |
1896 if (parent == root || parent == 0) | |
1897 break; | |
1898 | |
1899 win = parent; | |
1900 if (get_title) | |
1901 status = XGetWMName(x11_display, win, &text_prop); | |
1902 else | |
1903 status = XGetWMIconName(x11_display, win, &text_prop); | |
1904 } | |
1905 } | |
1906 if (status && text_prop.value != NULL) | |
1907 { | |
1908 retval = TRUE; | |
1909 if (!test_only) | |
1910 { | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1911 #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
|
1912 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
|
1913 # ifdef FEAT_MBYTE |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1914 && !has_mbyte |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1915 # endif |
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1916 ) |
7 | 1917 { |
1918 #endif | |
1919 if (get_title) | |
1920 oldtitle = vim_strsave((char_u *)text_prop.value); | |
1921 else | |
1922 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
|
1923 #if defined(FEAT_XFONTSET) || defined(FEAT_MBYTE) |
7 | 1924 } |
1925 else | |
1926 { | |
1927 char **cl; | |
1928 Status transform_status; | |
1929 int n = 0; | |
1930 | |
1931 transform_status = XmbTextPropertyToTextList(x11_display, | |
1932 &text_prop, | |
1933 &cl, &n); | |
1934 if (transform_status >= Success && n > 0 && cl[0]) | |
1935 { | |
1936 if (get_title) | |
1937 oldtitle = vim_strsave((char_u *) cl[0]); | |
1938 else | |
1939 oldicon = vim_strsave((char_u *) cl[0]); | |
1940 XFreeStringList(cl); | |
1941 } | |
1942 else | |
1943 { | |
1944 if (get_title) | |
1945 oldtitle = vim_strsave((char_u *)text_prop.value); | |
1946 else | |
1947 oldicon = vim_strsave((char_u *)text_prop.value); | |
1948 } | |
1949 } | |
1950 #endif | |
1951 } | |
1952 XFree((void *)text_prop.value); | |
1953 } | |
1954 } | |
1955 return retval; | |
1956 } | |
1957 | |
6282 | 1958 /* Xutf8 functions are not avaialble on older systems. Note that on some |
1959 * systems X_HAVE_UTF8_STRING may be defined in a header file but | |
1960 * Xutf8SetWMProperties() is not in the X11 library. Configure checks for | |
1961 * that and defines HAVE_XUTF8SETWMPROPERTIES. */ | |
7 | 1962 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE) |
6282 | 1963 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES |
7 | 1964 # define USE_UTF8_STRING |
1965 # endif | |
1966 #endif | |
1967 | |
1968 /* | |
1969 * Set x11 Window Title | |
1970 * | |
1971 * get_x11_windis() must be called before this and have returned OK | |
1972 */ | |
1973 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1974 set_x11_title(char_u *title) |
7 | 1975 { |
1976 /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING | |
1977 * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't | |
1978 * supported everywhere and STRING doesn't work for multi-byte titles. | |
1979 */ | |
1980 #ifdef USE_UTF8_STRING | |
1981 if (enc_utf8) | |
1982 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, | |
1983 NULL, NULL, 0, NULL, NULL, NULL); | |
1984 else | |
1985 #endif | |
1986 { | |
1987 #if XtSpecificationRelease >= 4 | |
1988 # ifdef FEAT_XFONTSET | |
1989 XmbSetWMProperties(x11_display, x11_window, (const char *)title, | |
1990 NULL, NULL, 0, NULL, NULL, NULL); | |
1991 # else | |
1992 XTextProperty text_prop; | |
129 | 1993 char *c_title = (char *)title; |
7 | 1994 |
1995 /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ | |
129 | 1996 (void)XStringListToTextProperty(&c_title, 1, &text_prop); |
7 | 1997 XSetWMProperties(x11_display, x11_window, &text_prop, |
1998 NULL, NULL, 0, NULL, NULL, NULL); | |
1999 # endif | |
2000 #else | |
2001 XStoreName(x11_display, x11_window, (char *)title); | |
2002 #endif | |
2003 } | |
2004 XFlush(x11_display); | |
2005 } | |
2006 | |
2007 /* | |
2008 * Set x11 Window icon | |
2009 * | |
2010 * get_x11_windis() must be called before this and have returned OK | |
2011 */ | |
2012 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2013 set_x11_icon(char_u *icon) |
7 | 2014 { |
2015 /* See above for comments about using X*SetWMProperties(). */ | |
2016 #ifdef USE_UTF8_STRING | |
2017 if (enc_utf8) | |
2018 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2019 NULL, 0, NULL, NULL, NULL); | |
2020 else | |
2021 #endif | |
2022 { | |
2023 #if XtSpecificationRelease >= 4 | |
2024 # ifdef FEAT_XFONTSET | |
2025 XmbSetWMProperties(x11_display, x11_window, NULL, (const char *)icon, | |
2026 NULL, 0, NULL, NULL, NULL); | |
2027 # else | |
2028 XTextProperty text_prop; | |
129 | 2029 char *c_icon = (char *)icon; |
2030 | |
2031 (void)XStringListToTextProperty(&c_icon, 1, &text_prop); | |
7 | 2032 XSetWMProperties(x11_display, x11_window, NULL, &text_prop, |
2033 NULL, 0, NULL, NULL, NULL); | |
2034 # endif | |
2035 #else | |
2036 XSetIconName(x11_display, x11_window, (char *)icon); | |
2037 #endif | |
2038 } | |
2039 XFlush(x11_display); | |
2040 } | |
2041 | |
2042 #else /* FEAT_X11 */ | |
2043 | |
2044 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2045 get_x11_title(int test_only UNUSED) |
7 | 2046 { |
2047 return FALSE; | |
2048 } | |
2049 | |
2050 static int | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2051 get_x11_icon(int test_only) |
7 | 2052 { |
2053 if (!test_only) | |
2054 { | |
2055 if (STRNCMP(T_NAME, "builtin_", 8) == 0) | |
1940 | 2056 oldicon = vim_strsave(T_NAME + 8); |
7 | 2057 else |
1940 | 2058 oldicon = vim_strsave(T_NAME); |
7 | 2059 } |
2060 return FALSE; | |
2061 } | |
2062 | |
2063 #endif /* FEAT_X11 */ | |
2064 | |
2065 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2066 mch_can_restore_title(void) |
7 | 2067 { |
2068 return get_x11_title(TRUE); | |
2069 } | |
2070 | |
2071 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2072 mch_can_restore_icon(void) |
7 | 2073 { |
2074 return get_x11_icon(TRUE); | |
2075 } | |
2076 | |
2077 /* | |
2078 * Set the window title and icon. | |
2079 */ | |
2080 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2081 mch_settitle(char_u *title, char_u *icon) |
7 | 2082 { |
2083 int type = 0; | |
2084 static int recursive = 0; | |
2085 | |
2086 if (T_NAME == NULL) /* no terminal name (yet) */ | |
2087 return; | |
2088 if (title == NULL && icon == NULL) /* nothing to do */ | |
2089 return; | |
2090 | |
2091 /* When one of the X11 functions causes a deadly signal, we get here again | |
2092 * recursively. Avoid hanging then (something is probably locked). */ | |
2093 if (recursive) | |
2094 return; | |
2095 ++recursive; | |
2096 | |
2097 /* | |
2098 * if the window ID and the display is known, we may use X11 calls | |
2099 */ | |
2100 #ifdef FEAT_X11 | |
2101 if (get_x11_windis() == OK) | |
2102 type = 1; | |
2103 #else | |
2104 # if defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_GTK) | |
2105 if (gui.in_use) | |
2106 type = 1; | |
2107 # endif | |
2108 #endif | |
2109 | |
2110 /* | |
2414
5bd81e397907
Fix: terminal title not properly restured when there are multi-byte
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2111 * Note: if "t_ts" is set, title is set with escape sequence rather |
7 | 2112 * than x11 calls, because the x11 calls don't always work |
2113 */ | |
2114 if ((type || *T_TS != NUL) && title != NULL) | |
2115 { | |
2116 if (oldtitle == NULL | |
2117 #ifdef FEAT_GUI | |
2118 && !gui.in_use | |
2119 #endif | |
2120 ) /* first call but not in GUI, save title */ | |
2121 (void)get_x11_title(FALSE); | |
2122 | |
2123 if (*T_TS != NUL) /* it's OK if t_fs is empty */ | |
2124 term_settitle(title); | |
2125 #ifdef FEAT_X11 | |
2126 else | |
2127 # ifdef FEAT_GUI_GTK | |
2128 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2129 # endif | |
2130 set_x11_title(title); /* x11 */ | |
2131 #endif | |
64 | 2132 #if defined(FEAT_GUI_GTK) \ |
7 | 2133 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
2134 else | |
2135 gui_mch_settitle(title, icon); | |
2136 #endif | |
2137 did_set_title = TRUE; | |
2138 } | |
2139 | |
2140 if ((type || *T_CIS != NUL) && icon != NULL) | |
2141 { | |
2142 if (oldicon == NULL | |
2143 #ifdef FEAT_GUI | |
2144 && !gui.in_use | |
2145 #endif | |
2146 ) /* first call, save icon */ | |
2147 get_x11_icon(FALSE); | |
2148 | |
2149 if (*T_CIS != NUL) | |
2150 { | |
2151 out_str(T_CIS); /* set icon start */ | |
2152 out_str_nf(icon); | |
2153 out_str(T_CIE); /* set icon end */ | |
2154 out_flush(); | |
2155 } | |
2156 #ifdef FEAT_X11 | |
2157 else | |
2158 # ifdef FEAT_GUI_GTK | |
2159 if (!gui.in_use) /* don't do this if GTK+ is running */ | |
2160 # endif | |
2161 set_x11_icon(icon); /* x11 */ | |
2162 #endif | |
2163 did_set_icon = TRUE; | |
2164 } | |
2165 --recursive; | |
2166 } | |
2167 | |
2168 /* | |
2169 * Restore the window/icon title. | |
2170 * "which" is one of: | |
2171 * 1 only restore title | |
2172 * 2 only restore icon | |
2173 * 3 restore title and icon | |
2174 */ | |
2175 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2176 mch_restore_title(int which) |
7 | 2177 { |
2178 /* only restore the title or icon when it has been set */ | |
2179 mch_settitle(((which & 1) && did_set_title) ? | |
2180 (oldtitle ? oldtitle : p_titleold) : NULL, | |
2181 ((which & 2) && did_set_icon) ? oldicon : NULL); | |
2182 } | |
2183 | |
2184 #endif /* FEAT_TITLE */ | |
2185 | |
2186 /* | |
2187 * Return TRUE if "name" looks like some xterm name. | |
158 | 2188 * Seiichi Sato mentioned that "mlterm" works like xterm. |
7 | 2189 */ |
2190 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2191 vim_is_xterm(char_u *name) |
7 | 2192 { |
2193 if (name == NULL) | |
2194 return FALSE; | |
2195 return (STRNICMP(name, "xterm", 5) == 0 | |
2196 || STRNICMP(name, "nxterm", 6) == 0 | |
2197 || STRNICMP(name, "kterm", 5) == 0 | |
158 | 2198 || STRNICMP(name, "mlterm", 6) == 0 |
7 | 2199 || STRNICMP(name, "rxvt", 4) == 0 |
2200 || STRCMP(name, "builtin_xterm") == 0); | |
2201 } | |
2202 | |
1620 | 2203 #if defined(FEAT_MOUSE_XTERM) || defined(PROTO) |
2204 /* | |
2205 * Return TRUE if "name" appears to be that of a terminal | |
2206 * known to support the xterm-style mouse protocol. | |
2207 * Relies on term_is_xterm having been set to its correct value. | |
2208 */ | |
2209 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2210 use_xterm_like_mouse(char_u *name) |
1620 | 2211 { |
2212 return (name != NULL | |
2213 && (term_is_xterm || STRNICMP(name, "screen", 6) == 0)); | |
2214 } | |
2215 #endif | |
2216 | |
7 | 2217 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) |
2218 /* | |
2219 * Return non-zero when using an xterm mouse, according to 'ttymouse'. | |
2220 * Return 1 for "xterm". | |
2221 * Return 2 for "xterm2". | |
3145 | 2222 * Return 3 for "urxvt". |
3746 | 2223 * Return 4 for "sgr". |
7 | 2224 */ |
2225 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2226 use_xterm_mouse(void) |
7 | 2227 { |
3746 | 2228 if (ttym_flags == TTYM_SGR) |
2229 return 4; | |
3145 | 2230 if (ttym_flags == TTYM_URXVT) |
2231 return 3; | |
7 | 2232 if (ttym_flags == TTYM_XTERM2) |
2233 return 2; | |
2234 if (ttym_flags == TTYM_XTERM) | |
2235 return 1; | |
2236 return 0; | |
2237 } | |
2238 #endif | |
2239 | |
2240 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2241 vim_is_iris(char_u *name) |
7 | 2242 { |
2243 if (name == NULL) | |
2244 return FALSE; | |
2245 return (STRNICMP(name, "iris-ansi", 9) == 0 | |
2246 || STRCMP(name, "builtin_iris-ansi") == 0); | |
2247 } | |
2248 | |
2249 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2250 vim_is_vt300(char_u *name) |
7 | 2251 { |
2252 if (name == NULL) | |
2253 return FALSE; /* actually all ANSI comp. terminals should be here */ | |
22 | 2254 /* catch VT100 - VT5xx */ |
2255 return ((STRNICMP(name, "vt", 2) == 0 | |
2256 && vim_strchr((char_u *)"12345", name[2]) != NULL) | |
7 | 2257 || STRCMP(name, "builtin_vt320") == 0); |
2258 } | |
2259 | |
2260 /* | |
2261 * Return TRUE if "name" is a terminal for which 'ttyfast' should be set. | |
2262 * This should include all windowed terminal emulators. | |
2263 */ | |
2264 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2265 vim_is_fastterm(char_u *name) |
7 | 2266 { |
2267 if (name == NULL) | |
2268 return FALSE; | |
2269 if (vim_is_xterm(name) || vim_is_vt300(name) || vim_is_iris(name)) | |
2270 return TRUE; | |
2271 return ( STRNICMP(name, "hpterm", 6) == 0 | |
2272 || STRNICMP(name, "sun-cmd", 7) == 0 | |
2273 || STRNICMP(name, "screen", 6) == 0 | |
2274 || STRNICMP(name, "dtterm", 6) == 0); | |
2275 } | |
2276 | |
2277 /* | |
2278 * Insert user name in s[len]. | |
2279 * Return OK if a name found. | |
2280 */ | |
2281 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2282 mch_get_user_name(char_u *s, int len) |
7 | 2283 { |
2284 #ifdef VMS | |
509 | 2285 vim_strncpy(s, (char_u *)cuserid(NULL), len - 1); |
7 | 2286 return OK; |
2287 #else | |
2288 return mch_get_uname(getuid(), s, len); | |
2289 #endif | |
2290 } | |
2291 | |
2292 /* | |
2293 * Insert user name for "uid" in s[len]. | |
2294 * Return OK if a name found. | |
2295 */ | |
2296 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2297 mch_get_uname(uid_t uid, char_u *s, int len) |
7 | 2298 { |
2299 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) | |
2300 struct passwd *pw; | |
2301 | |
2302 if ((pw = getpwuid(uid)) != NULL | |
2303 && pw->pw_name != NULL && *(pw->pw_name) != NUL) | |
2304 { | |
418 | 2305 vim_strncpy(s, (char_u *)pw->pw_name, len - 1); |
7 | 2306 return OK; |
2307 } | |
2308 #endif | |
2309 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ | |
2310 return FAIL; /* a number is not a name */ | |
2311 } | |
2312 | |
2313 /* | |
2314 * Insert host name is s[len]. | |
2315 */ | |
2316 | |
2317 #ifdef HAVE_SYS_UTSNAME_H | |
2318 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2319 mch_get_host_name(char_u *s, int len) |
7 | 2320 { |
2321 struct utsname vutsname; | |
2322 | |
2323 if (uname(&vutsname) < 0) | |
2324 *s = NUL; | |
2325 else | |
418 | 2326 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); |
7 | 2327 } |
2328 #else /* HAVE_SYS_UTSNAME_H */ | |
2329 | |
2330 # ifdef HAVE_SYS_SYSTEMINFO_H | |
2331 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) | |
2332 # endif | |
2333 | |
2334 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2335 mch_get_host_name(char_u *s, int len) |
7 | 2336 { |
2337 # ifdef VAXC | |
2338 vaxc$gethostname((char *)s, len); | |
2339 # else | |
2340 gethostname((char *)s, len); | |
2341 # endif | |
2342 s[len - 1] = NUL; /* make sure it's terminated */ | |
2343 } | |
2344 #endif /* HAVE_SYS_UTSNAME_H */ | |
2345 | |
2346 /* | |
2347 * return process ID | |
2348 */ | |
2349 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2350 mch_get_pid(void) |
7 | 2351 { |
2352 return (long)getpid(); | |
2353 } | |
2354 | |
2355 #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
|
2356 static char *strerror(int); |
7 | 2357 |
2358 static char * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2359 strerror(int err) |
7 | 2360 { |
2361 extern int sys_nerr; | |
2362 extern char *sys_errlist[]; | |
2363 static char er[20]; | |
2364 | |
2365 if (err > 0 && err < sys_nerr) | |
2366 return (sys_errlist[err]); | |
2367 sprintf(er, "Error %d", err); | |
2368 return er; | |
2369 } | |
2370 #endif | |
2371 | |
2372 /* | |
2373 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2374 * Return OK for success, FAIL for failure. | |
2375 */ | |
2376 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2377 mch_dirname(char_u *buf, int len) |
7 | 2378 { |
2379 #if defined(USE_GETCWD) | |
2380 if (getcwd((char *)buf, len) == NULL) | |
2381 { | |
2382 STRCPY(buf, strerror(errno)); | |
2383 return FAIL; | |
2384 } | |
2385 return OK; | |
2386 #else | |
2387 return (getwd((char *)buf) != NULL ? OK : FAIL); | |
2388 #endif | |
2389 } | |
2390 | |
2391 /* | |
1045 | 2392 * Get absolute file name into "buf[len]". |
7 | 2393 * |
2394 * return FAIL for failure, OK for success | |
2395 */ | |
2396 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2397 mch_FullName( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2398 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2399 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2400 int len, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2401 int force) /* also expand when already absolute path */ |
7 | 2402 { |
2403 int l; | |
1082 | 2404 #ifdef HAVE_FCHDIR |
7 | 2405 int fd = -1; |
2406 static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ | |
1082 | 2407 #endif |
7 | 2408 char_u olddir[MAXPATHL]; |
2409 char_u *p; | |
2410 int retval = OK; | |
1615 | 2411 #ifdef __CYGWIN__ |
1620 | 2412 char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but |
2413 it's not always defined */ | |
2414 #endif | |
7 | 2415 |
1082 | 2416 #ifdef VMS |
2417 fname = vms_fixfilename(fname); | |
2418 #endif | |
2419 | |
1102 | 2420 #ifdef __CYGWIN__ |
2421 /* | |
2422 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". | |
2423 */ | |
1657 | 2424 # 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
|
2425 /* 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
|
2426 * a forward slash. */ |
37092e334ef2
commit https://github.com/vim/vim/commit/06b0734d9cd2f39d4c12c7fd89a100eadbe5be78
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2427 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
|
2428 fname, posix_fname, MAXPATHL); |
1657 | 2429 # else |
1615 | 2430 cygwin_conv_to_posix_path(fname, posix_fname); |
1657 | 2431 # endif |
1615 | 2432 fname = posix_fname; |
1102 | 2433 #endif |
2434 | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2435 /* 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
|
2436 * 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
|
2437 if ((force || !mch_isFullName(fname)) |
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2438 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) |
7 | 2439 { |
2440 /* | |
2441 * If the file name has a path, change to that directory for a moment, | |
2442 * and then do the getwd() (and get back to where we were). | |
2443 * This will get the correct path name with "../" things. | |
2444 */ | |
7406
c97735aaef9f
commit https://github.com/vim/vim/commit/e3303cb0817e826e3c25d5dc4ac10b569d0841e1
Christian Brabandt <cb@256bit.org>
parents:
7239
diff
changeset
|
2445 if (p != NULL) |
7 | 2446 { |
1082 | 2447 #ifdef HAVE_FCHDIR |
7 | 2448 /* |
2449 * Use fchdir() if possible, it's said to be faster and more | |
2450 * reliable. But on SunOS 4 it might not work. Check this by | |
2451 * doing a fchdir() right now. | |
2452 */ | |
2453 if (!dont_fchdir) | |
2454 { | |
2455 fd = open(".", O_RDONLY | O_EXTRA, 0); | |
2456 if (fd >= 0 && fchdir(fd) < 0) | |
2457 { | |
2458 close(fd); | |
2459 fd = -1; | |
2460 dont_fchdir = TRUE; /* don't try again */ | |
2461 } | |
2462 } | |
1082 | 2463 #endif |
7 | 2464 |
2465 /* Only change directory when we are sure we can return to where | |
2466 * we are now. After doing "su" chdir(".") might not work. */ | |
2467 if ( | |
1082 | 2468 #ifdef HAVE_FCHDIR |
7 | 2469 fd < 0 && |
1082 | 2470 #endif |
7 | 2471 (mch_dirname(olddir, MAXPATHL) == FAIL |
2472 || mch_chdir((char *)olddir) != 0)) | |
2473 { | |
2474 p = NULL; /* can't get current dir: don't chdir */ | |
2475 retval = FAIL; | |
2476 } | |
2477 else | |
2478 { | |
2479 /* The directory is copied into buf[], to be able to remove | |
2480 * the file name without changing it (could be a string in | |
2481 * read-only memory) */ | |
2482 if (p - fname >= len) | |
2483 retval = FAIL; | |
2484 else | |
2485 { | |
418 | 2486 vim_strncpy(buf, fname, p - fname); |
7 | 2487 if (mch_chdir((char *)buf)) |
2488 retval = FAIL; | |
2489 else | |
2490 fname = p + 1; | |
2491 *buf = NUL; | |
2492 } | |
2493 } | |
2494 } | |
2495 if (mch_dirname(buf, len) == FAIL) | |
2496 { | |
2497 retval = FAIL; | |
2498 *buf = NUL; | |
2499 } | |
2500 if (p != NULL) | |
2501 { | |
1082 | 2502 #ifdef HAVE_FCHDIR |
7 | 2503 if (fd >= 0) |
2504 { | |
1935 | 2505 if (p_verbose >= 5) |
2506 { | |
2507 verbose_enter(); | |
2508 MSG("fchdir() to previous dir"); | |
2509 verbose_leave(); | |
2510 } | |
7 | 2511 l = fchdir(fd); |
2512 close(fd); | |
2513 } | |
2514 else | |
1082 | 2515 #endif |
7 | 2516 l = mch_chdir((char *)olddir); |
2517 if (l != 0) | |
2518 EMSG(_(e_prev_dir)); | |
2519 } | |
2520 | |
2521 l = STRLEN(buf); | |
3867 | 2522 if (l >= len - 1) |
2523 retval = FAIL; /* no space for trailing "/" */ | |
1082 | 2524 #ifndef VMS |
3867 | 2525 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL |
7 | 2526 && STRCMP(fname, ".") != 0) |
3867 | 2527 STRCAT(buf, "/"); |
1082 | 2528 #endif |
7 | 2529 } |
1045 | 2530 |
7 | 2531 /* Catch file names which are too long. */ |
1877 | 2532 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) |
7 | 2533 return FAIL; |
2534 | |
2535 /* Do not append ".", "/dir/." is equal to "/dir". */ | |
2536 if (STRCMP(fname, ".") != 0) | |
2537 STRCAT(buf, fname); | |
2538 | |
2539 return OK; | |
2540 } | |
2541 | |
2542 /* | |
2543 * Return TRUE if "fname" does not depend on the current directory. | |
2544 */ | |
2545 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2546 mch_isFullName(char_u *fname) |
7 | 2547 { |
2548 #ifdef __EMX__ | |
2549 return _fnisabs(fname); | |
2550 #else | |
2551 # ifdef VMS | |
2552 return ( fname[0] == '/' || fname[0] == '.' || | |
2553 strchr((char *)fname,':') || strchr((char *)fname,'"') || | |
2554 (strchr((char *)fname,'[') && strchr((char *)fname,']'))|| | |
2555 (strchr((char *)fname,'<') && strchr((char *)fname,'>')) ); | |
2556 # else | |
2557 return (*fname == '/' || *fname == '~'); | |
2558 # endif | |
2559 #endif | |
2560 } | |
2561 | |
585 | 2562 #if defined(USE_FNAME_CASE) || defined(PROTO) |
2563 /* | |
2564 * Set the case of the file name, if it already exists. This will cause the | |
2565 * file name to remain exactly the same. | |
1450 | 2566 * Only required for file systems where case is ignored and preserved. |
585 | 2567 */ |
2568 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2569 fname_case( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2570 char_u *name, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2571 int len UNUSED) /* buffer size, only used when name gets longer */ |
585 | 2572 { |
2573 struct stat st; | |
2574 char_u *slash, *tail; | |
2575 DIR *dirp; | |
2576 struct dirent *dp; | |
2577 | |
2578 if (lstat((char *)name, &st) >= 0) | |
2579 { | |
2580 /* Open the directory where the file is located. */ | |
2581 slash = vim_strrchr(name, '/'); | |
2582 if (slash == NULL) | |
2583 { | |
2584 dirp = opendir("."); | |
2585 tail = name; | |
2586 } | |
2587 else | |
2588 { | |
2589 *slash = NUL; | |
2590 dirp = opendir((char *)name); | |
2591 *slash = '/'; | |
2592 tail = slash + 1; | |
2593 } | |
2594 | |
2595 if (dirp != NULL) | |
2596 { | |
2597 while ((dp = readdir(dirp)) != NULL) | |
2598 { | |
2599 /* Only accept names that differ in case and are the same byte | |
2600 * length. TODO: accept different length name. */ | |
2601 if (STRICMP(tail, dp->d_name) == 0 | |
2602 && STRLEN(tail) == STRLEN(dp->d_name)) | |
2603 { | |
2604 char_u newname[MAXPATHL + 1]; | |
2605 struct stat st2; | |
2606 | |
2607 /* Verify the inode is equal. */ | |
2608 vim_strncpy(newname, name, MAXPATHL); | |
2609 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, | |
2610 MAXPATHL - (tail - name)); | |
2611 if (lstat((char *)newname, &st2) >= 0 | |
2612 && st.st_ino == st2.st_ino | |
2613 && st.st_dev == st2.st_dev) | |
2614 { | |
2615 STRCPY(tail, dp->d_name); | |
2616 break; | |
2617 } | |
2618 } | |
2619 } | |
2620 | |
2621 closedir(dirp); | |
2622 } | |
2623 } | |
2624 } | |
2625 #endif | |
2626 | |
7 | 2627 /* |
2628 * Get file permissions for 'name'. | |
2629 * Returns -1 when it doesn't exist. | |
2630 */ | |
2631 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2632 mch_getperm(char_u *name) |
7 | 2633 { |
2634 struct stat statb; | |
2635 | |
2636 /* Keep the #ifdef outside of stat(), it may be a macro. */ | |
2637 #ifdef VMS | |
2638 if (stat((char *)vms_fixfilename(name), &statb)) | |
2639 #else | |
2640 if (stat((char *)name, &statb)) | |
2641 #endif | |
2642 return -1; | |
1350 | 2643 #ifdef __INTERIX |
2644 /* The top bit makes the value negative, which means the file doesn't | |
2645 * exist. Remove the bit, we don't use it. */ | |
2646 return statb.st_mode & ~S_ADDACE; | |
2647 #else | |
7 | 2648 return statb.st_mode; |
1350 | 2649 #endif |
7 | 2650 } |
2651 | |
2652 /* | |
2653 * set file permission for 'name' to 'perm' | |
2654 * | |
2655 * return FAIL for failure, OK otherwise | |
2656 */ | |
2657 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2658 mch_setperm(char_u *name, long perm) |
7 | 2659 { |
2660 return (chmod((char *) | |
2661 #ifdef VMS | |
2662 vms_fixfilename(name), | |
2663 #else | |
2664 name, | |
2665 #endif | |
2666 (mode_t)perm) == 0 ? OK : FAIL); | |
2667 } | |
2668 | |
2669 #if defined(HAVE_ACL) || defined(PROTO) | |
2670 # ifdef HAVE_SYS_ACL_H | |
2671 # include <sys/acl.h> | |
2672 # endif | |
2673 # ifdef HAVE_SYS_ACCESS_H | |
2674 # include <sys/access.h> | |
2675 # endif | |
2676 | |
2677 # ifdef HAVE_SOLARIS_ACL | |
2678 typedef struct vim_acl_solaris_T { | |
2679 int acl_cnt; | |
2680 aclent_t *acl_entry; | |
2681 } vim_acl_solaris_T; | |
2682 # endif | |
2683 | |
1583 | 2684 #if defined(HAVE_SELINUX) || defined(PROTO) |
2685 /* | |
2686 * Copy security info from "from_file" to "to_file". | |
2687 */ | |
2688 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2689 mch_copy_sec(char_u *from_file, char_u *to_file) |
1583 | 2690 { |
2691 if (from_file == NULL) | |
2692 return; | |
2693 | |
2694 if (selinux_enabled == -1) | |
2695 selinux_enabled = is_selinux_enabled(); | |
2696 | |
2697 if (selinux_enabled > 0) | |
2698 { | |
2699 security_context_t from_context = NULL; | |
2700 security_context_t to_context = NULL; | |
2701 | |
2702 if (getfilecon((char *)from_file, &from_context) < 0) | |
2703 { | |
2704 /* If the filesystem doesn't support extended attributes, | |
2705 the original had no special security context and the | |
2706 target cannot have one either. */ | |
2707 if (errno == EOPNOTSUPP) | |
2708 return; | |
2709 | |
2710 MSG_PUTS(_("\nCould not get security context for ")); | |
2711 msg_outtrans(from_file); | |
2712 msg_putchar('\n'); | |
2713 return; | |
2714 } | |
2715 if (getfilecon((char *)to_file, &to_context) < 0) | |
2716 { | |
2717 MSG_PUTS(_("\nCould not get security context for ")); | |
2718 msg_outtrans(to_file); | |
2719 msg_putchar('\n'); | |
2720 freecon (from_context); | |
2721 return ; | |
2722 } | |
2723 if (strcmp(from_context, to_context) != 0) | |
2724 { | |
2725 if (setfilecon((char *)to_file, from_context) < 0) | |
2726 { | |
2727 MSG_PUTS(_("\nCould not set security context for ")); | |
2728 msg_outtrans(to_file); | |
2729 msg_putchar('\n'); | |
2730 } | |
2731 } | |
2732 freecon(to_context); | |
2733 freecon(from_context); | |
2734 } | |
2735 } | |
2736 #endif /* HAVE_SELINUX */ | |
2737 | |
5788 | 2738 #if defined(HAVE_SMACK) && !defined(PROTO) |
2739 /* | |
2740 * Copy security info from "from_file" to "to_file". | |
2741 */ | |
2742 void | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2743 mch_copy_sec(char_u *from_file, char_u *to_file) |
5788 | 2744 { |
5832 | 2745 static const char * const smack_copied_attributes[] = |
5788 | 2746 { |
2747 XATTR_NAME_SMACK, | |
2748 XATTR_NAME_SMACKEXEC, | |
2749 XATTR_NAME_SMACKMMAP | |
2750 }; | |
2751 | |
2752 char buffer[SMACK_LABEL_LEN]; | |
2753 const char *name; | |
2754 int index; | |
2755 int ret; | |
2756 ssize_t size; | |
2757 | |
2758 if (from_file == NULL) | |
2759 return; | |
2760 | |
2761 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) | |
2762 / sizeof(smack_copied_attributes)[0]) ; index++) | |
2763 { | |
2764 /* get the name of the attribute to copy */ | |
2765 name = smack_copied_attributes[index]; | |
2766 | |
2767 /* get the value of the attribute in buffer */ | |
2768 size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); | |
2769 if (size >= 0) | |
2770 { | |
2771 /* copy the attribute value of buffer */ | |
2772 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); | |
2773 if (ret < 0) | |
2774 { | |
7778
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2775 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2776 _("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
|
2777 name, to_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2778 msg_outtrans(IObuff); |
5788 | 2779 msg_putchar('\n'); |
2780 } | |
2781 } | |
2782 else | |
2783 { | |
2784 /* what reason of not having the attribute value? */ | |
2785 switch (errno) | |
2786 { | |
2787 case ENOTSUP: | |
2788 /* extended attributes aren't supported or enabled */ | |
2789 /* should a message be echoed? not sure... */ | |
2790 return; /* leave because it isn't usefull to continue */ | |
2791 | |
2792 case ERANGE: | |
2793 default: | |
2794 /* 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
|
2795 vim_snprintf((char *)IObuff, IOSIZE, |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2796 _("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
|
2797 name, from_file); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2798 msg_puts(IObuff); |
4e09a38129a3
commit https://github.com/vim/vim/commit/4a1314cb9c1847dc32ceeb3eebeae123ef10b16e
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
2799 msg_putchar('\n'); |
5788 | 2800 /* FALLTHROUGH to remove the attribute */ |
2801 | |
2802 case ENODATA: | |
2803 /* no attribute of this name */ | |
2804 ret = removexattr((char*)to_file, name); | |
5800 | 2805 /* Silently ignore errors, apparently this happens when |
2806 * smack is not actually being used. */ | |
5788 | 2807 break; |
2808 } | |
2809 } | |
2810 } | |
2811 } | |
2812 #endif /* HAVE_SMACK */ | |
2813 | |
7 | 2814 /* |
2815 * Return a pointer to the ACL of file "fname" in allocated memory. | |
2816 * Return NULL if the ACL is not available for whatever reason. | |
2817 */ | |
2818 vim_acl_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2819 mch_get_acl(char_u *fname UNUSED) |
7 | 2820 { |
2821 vim_acl_T ret = NULL; | |
2822 #ifdef HAVE_POSIX_ACL | |
2823 ret = (vim_acl_T)acl_get_file((char *)fname, ACL_TYPE_ACCESS); | |
2824 #else | |
3330 | 2825 #ifdef HAVE_SOLARIS_ZFS_ACL |
2826 acl_t *aclent; | |
2827 | |
2828 if (acl_get((char *)fname, 0, &aclent) < 0) | |
2829 return NULL; | |
2830 ret = (vim_acl_T)aclent; | |
2831 #else | |
7 | 2832 #ifdef HAVE_SOLARIS_ACL |
2833 vim_acl_solaris_T *aclent; | |
2834 | |
2835 aclent = malloc(sizeof(vim_acl_solaris_T)); | |
2836 if ((aclent->acl_cnt = acl((char *)fname, GETACLCNT, 0, NULL)) < 0) | |
2837 { | |
2838 free(aclent); | |
2839 return NULL; | |
2840 } | |
2841 aclent->acl_entry = malloc(aclent->acl_cnt * sizeof(aclent_t)); | |
2842 if (acl((char *)fname, GETACL, aclent->acl_cnt, aclent->acl_entry) < 0) | |
2843 { | |
2844 free(aclent->acl_entry); | |
2845 free(aclent); | |
2846 return NULL; | |
2847 } | |
2848 ret = (vim_acl_T)aclent; | |
2849 #else | |
2850 #if defined(HAVE_AIX_ACL) | |
2851 int aclsize; | |
2852 struct acl *aclent; | |
2853 | |
2854 aclsize = sizeof(struct acl); | |
2855 aclent = malloc(aclsize); | |
2856 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
2857 { | |
2858 if (errno == ENOSPC) | |
2859 { | |
2860 aclsize = aclent->acl_len; | |
2861 aclent = realloc(aclent, aclsize); | |
2862 if (statacl((char *)fname, STX_NORMAL, aclent, aclsize) < 0) | |
2863 { | |
2864 free(aclent); | |
2865 return NULL; | |
2866 } | |
2867 } | |
2868 else | |
2869 { | |
2870 free(aclent); | |
2871 return NULL; | |
2872 } | |
2873 } | |
2874 ret = (vim_acl_T)aclent; | |
2875 #endif /* HAVE_AIX_ACL */ | |
2876 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 2877 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 2878 #endif /* HAVE_POSIX_ACL */ |
2879 return ret; | |
2880 } | |
2881 | |
2882 /* | |
2883 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
2884 */ | |
2885 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2886 mch_set_acl(char_u *fname UNUSED, vim_acl_T aclent) |
7 | 2887 { |
2888 if (aclent == NULL) | |
2889 return; | |
2890 #ifdef HAVE_POSIX_ACL | |
2891 acl_set_file((char *)fname, ACL_TYPE_ACCESS, (acl_t)aclent); | |
2892 #else | |
3330 | 2893 #ifdef HAVE_SOLARIS_ZFS_ACL |
2894 acl_set((char *)fname, (acl_t *)aclent); | |
2895 #else | |
7 | 2896 #ifdef HAVE_SOLARIS_ACL |
2897 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt, | |
2898 ((vim_acl_solaris_T *)aclent)->acl_entry); | |
2899 #else | |
2900 #ifdef HAVE_AIX_ACL | |
2901 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); | |
2902 #endif /* HAVE_AIX_ACL */ | |
2903 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 2904 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 2905 #endif /* HAVE_POSIX_ACL */ |
2906 } | |
2907 | |
2908 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2909 mch_free_acl(vim_acl_T aclent) |
7 | 2910 { |
2911 if (aclent == NULL) | |
2912 return; | |
2913 #ifdef HAVE_POSIX_ACL | |
2914 acl_free((acl_t)aclent); | |
2915 #else | |
3330 | 2916 #ifdef HAVE_SOLARIS_ZFS_ACL |
2917 acl_free((acl_t *)aclent); | |
2918 #else | |
7 | 2919 #ifdef HAVE_SOLARIS_ACL |
2920 free(((vim_acl_solaris_T *)aclent)->acl_entry); | |
2921 free(aclent); | |
2922 #else | |
2923 #ifdef HAVE_AIX_ACL | |
2924 free(aclent); | |
2925 #endif /* HAVE_AIX_ACL */ | |
2926 #endif /* HAVE_SOLARIS_ACL */ | |
3330 | 2927 #endif /* HAVE_SOLARIS_ZFS_ACL */ |
7 | 2928 #endif /* HAVE_POSIX_ACL */ |
2929 } | |
2930 #endif | |
2931 | |
2932 /* | |
2933 * Set hidden flag for "name". | |
2934 */ | |
2935 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2936 mch_hide(char_u *name UNUSED) |
7 | 2937 { |
2938 /* can't hide a file */ | |
2939 } | |
2940 | |
2941 /* | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2942 * return TRUE if "name" is a directory or a symlink to a directory |
7 | 2943 * return FALSE if "name" is not a directory |
2944 * return FALSE for error | |
2945 */ | |
2946 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2947 mch_isdir(char_u *name) |
7 | 2948 { |
2949 struct stat statb; | |
2950 | |
2951 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ | |
2952 return FALSE; | |
2953 if (stat((char *)name, &statb)) | |
2954 return FALSE; | |
2955 #ifdef _POSIX_SOURCE | |
2956 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); | |
2957 #else | |
2958 return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); | |
2959 #endif | |
2960 } | |
2961 | |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2962 /* |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2963 * 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
|
2964 * 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
|
2965 * return FALSE for error |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2966 */ |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2967 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2968 mch_isrealdir(char_u *name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2969 { |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2970 struct stat statb; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2971 |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2972 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
|
2973 return FALSE; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2974 if (lstat((char *)name, &statb)) |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2975 return FALSE; |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2976 #ifdef _POSIX_SOURCE |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2977 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
|
2978 #else |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2979 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
|
2980 #endif |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2981 } |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
2982 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
2983 static int executable_file(char_u *name); |
7 | 2984 |
2985 /* | |
2986 * Return 1 if "name" is an executable file, 0 if not or it doesn't exist. | |
2987 */ | |
2988 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2989 executable_file(char_u *name) |
7 | 2990 { |
2991 struct stat st; | |
2992 | |
2993 if (stat((char *)name, &st)) | |
2994 return 0; | |
5704 | 2995 #ifdef VMS |
2996 /* Like on Unix system file can have executable rights but not necessarily | |
2997 * be an executable, but on Unix is not a default for an ordianry file to | |
2998 * have an executable flag - on VMS it is in most cases. | |
2999 * Therefore, this check does not have any sense - let keep us to the | |
3000 * conventions instead: | |
3001 * *.COM and *.EXE files are the executables - the rest are not. This is | |
3002 * not ideal but better then it was. | |
3003 */ | |
3004 int vms_executable = 0; | |
3005 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) | |
3006 { | |
3007 if (strstr(vms_tolower((char*)name),".exe") != NULL | |
3008 || strstr(vms_tolower((char*)name),".com")!= NULL) | |
3009 vms_executable = 1; | |
3010 } | |
3011 return vms_executable; | |
3012 #else | |
7 | 3013 return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0; |
5704 | 3014 #endif |
7 | 3015 } |
3016 | |
3017 /* | |
3018 * Return 1 if "name" can be found in $PATH and executed, 0 if not. | |
6695 | 3019 * If "use_path" is FALSE only check if "name" is executable. |
7 | 3020 * Return -1 if unknown. |
3021 */ | |
3022 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3023 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3024 { |
3025 char_u *buf; | |
3026 char_u *p, *e; | |
3027 int retval; | |
3028 | |
6695 | 3029 /* When "use_path" is false and if it's an absolute or relative path don't |
3030 * need to use $PATH. */ | |
3031 if (!use_path || mch_isFullName(name) || (name[0] == '.' | |
3032 && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) | |
5704 | 3033 { |
6695 | 3034 /* There must be a path separator, files in the current directory |
3035 * can't be executed. */ | |
3036 if (gettail(name) != name && executable_file(name)) | |
5782 | 3037 { |
3038 if (path != NULL) | |
3039 { | |
3040 if (name[0] == '.') | |
3041 *path = FullName_save(name, TRUE); | |
3042 else | |
3043 *path = vim_strsave(name); | |
3044 } | |
3045 return TRUE; | |
3046 } | |
3047 return FALSE; | |
5704 | 3048 } |
7 | 3049 |
3050 p = (char_u *)getenv("PATH"); | |
3051 if (p == NULL || *p == NUL) | |
3052 return -1; | |
3053 buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); | |
3054 if (buf == NULL) | |
3055 return -1; | |
3056 | |
3057 /* | |
3058 * Walk through all entries in $PATH to check if "name" exists there and | |
3059 * is an executable file. | |
3060 */ | |
3061 for (;;) | |
3062 { | |
3063 e = (char_u *)strchr((char *)p, ':'); | |
3064 if (e == NULL) | |
3065 e = p + STRLEN(p); | |
3066 if (e - p <= 1) /* empty entry means current dir */ | |
3067 STRCPY(buf, "./"); | |
3068 else | |
3069 { | |
418 | 3070 vim_strncpy(buf, p, e - p); |
7 | 3071 add_pathsep(buf); |
3072 } | |
3073 STRCAT(buf, name); | |
3074 retval = executable_file(buf); | |
3075 if (retval == 1) | |
5782 | 3076 { |
3077 if (path != NULL) | |
3078 { | |
3079 if (buf[0] == '.') | |
3080 *path = FullName_save(buf, TRUE); | |
3081 else | |
3082 *path = vim_strsave(buf); | |
3083 } | |
7 | 3084 break; |
5782 | 3085 } |
7 | 3086 |
3087 if (*e != ':') | |
3088 break; | |
3089 p = e + 1; | |
3090 } | |
3091 | |
3092 vim_free(buf); | |
3093 return retval; | |
3094 } | |
3095 | |
3096 /* | |
3097 * Check what "name" is: | |
3098 * NODE_NORMAL: file or directory (or doesn't exist) | |
3099 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3100 * NODE_OTHER: non-writable things | |
3101 */ | |
3102 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3103 mch_nodetype(char_u *name) |
7 | 3104 { |
3105 struct stat st; | |
3106 | |
3107 if (stat((char *)name, &st)) | |
3108 return NODE_NORMAL; | |
3109 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) | |
3110 return NODE_NORMAL; | |
3111 if (S_ISBLK(st.st_mode)) /* block device isn't writable */ | |
3112 return NODE_OTHER; | |
3113 /* Everything else is writable? */ | |
3114 return NODE_WRITABLE; | |
3115 } | |
3116 | |
3117 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3118 mch_early_init(void) |
7 | 3119 { |
3120 #ifdef HAVE_CHECK_STACK_GROWTH | |
3121 int i; | |
180 | 3122 |
7 | 3123 check_stack_growth((char *)&i); |
3124 | |
180 | 3125 # ifdef HAVE_STACK_LIMIT |
7 | 3126 get_stack_limit(); |
3127 # endif | |
3128 | |
3129 #endif | |
3130 | |
3131 /* | |
3132 * Setup an alternative stack for signals. Helps to catch signals when | |
3133 * running out of stack space. | |
3134 * Use of sigaltstack() is preferred, it's more portable. | |
3135 * Ignore any errors. | |
3136 */ | |
3137 #if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
1737 | 3138 signal_stack = (char *)alloc(SIGSTKSZ); |
7 | 3139 init_signal_stack(); |
3140 #endif | |
3141 } | |
3142 | |
355 | 3143 #if defined(EXITFREE) || defined(PROTO) |
3144 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3145 mch_free_mem(void) |
355 | 3146 { |
359 | 3147 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
3148 if (clip_star.owned) | |
3149 clip_lose_selection(&clip_star); | |
3150 if (clip_plus.owned) | |
3151 clip_lose_selection(&clip_plus); | |
355 | 3152 # endif |
1605 | 3153 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) |
355 | 3154 if (xterm_Shell != (Widget)0) |
3155 XtDestroyWidget(xterm_Shell); | |
1605 | 3156 # ifndef LESSTIF_VERSION |
3157 /* Lesstif crashes here, lose some memory */ | |
355 | 3158 if (xterm_dpy != NULL) |
3159 XtCloseDisplay(xterm_dpy); | |
3160 if (app_context != (XtAppContext)NULL) | |
1605 | 3161 { |
355 | 3162 XtDestroyApplicationContext(app_context); |
1605 | 3163 # ifdef FEAT_X11 |
3164 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ | |
3165 # endif | |
3166 } | |
3167 # endif | |
355 | 3168 # endif |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
3169 # if defined(FEAT_X11) |
1605 | 3170 if (x11_display != NULL |
3171 # ifdef FEAT_XCLIPBOARD | |
3172 && x11_display != xterm_dpy | |
3173 # endif | |
3174 ) | |
359 | 3175 XCloseDisplay(x11_display); |
3176 # endif | |
3177 # if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK) | |
3178 vim_free(signal_stack); | |
3179 signal_stack = NULL; | |
3180 # endif | |
3181 # ifdef FEAT_TITLE | |
3182 vim_free(oldtitle); | |
3183 vim_free(oldicon); | |
3184 # endif | |
355 | 3185 } |
3186 #endif | |
3187 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
3188 static void exit_scroll(void); |
7 | 3189 |
3190 /* | |
3191 * Output a newline when exiting. | |
3192 * Make sure the newline goes to the same stream as the text. | |
3193 */ | |
3194 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3195 exit_scroll(void) |
7 | 3196 { |
167 | 3197 if (silent_mode) |
3198 return; | |
7 | 3199 if (newline_on_exit || msg_didout) |
3200 { | |
3201 if (msg_use_printf()) | |
3202 { | |
3203 if (info_message) | |
3204 mch_msg("\n"); | |
3205 else | |
3206 mch_errmsg("\r\n"); | |
3207 } | |
3208 else | |
3209 out_char('\n'); | |
3210 } | |
3211 else | |
3212 { | |
3213 restore_cterm_colors(); /* get original colors back */ | |
3214 msg_clr_eos_force(); /* clear the rest of the display */ | |
3215 windgoto((int)Rows - 1, 0); /* may have moved the cursor */ | |
3216 } | |
3217 } | |
3218 | |
3219 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3220 mch_exit(int r) |
7 | 3221 { |
3222 exiting = TRUE; | |
3223 | |
3224 #if defined(FEAT_X11) && defined(FEAT_CLIPBOARD) | |
3225 x11_export_final_selection(); | |
3226 #endif | |
3227 | |
3228 #ifdef FEAT_GUI | |
3229 if (!gui.in_use) | |
3230 #endif | |
3231 { | |
3232 settmode(TMODE_COOK); | |
3233 #ifdef FEAT_TITLE | |
3234 mch_restore_title(3); /* restore xterm title and icon name */ | |
3235 #endif | |
3236 /* | |
3237 * When t_ti is not empty but it doesn't cause swapping terminal | |
3238 * pages, need to output a newline when msg_didout is set. But when | |
3239 * t_ti does swap pages it should not go to the shell page. Do this | |
3240 * before stoptermcap(). | |
3241 */ | |
3242 if (swapping_screen() && !newline_on_exit) | |
3243 exit_scroll(); | |
3244 | |
3245 /* Stop termcap: May need to check for T_CRV response, which | |
3246 * requires RAW mode. */ | |
3247 stoptermcap(); | |
3248 | |
3249 /* | |
3250 * A newline is only required after a message in the alternate screen. | |
3251 * This is set to TRUE by wait_return(). | |
3252 */ | |
3253 if (!swapping_screen() || newline_on_exit) | |
3254 exit_scroll(); | |
3255 | |
3256 /* Cursor may have been switched off without calling starttermcap() | |
3257 * when doing "vim -u vimrc" and vimrc contains ":q". */ | |
3258 if (full_screen) | |
3259 cursor_on(); | |
3260 } | |
3261 out_flush(); | |
3262 ml_close_all(TRUE); /* remove all memfiles */ | |
3263 may_core_dump(); | |
3264 #ifdef FEAT_GUI | |
3265 if (gui.in_use) | |
3266 gui_exit(r); | |
3267 #endif | |
167 | 3268 |
765 | 3269 #ifdef MACOS_CONVERT |
167 | 3270 mac_conv_cleanup(); |
3271 #endif | |
3272 | |
7 | 3273 #ifdef __QNX__ |
3274 /* A core dump won't be created if the signal handler | |
3275 * doesn't return, so we can't call exit() */ | |
3276 if (deadly_signal != 0) | |
3277 return; | |
3278 #endif | |
3279 | |
33 | 3280 #ifdef FEAT_NETBEANS_INTG |
2210 | 3281 netbeans_send_disconnect(); |
33 | 3282 #endif |
355 | 3283 |
3284 #ifdef EXITFREE | |
3285 free_all_mem(); | |
3286 #endif | |
3287 | |
7 | 3288 exit(r); |
3289 } | |
3290 | |
3291 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3292 may_core_dump(void) |
7 | 3293 { |
3294 if (deadly_signal != 0) | |
3295 { | |
3296 signal(deadly_signal, SIG_DFL); | |
3297 kill(getpid(), deadly_signal); /* Die using the signal we caught */ | |
3298 } | |
3299 } | |
3300 | |
3301 #ifndef VMS | |
3302 | |
3303 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3304 mch_settmode(int tmode) |
7 | 3305 { |
3306 static int first = TRUE; | |
3307 | |
3308 /* Why is NeXT excluded here (and not in os_unixx.h)? */ | |
3309 #if defined(ECHOE) && defined(ICANON) && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) && !defined(__NeXT__) | |
3310 /* | |
3311 * for "new" tty systems | |
3312 */ | |
3313 # ifdef HAVE_TERMIOS_H | |
3314 static struct termios told; | |
3315 struct termios tnew; | |
3316 # else | |
3317 static struct termio told; | |
3318 struct termio tnew; | |
3319 # endif | |
3320 | |
3321 if (first) | |
3322 { | |
3323 first = FALSE; | |
3324 # if defined(HAVE_TERMIOS_H) | |
3325 tcgetattr(read_cmd_fd, &told); | |
3326 # else | |
3327 ioctl(read_cmd_fd, TCGETA, &told); | |
3328 # endif | |
3329 } | |
3330 | |
3331 tnew = told; | |
3332 if (tmode == TMODE_RAW) | |
3333 { | |
3334 /* | |
3335 * ~ICRNL enables typing ^V^M | |
3336 */ | |
3337 tnew.c_iflag &= ~ICRNL; | |
3338 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE | |
3339 # if defined(IEXTEN) && !defined(__MINT__) | |
3340 | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ | |
3341 /* but it breaks function keys on MINT */ | |
3342 # endif | |
3343 ); | |
3344 # ifdef ONLCR /* don't map NL -> CR NL, we do it ourselves */ | |
3345 tnew.c_oflag &= ~ONLCR; | |
3346 # endif | |
3347 tnew.c_cc[VMIN] = 1; /* return after 1 char */ | |
3348 tnew.c_cc[VTIME] = 0; /* don't wait */ | |
3349 } | |
3350 else if (tmode == TMODE_SLEEP) | |
3351 tnew.c_lflag &= ~(ECHO); | |
3352 | |
3353 # if defined(HAVE_TERMIOS_H) | |
3354 { | |
3355 int n = 10; | |
3356 | |
3357 /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a | |
3358 * few times. */ | |
3359 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 | |
3360 && errno == EINTR && n > 0) | |
3361 --n; | |
3362 } | |
3363 # else | |
3364 ioctl(read_cmd_fd, TCSETA, &tnew); | |
3365 # endif | |
3366 | |
3367 #else | |
3368 | |
3369 /* | |
3370 * for "old" tty systems | |
3371 */ | |
3372 # ifndef TIOCSETN | |
3373 # define TIOCSETN TIOCSETP /* for hpux 9.0 */ | |
3374 # endif | |
3375 static struct sgttyb ttybold; | |
3376 struct sgttyb ttybnew; | |
3377 | |
3378 if (first) | |
3379 { | |
3380 first = FALSE; | |
3381 ioctl(read_cmd_fd, TIOCGETP, &ttybold); | |
3382 } | |
3383 | |
3384 ttybnew = ttybold; | |
3385 if (tmode == TMODE_RAW) | |
3386 { | |
3387 ttybnew.sg_flags &= ~(CRMOD | ECHO); | |
3388 ttybnew.sg_flags |= RAW; | |
3389 } | |
3390 else if (tmode == TMODE_SLEEP) | |
3391 ttybnew.sg_flags &= ~(ECHO); | |
3392 ioctl(read_cmd_fd, TIOCSETN, &ttybnew); | |
3393 #endif | |
3394 curr_tmode = tmode; | |
3395 } | |
3396 | |
3397 /* | |
3398 * Try to get the code for "t_kb" from the stty setting | |
3399 * | |
3400 * Even if termcap claims a backspace key, the user's setting *should* | |
3401 * prevail. stty knows more about reality than termcap does, and if | |
3402 * somebody's usual erase key is DEL (which, for most BSD users, it will | |
3403 * be), they're going to get really annoyed if their erase key starts | |
3404 * doing forward deletes for no reason. (Eric Fischer) | |
3405 */ | |
3406 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3407 get_stty(void) |
7 | 3408 { |
3409 char_u buf[2]; | |
3410 char_u *p; | |
3411 | |
3412 /* Why is NeXT excluded here (and not in os_unixx.h)? */ | |
3413 #if defined(ECHOE) && defined(ICANON) && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) && !defined(__NeXT__) | |
3414 /* for "new" tty systems */ | |
3415 # ifdef HAVE_TERMIOS_H | |
3416 struct termios keys; | |
3417 # else | |
3418 struct termio keys; | |
3419 # endif | |
3420 | |
3421 # if defined(HAVE_TERMIOS_H) | |
3422 if (tcgetattr(read_cmd_fd, &keys) != -1) | |
3423 # else | |
3424 if (ioctl(read_cmd_fd, TCGETA, &keys) != -1) | |
3425 # endif | |
3426 { | |
3427 buf[0] = keys.c_cc[VERASE]; | |
3428 intr_char = keys.c_cc[VINTR]; | |
3429 #else | |
3430 /* for "old" tty systems */ | |
3431 struct sgttyb keys; | |
3432 | |
3433 if (ioctl(read_cmd_fd, TIOCGETP, &keys) != -1) | |
3434 { | |
3435 buf[0] = keys.sg_erase; | |
3436 intr_char = keys.sg_kill; | |
3437 #endif | |
3438 buf[1] = NUL; | |
3439 add_termcode((char_u *)"kb", buf, FALSE); | |
3440 | |
3441 /* | |
3442 * If <BS> and <DEL> are now the same, redefine <DEL>. | |
3443 */ | |
3444 p = find_termcode((char_u *)"kD"); | |
3445 if (p != NULL && p[0] == buf[0] && p[1] == buf[1]) | |
3446 do_fixdel(NULL); | |
3447 } | |
3448 #if 0 | |
3449 } /* to keep cindent happy */ | |
3450 #endif | |
3451 } | |
3452 | |
3453 #endif /* VMS */ | |
3454 | |
3455 #if defined(FEAT_MOUSE_TTY) || defined(PROTO) | |
3456 /* | |
3457 * Set mouse clicks on or off. | |
3458 */ | |
3459 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3460 mch_setmouse(int on) |
7 | 3461 { |
3462 static int ison = FALSE; | |
3463 int xterm_mouse_vers; | |
3464 | |
3465 if (on == ison) /* return quickly if nothing to do */ | |
3466 return; | |
3467 | |
3468 xterm_mouse_vers = use_xterm_mouse(); | |
3145 | 3469 |
3470 # ifdef FEAT_MOUSE_URXVT | |
3746 | 3471 if (ttym_flags == TTYM_URXVT) |
3472 { | |
3145 | 3473 out_str_nf((char_u *) |
3474 (on | |
3475 ? IF_EB("\033[?1015h", ESC_STR "[?1015h") | |
3476 : IF_EB("\033[?1015l", ESC_STR "[?1015l"))); | |
3477 ison = on; | |
3478 } | |
3479 # endif | |
3480 | |
3746 | 3481 # ifdef FEAT_MOUSE_SGR |
3482 if (ttym_flags == TTYM_SGR) | |
3483 { | |
3484 out_str_nf((char_u *) | |
3485 (on | |
3486 ? IF_EB("\033[?1006h", ESC_STR "[?1006h") | |
3487 : IF_EB("\033[?1006l", ESC_STR "[?1006l"))); | |
3488 ison = on; | |
3489 } | |
3490 # endif | |
3491 | |
7 | 3492 if (xterm_mouse_vers > 0) |
3493 { | |
3494 if (on) /* enable mouse events, use mouse tracking if available */ | |
3495 out_str_nf((char_u *) | |
3496 (xterm_mouse_vers > 1 | |
3497 ? IF_EB("\033[?1002h", ESC_STR "[?1002h") | |
3498 : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); | |
3499 else /* disable mouse events, could probably always send the same */ | |
3500 out_str_nf((char_u *) | |
3501 (xterm_mouse_vers > 1 | |
3502 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") | |
3503 : IF_EB("\033[?1000l", ESC_STR "[?1000l"))); | |
3504 ison = on; | |
3505 } | |
3506 | |
3507 # ifdef FEAT_MOUSE_DEC | |
3508 else if (ttym_flags == TTYM_DEC) | |
3509 { | |
3510 if (on) /* enable mouse events */ | |
3511 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); | |
3512 else /* disable mouse events */ | |
3513 out_str_nf((char_u *)"\033['z"); | |
3514 ison = on; | |
3515 } | |
3516 # endif | |
3517 | |
3518 # ifdef FEAT_MOUSE_GPM | |
3519 else | |
3520 { | |
3521 if (on) | |
3522 { | |
3523 if (gpm_open()) | |
3524 ison = TRUE; | |
3525 } | |
3526 else | |
3527 { | |
3528 gpm_close(); | |
3529 ison = FALSE; | |
3530 } | |
3531 } | |
3532 # endif | |
3533 | |
1620 | 3534 # ifdef FEAT_SYSMOUSE |
3535 else | |
3536 { | |
3537 if (on) | |
3538 { | |
3539 if (sysmouse_open() == OK) | |
3540 ison = TRUE; | |
3541 } | |
3542 else | |
3543 { | |
3544 sysmouse_close(); | |
3545 ison = FALSE; | |
3546 } | |
3547 } | |
3548 # endif | |
3549 | |
7 | 3550 # ifdef FEAT_MOUSE_JSB |
3551 else | |
3552 { | |
3553 if (on) | |
3554 { | |
3555 /* D - Enable Mouse up/down messages | |
3556 * L - Enable Left Button Reporting | |
3557 * M - Enable Middle Button Reporting | |
3558 * R - Enable Right Button Reporting | |
3559 * K - Enable SHIFT and CTRL key Reporting | |
3560 * + - Enable Advanced messaging of mouse moves and up/down messages | |
3561 * Q - Quiet No Ack | |
3562 * # - Numeric value of mouse pointer required | |
3563 * 0 = Multiview 2000 cursor, used as standard | |
3564 * 1 = Windows Arrow | |
3565 * 2 = Windows I Beam | |
3566 * 3 = Windows Hour Glass | |
3567 * 4 = Windows Cross Hair | |
3568 * 5 = Windows UP Arrow | |
3569 */ | |
4299 | 3570 # ifdef JSBTERM_MOUSE_NONADVANCED |
3571 /* Disables full feedback of pointer movements */ | |
7 | 3572 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", |
3573 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); | |
4299 | 3574 # else |
7 | 3575 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\", |
3576 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\")); | |
4299 | 3577 # endif |
7 | 3578 ison = TRUE; |
3579 } | |
3580 else | |
3581 { | |
3582 out_str_nf((char_u *)IF_EB("\033[0~ZwQ\033\\", | |
3583 ESC_STR "[0~ZwQ" ESC_STR "\\")); | |
3584 ison = FALSE; | |
3585 } | |
3586 } | |
3587 # endif | |
3588 # ifdef FEAT_MOUSE_PTERM | |
3589 else | |
3590 { | |
3591 /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ | |
3592 if (on) | |
3593 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); | |
3594 else | |
3595 out_str_nf("\033[>1l\033[>6l\033[>7l\033[>1l\033[>9h"); | |
3596 ison = on; | |
3597 } | |
3598 # endif | |
3599 } | |
3600 | |
3601 /* | |
3602 * Set the mouse termcode, depending on the 'term' and 'ttymouse' options. | |
3603 */ | |
3604 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3605 check_mouse_termcode(void) |
7 | 3606 { |
3607 # ifdef FEAT_MOUSE_XTERM | |
3608 if (use_xterm_mouse() | |
3145 | 3609 # ifdef FEAT_MOUSE_URXVT |
3610 && use_xterm_mouse() != 3 | |
3611 # endif | |
7 | 3612 # ifdef FEAT_GUI |
3613 && !gui.in_use | |
3614 # endif | |
3615 ) | |
3616 { | |
3617 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
180 | 3618 ? IF_EB("\233M", CSI_STR "M") |
3619 : IF_EB("\033[M", ESC_STR "[M"))); | |
7 | 3620 if (*p_mouse != NUL) |
3621 { | |
3622 /* force mouse off and maybe on to send possibly new mouse | |
3623 * activation sequence to the xterm, with(out) drag tracing. */ | |
3624 mch_setmouse(FALSE); | |
3625 setmouse(); | |
3626 } | |
3627 } | |
3628 else | |
3629 del_mouse_termcode(KS_MOUSE); | |
3630 # endif | |
3631 | |
3632 # ifdef FEAT_MOUSE_GPM | |
3633 if (!use_xterm_mouse() | |
3634 # ifdef FEAT_GUI | |
3635 && !gui.in_use | |
3636 # endif | |
3637 ) | |
3638 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MG", ESC_STR "MG")); | |
3639 # endif | |
3640 | |
1620 | 3641 # ifdef FEAT_SYSMOUSE |
3642 if (!use_xterm_mouse() | |
3643 # ifdef FEAT_GUI | |
3644 && !gui.in_use | |
3645 # endif | |
3646 ) | |
3647 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS")); | |
3648 # endif | |
3649 | |
7 | 3650 # ifdef FEAT_MOUSE_JSB |
6102 | 3651 /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ |
7 | 3652 if (!use_xterm_mouse() |
3653 # ifdef FEAT_GUI | |
3654 && !gui.in_use | |
3655 # endif | |
3656 ) | |
3657 set_mouse_termcode(KS_JSBTERM_MOUSE, | |
3658 (char_u *)IF_EB("\033[0~zw", ESC_STR "[0~zw")); | |
3659 else | |
3660 del_mouse_termcode(KS_JSBTERM_MOUSE); | |
3661 # endif | |
3662 | |
3663 # ifdef FEAT_MOUSE_NET | |
180 | 3664 /* There is no conflict, but one may type "ESC }" from Insert mode. Don't |
7 | 3665 * define it in the GUI or when using an xterm. */ |
3666 if (!use_xterm_mouse() | |
3667 # ifdef FEAT_GUI | |
3668 && !gui.in_use | |
3669 # endif | |
3670 ) | |
3671 set_mouse_termcode(KS_NETTERM_MOUSE, | |
3672 (char_u *)IF_EB("\033}", ESC_STR "}")); | |
3673 else | |
3674 del_mouse_termcode(KS_NETTERM_MOUSE); | |
3675 # endif | |
3676 | |
3677 # ifdef FEAT_MOUSE_DEC | |
6102 | 3678 /* Conflicts with xterm mouse: "\033[" and "\033[M" */ |
5932 | 3679 if (!use_xterm_mouse() |
7 | 3680 # ifdef FEAT_GUI |
3681 && !gui.in_use | |
3682 # endif | |
3683 ) | |
180 | 3684 set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME) |
3685 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); | |
7 | 3686 else |
3687 del_mouse_termcode(KS_DEC_MOUSE); | |
3688 # endif | |
3689 # ifdef FEAT_MOUSE_PTERM | |
6102 | 3690 /* same conflict as the dec mouse */ |
5932 | 3691 if (!use_xterm_mouse() |
7 | 3692 # ifdef FEAT_GUI |
3693 && !gui.in_use | |
3694 # endif | |
3695 ) | |
3696 set_mouse_termcode(KS_PTERM_MOUSE, | |
3697 (char_u *) IF_EB("\033[", ESC_STR "[")); | |
3698 else | |
3699 del_mouse_termcode(KS_PTERM_MOUSE); | |
3700 # endif | |
3145 | 3701 # ifdef FEAT_MOUSE_URXVT |
6102 | 3702 /* same conflict as the dec mouse */ |
5932 | 3703 if (use_xterm_mouse() == 3 |
3145 | 3704 # ifdef FEAT_GUI |
3705 && !gui.in_use | |
3706 # endif | |
3707 ) | |
3708 { | |
3709 set_mouse_termcode(KS_URXVT_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
3710 ? IF_EB("\233", CSI_STR) | |
3711 : IF_EB("\033[", ESC_STR "["))); | |
3712 | |
3713 if (*p_mouse != NUL) | |
3714 { | |
3715 mch_setmouse(FALSE); | |
3716 setmouse(); | |
3717 } | |
3718 } | |
3719 else | |
3720 del_mouse_termcode(KS_URXVT_MOUSE); | |
3721 # endif | |
3746 | 3722 # ifdef FEAT_MOUSE_SGR |
5905 | 3723 /* There is no conflict with xterm mouse */ |
3746 | 3724 if (use_xterm_mouse() == 4 |
3725 # ifdef FEAT_GUI | |
3726 && !gui.in_use | |
3727 # endif | |
3728 ) | |
3729 { | |
3730 set_mouse_termcode(KS_SGR_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
3731 ? IF_EB("\233<", CSI_STR "<") | |
3732 : IF_EB("\033[<", ESC_STR "[<"))); | |
3733 | |
3734 if (*p_mouse != NUL) | |
3735 { | |
3736 mch_setmouse(FALSE); | |
3737 setmouse(); | |
3738 } | |
3739 } | |
3740 else | |
3741 del_mouse_termcode(KS_SGR_MOUSE); | |
3742 # endif | |
7 | 3743 } |
3744 #endif | |
3745 | |
3746 /* | |
3747 * set screen mode, always fails. | |
3748 */ | |
3749 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3750 mch_screenmode(char_u *arg UNUSED) |
7 | 3751 { |
3752 EMSG(_(e_screenmode)); | |
3753 return FAIL; | |
3754 } | |
3755 | |
3756 #ifndef VMS | |
3757 | |
3758 /* | |
3759 * Try to get the current window size: | |
3760 * 1. with an ioctl(), most accurate method | |
3761 * 2. from the environment variables LINES and COLUMNS | |
3762 * 3. from the termcap | |
3763 * 4. keep using the old values | |
3764 * Return OK when size could be determined, FAIL otherwise. | |
3765 */ | |
3766 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3767 mch_get_shellsize(void) |
7 | 3768 { |
3769 long rows = 0; | |
3770 long columns = 0; | |
3771 char_u *p; | |
3772 | |
3773 /* | |
3774 * For OS/2 use _scrsize(). | |
3775 */ | |
3776 # ifdef __EMX__ | |
3777 { | |
3778 int s[2]; | |
3779 | |
3780 _scrsize(s); | |
3781 columns = s[0]; | |
3782 rows = s[1]; | |
3783 } | |
3784 # endif | |
3785 | |
3786 /* | |
3787 * 1. try using an ioctl. It is the most accurate method. | |
3788 * | |
3789 * Try using TIOCGWINSZ first, some systems that have it also define | |
3790 * TIOCGSIZE but don't have a struct ttysize. | |
3791 */ | |
3792 # ifdef TIOCGWINSZ | |
3793 { | |
3794 struct winsize ws; | |
3795 int fd = 1; | |
3796 | |
3797 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
3798 if (!isatty(fd) && isatty(read_cmd_fd)) | |
3799 fd = read_cmd_fd; | |
3800 if (ioctl(fd, TIOCGWINSZ, &ws) == 0) | |
3801 { | |
3802 columns = ws.ws_col; | |
3803 rows = ws.ws_row; | |
3804 } | |
3805 } | |
3806 # else /* TIOCGWINSZ */ | |
3807 # ifdef TIOCGSIZE | |
3808 { | |
3809 struct ttysize ts; | |
3810 int fd = 1; | |
3811 | |
3812 /* When stdout is not a tty, use stdin for the ioctl(). */ | |
3813 if (!isatty(fd) && isatty(read_cmd_fd)) | |
3814 fd = read_cmd_fd; | |
3815 if (ioctl(fd, TIOCGSIZE, &ts) == 0) | |
3816 { | |
3817 columns = ts.ts_cols; | |
3818 rows = ts.ts_lines; | |
3819 } | |
3820 } | |
3821 # endif /* TIOCGSIZE */ | |
3822 # endif /* TIOCGWINSZ */ | |
3823 | |
3824 /* | |
3825 * 2. get size from environment | |
164 | 3826 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules |
3827 * the ioctl() values! | |
7 | 3828 */ |
164 | 3829 if (columns == 0 || rows == 0 || vim_strchr(p_cpo, CPO_TSIZE) != NULL) |
7 | 3830 { |
3831 if ((p = (char_u *)getenv("LINES"))) | |
3832 rows = atoi((char *)p); | |
3833 if ((p = (char_u *)getenv("COLUMNS"))) | |
3834 columns = atoi((char *)p); | |
3835 } | |
3836 | |
3837 #ifdef HAVE_TGETENT | |
3838 /* | |
3839 * 3. try reading "co" and "li" entries from termcap | |
3840 */ | |
3841 if (columns == 0 || rows == 0) | |
3842 getlinecol(&columns, &rows); | |
3843 #endif | |
3844 | |
3845 /* | |
3846 * 4. If everything fails, use the old values | |
3847 */ | |
3848 if (columns <= 0 || rows <= 0) | |
3849 return FAIL; | |
3850 | |
3851 Rows = rows; | |
3852 Columns = columns; | |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
3853 limit_screen_size(); |
7 | 3854 return OK; |
3855 } | |
3856 | |
3857 /* | |
3858 * Try to set the window size to Rows and Columns. | |
3859 */ | |
3860 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3861 mch_set_shellsize(void) |
7 | 3862 { |
3863 if (*T_CWS) | |
3864 { | |
3865 /* | |
3866 * NOTE: if you get an error here that term_set_winsize() is | |
3867 * undefined, check the output of configure. It could probably not | |
3868 * find a ncurses, termcap or termlib library. | |
3869 */ | |
3870 term_set_winsize((int)Rows, (int)Columns); | |
3871 out_flush(); | |
3872 screen_start(); /* don't know where cursor is now */ | |
3873 } | |
3874 } | |
3875 | |
3876 #endif /* VMS */ | |
3877 | |
3878 /* | |
3879 * Rows and/or Columns has changed. | |
3880 */ | |
3881 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3882 mch_new_shellsize(void) |
7 | 3883 { |
3884 /* Nothing to do. */ | |
3885 } | |
3886 | |
3048 | 3887 /* |
3888 * Wait for process "child" to end. | |
3889 * Return "child" if it exited properly, <= 0 on error. | |
3890 */ | |
3891 static pid_t | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3892 wait4pid(pid_t child, waitstatus *status) |
3048 | 3893 { |
3894 pid_t wait_pid = 0; | |
3895 | |
3896 while (wait_pid != child) | |
3897 { | |
3470 | 3898 /* When compiled with Python threads are probably used, in which case |
3899 * wait() sometimes hangs for no obvious reason. Use waitpid() | |
3900 * instead and loop (like the GUI). Also needed for other interfaces, | |
3901 * they might call system(). */ | |
3902 # ifdef __NeXT__ | |
3048 | 3903 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); |
3470 | 3904 # else |
3048 | 3905 wait_pid = waitpid(child, status, WNOHANG); |
3470 | 3906 # endif |
3048 | 3907 if (wait_pid == 0) |
3908 { | |
4074 | 3909 /* Wait for 10 msec before trying again. */ |
3048 | 3910 mch_delay(10L, TRUE); |
3911 continue; | |
3912 } | |
3913 if (wait_pid <= 0 | |
3914 # ifdef ECHILD | |
3915 && errno == ECHILD | |
3916 # endif | |
3917 ) | |
3918 break; | |
3919 } | |
3920 return wait_pid; | |
3921 } | |
3922 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3923 #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
|
3924 /* |
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
3925 * 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
|
3926 * "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
|
3927 * Returns FAIL when out of memory. |
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
3928 */ |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3929 int |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3930 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
|
3931 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3932 int i; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3933 char_u *p; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3934 int inquote; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3935 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3936 /* |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3937 * Do this loop twice: |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3938 * 1: find number of arguments |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3939 * 2: separate them and build argv[] |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3940 */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3941 for (i = 0; i < 2; ++i) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3942 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3943 p = cmd; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3944 inquote = FALSE; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3945 *argc = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3946 for (;;) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3947 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3948 if (i == 1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3949 (*argv)[*argc] = (char *)p; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3950 ++*argc; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3951 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
|
3952 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3953 if (*p == '"') |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3954 inquote = !inquote; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3955 ++p; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3956 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3957 if (*p == NUL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3958 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3959 if (i == 1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3960 *p++ = NUL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3961 p = skipwhite(p); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3962 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3963 if (*argv == NULL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3964 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3965 if (use_shcf) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3966 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3967 /* 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
|
3968 p = p_shcf; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3969 for (;;) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3970 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3971 p = skiptowhite(p); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3972 if (*p == NUL) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3973 break; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3974 ++*argc; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3975 p = skipwhite(p); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3976 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3977 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3978 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3979 *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
|
3980 if (*argv == NULL) /* out of memory */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3981 return FAIL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3982 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3983 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3984 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3985 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3986 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
3987 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
3988 #if !defined(USE_SYSTEM) || defined(FEAT_JOB_CHANNEL) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3989 static void |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3990 set_child_environment(void) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3991 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3992 # ifdef HAVE_SETENV |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3993 char envbuf[50]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3994 # else |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3995 static char envbuf_Rows[20]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3996 static char envbuf_Columns[20]; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3997 # endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3998 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
3999 /* Simulate to have a dumb terminal (for now) */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4000 # ifdef HAVE_SETENV |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4001 setenv("TERM", "dumb", 1); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4002 sprintf((char *)envbuf, "%ld", Rows); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4003 setenv("ROWS", (char *)envbuf, 1); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4004 sprintf((char *)envbuf, "%ld", Rows); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4005 setenv("LINES", (char *)envbuf, 1); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4006 sprintf((char *)envbuf, "%ld", Columns); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4007 setenv("COLUMNS", (char *)envbuf, 1); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4008 # else |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4009 /* |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4010 * 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
|
4011 * Use a static array to avoid losing allocated memory. |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4012 */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4013 putenv("TERM=dumb"); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4014 sprintf(envbuf_Rows, "ROWS=%ld", Rows); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4015 putenv(envbuf_Rows); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4016 sprintf(envbuf_Rows, "LINES=%ld", Rows); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4017 putenv(envbuf_Rows); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4018 sprintf(envbuf_Columns, "COLUMNS=%ld", Columns); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4019 putenv(envbuf_Columns); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4020 # endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4021 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4022 #endif |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4023 |
7 | 4024 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4025 mch_call_shell( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4026 char_u *cmd, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4027 int options) /* SHELL_*, see vim.h */ |
7 | 4028 { |
4029 #ifdef VMS | |
4030 char *ifn = NULL; | |
4031 char *ofn = NULL; | |
4032 #endif | |
4033 int tmode = cur_tmode; | |
4034 #ifdef USE_SYSTEM /* use system() to start the shell: simple but slow */ | |
4035 int x; | |
4036 # ifndef __EMX__ | |
4037 char_u *newcmd; /* only needed for unix */ | |
4038 # else | |
4039 /* | |
4040 * Set the preferred shell in the EMXSHELL environment variable (but | |
4041 * only if it is different from what is already in the environment). | |
4042 * Emx then takes care of whether to use "/c" or "-c" in an | |
4043 * intelligent way. Simply pass the whole thing to emx's system() call. | |
4044 * Emx also starts an interactive shell if system() is passed an empty | |
4045 * string. | |
4046 */ | |
4047 char_u *p, *old; | |
4048 | |
4049 if (((old = (char_u *)getenv("EMXSHELL")) == NULL) || STRCMP(old, p_sh)) | |
4050 { | |
4051 /* should check HAVE_SETENV, but I know we don't have it. */ | |
4052 p = alloc(10 + strlen(p_sh)); | |
4053 if (p) | |
4054 { | |
4055 sprintf((char *)p, "EMXSHELL=%s", p_sh); | |
4056 putenv((char *)p); /* don't free the pointer! */ | |
4057 } | |
4058 } | |
4059 # endif | |
4060 | |
4061 out_flush(); | |
4062 | |
4063 if (options & SHELL_COOKED) | |
4064 settmode(TMODE_COOK); /* set to normal mode */ | |
4065 | |
2586 | 4066 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4209 | 4067 save_clipboard(); |
2586 | 4068 loose_clipboard(); |
4069 # endif | |
4070 | |
7 | 4071 # ifdef __EMX__ |
4072 if (cmd == NULL) | |
4073 x = system(""); /* this starts an interactive shell in emx */ | |
4074 else | |
4075 x = system((char *)cmd); | |
4076 /* system() returns -1 when error occurs in starting shell */ | |
4077 if (x == -1 && !emsg_silent) | |
4078 { | |
4079 MSG_PUTS(_("\nCannot execute shell ")); | |
4080 msg_outtrans(p_sh); | |
4081 msg_putchar('\n'); | |
4082 } | |
4083 # else /* not __EMX__ */ | |
4084 if (cmd == NULL) | |
4085 x = system((char *)p_sh); | |
4086 else | |
4087 { | |
4088 # ifdef VMS | |
4089 if (ofn = strchr((char *)cmd, '>')) | |
4090 *ofn++ = '\0'; | |
4091 if (ifn = strchr((char *)cmd, '<')) | |
4092 { | |
4093 char *p; | |
4094 | |
4095 *ifn++ = '\0'; | |
4096 p = strchr(ifn,' '); /* chop off any trailing spaces */ | |
4097 if (p) | |
4098 *p = '\0'; | |
4099 } | |
4100 if (ofn) | |
4101 x = vms_sys((char *)cmd, ofn, ifn); | |
4102 else | |
4103 x = system((char *)cmd); | |
4104 # else | |
4105 newcmd = lalloc(STRLEN(p_sh) | |
4106 + (extra_shell_arg == NULL ? 0 : STRLEN(extra_shell_arg)) | |
4107 + STRLEN(p_shcf) + STRLEN(cmd) + 4, TRUE); | |
4108 if (newcmd == NULL) | |
4109 x = 0; | |
4110 else | |
4111 { | |
4112 sprintf((char *)newcmd, "%s %s %s %s", p_sh, | |
4113 extra_shell_arg == NULL ? "" : (char *)extra_shell_arg, | |
4114 (char *)p_shcf, | |
4115 (char *)cmd); | |
4116 x = system((char *)newcmd); | |
4117 vim_free(newcmd); | |
4118 } | |
4119 # endif | |
4120 } | |
4121 # ifdef VMS | |
4122 x = vms_sys_status(x); | |
4123 # endif | |
4124 if (emsg_silent) | |
4125 ; | |
4126 else if (x == 127) | |
4127 MSG_PUTS(_("\nCannot execute shell sh\n")); | |
4128 # endif /* __EMX__ */ | |
4129 else if (x && !(options & SHELL_SILENT)) | |
4130 { | |
4131 MSG_PUTS(_("\nshell returned ")); | |
4132 msg_outnum((long)x); | |
4133 msg_putchar('\n'); | |
4134 } | |
4135 | |
4136 if (tmode == TMODE_RAW) | |
4137 settmode(TMODE_RAW); /* set to raw mode */ | |
4138 # ifdef FEAT_TITLE | |
4139 resettitle(); | |
4140 # endif | |
4209 | 4141 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
4142 restore_clipboard(); | |
4143 # endif | |
7 | 4144 return x; |
4145 | |
4146 #else /* USE_SYSTEM */ /* don't use system(), use fork()/exec() */ | |
4147 | |
167 | 4148 # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use |
4149 127, some shells use that already */ | |
7 | 4150 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4151 char_u *newcmd; |
7 | 4152 pid_t pid; |
167 | 4153 pid_t wpid = 0; |
7 | 4154 pid_t wait_pid = 0; |
4155 # ifdef HAVE_UNION_WAIT | |
4156 union wait status; | |
4157 # else | |
4158 int status = -1; | |
4159 # endif | |
4160 int retval = -1; | |
4161 char **argv = NULL; | |
4162 int argc; | |
2994 | 4163 char_u *p_shcf_copy = NULL; |
7 | 4164 int i; |
4165 char_u *p; | |
167 | 4166 int pty_master_fd = -1; /* for pty's */ |
7 | 4167 # ifdef FEAT_GUI |
4168 int pty_slave_fd = -1; | |
4169 char *tty_name; | |
167 | 4170 # endif |
602 | 4171 int fd_toshell[2]; /* for pipes */ |
7 | 4172 int fd_fromshell[2]; |
4173 int pipe_error = FALSE; | |
602 | 4174 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ |
7 | 4175 |
2586 | 4176 newcmd = vim_strsave(p_sh); |
4177 if (newcmd == NULL) /* out of memory */ | |
4178 goto error; | |
4179 | |
7 | 4180 out_flush(); |
4181 if (options & SHELL_COOKED) | |
4182 settmode(TMODE_COOK); /* set to normal mode */ | |
4183 | |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4184 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
|
4185 goto error; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
4186 |
7 | 4187 if (cmd != NULL) |
4188 { | |
3263 | 4189 char_u *s; |
4190 | |
7 | 4191 if (extra_shell_arg != NULL) |
4192 argv[argc++] = (char *)extra_shell_arg; | |
2994 | 4193 |
4194 /* Break 'shellcmdflag' into white separated parts. This doesn't | |
4195 * handle quoted strings, they are very unlikely to appear. */ | |
4196 p_shcf_copy = alloc((unsigned)STRLEN(p_shcf) + 1); | |
4197 if (p_shcf_copy == NULL) /* out of memory */ | |
4198 goto error; | |
4199 s = p_shcf_copy; | |
4200 p = p_shcf; | |
4201 while (*p != NUL) | |
4202 { | |
4203 argv[argc++] = (char *)s; | |
4204 while (*p && *p != ' ' && *p != TAB) | |
4205 *s++ = *p++; | |
4206 *s++ = NUL; | |
4207 p = skipwhite(p); | |
4208 } | |
4209 | |
7 | 4210 argv[argc++] = (char *)cmd; |
4211 } | |
4212 argv[argc] = NULL; | |
4213 | |
167 | 4214 /* |
4215 * For the GUI, when writing the output into the buffer and when reading | |
4216 * input from the buffer: Try using a pseudo-tty to get the stdin/stdout | |
4217 * of the executed command into the Vim window. Or use a pipe. | |
4218 */ | |
4219 if ((options & (SHELL_READ|SHELL_WRITE)) | |
7 | 4220 # ifdef FEAT_GUI |
167 | 4221 || (gui.in_use && show_shell_mess) |
4222 # endif | |
4223 ) | |
7 | 4224 { |
167 | 4225 # ifdef FEAT_GUI |
7 | 4226 /* |
4227 * Try to open a master pty. | |
4228 * If this works, open the slave pty. | |
4229 * If the slave can't be opened, close the master pty. | |
4230 */ | |
167 | 4231 if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE))) |
7 | 4232 { |
4233 pty_master_fd = OpenPTY(&tty_name); /* open pty */ | |
2992 | 4234 if (pty_master_fd >= 0) |
7 | 4235 { |
2992 | 4236 /* Leaving out O_NOCTTY may lead to waitpid() always returning |
4237 * 0 on Mac OS X 10.7 thereby causing freezes. Let's assume | |
4238 * adding O_NOCTTY always works when defined. */ | |
4239 #ifdef O_NOCTTY | |
4240 pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0); | |
4241 #else | |
4242 pty_slave_fd = open(tty_name, O_RDWR | O_EXTRA, 0); | |
4243 #endif | |
4244 if (pty_slave_fd < 0) | |
4245 { | |
4246 close(pty_master_fd); | |
4247 pty_master_fd = -1; | |
4248 } | |
7 | 4249 } |
4250 } | |
4251 /* | |
4252 * If not opening a pty or it didn't work, try using pipes. | |
4253 */ | |
4254 if (pty_master_fd < 0) | |
167 | 4255 # endif |
7 | 4256 { |
4257 pipe_error = (pipe(fd_toshell) < 0); | |
4258 if (!pipe_error) /* pipe create OK */ | |
4259 { | |
4260 pipe_error = (pipe(fd_fromshell) < 0); | |
4261 if (pipe_error) /* pipe create failed */ | |
4262 { | |
4263 close(fd_toshell[0]); | |
4264 close(fd_toshell[1]); | |
4265 } | |
4266 } | |
4267 if (pipe_error) | |
4268 { | |
4269 MSG_PUTS(_("\nCannot create pipes\n")); | |
4270 out_flush(); | |
4271 } | |
4272 } | |
4273 } | |
4274 | |
4275 if (!pipe_error) /* pty or pipe opened or not used */ | |
4276 { | |
4277 # ifdef __BEOS__ | |
4278 beos_cleanup_read_thread(); | |
4279 # endif | |
602 | 4280 |
7 | 4281 if ((pid = fork()) == -1) /* maybe we should use vfork() */ |
4282 { | |
4283 MSG_PUTS(_("\nCannot fork\n")); | |
167 | 4284 if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4285 # ifdef FEAT_GUI |
167 | 4286 || (gui.in_use && show_shell_mess) |
4287 # endif | |
4288 ) | |
7 | 4289 { |
167 | 4290 # ifdef FEAT_GUI |
7 | 4291 if (pty_master_fd >= 0) /* close the pseudo tty */ |
4292 { | |
4293 close(pty_master_fd); | |
4294 close(pty_slave_fd); | |
4295 } | |
4296 else /* close the pipes */ | |
167 | 4297 # endif |
7 | 4298 { |
4299 close(fd_toshell[0]); | |
4300 close(fd_toshell[1]); | |
4301 close(fd_fromshell[0]); | |
4302 close(fd_fromshell[1]); | |
4303 } | |
4304 } | |
4305 } | |
4306 else if (pid == 0) /* child */ | |
4307 { | |
4308 reset_signals(); /* handle signals normally */ | |
4309 | |
4310 if (!show_shell_mess || (options & SHELL_EXPAND)) | |
4311 { | |
4312 int fd; | |
4313 | |
4314 /* | |
4315 * Don't want to show any message from the shell. Can't just | |
4316 * close stdout and stderr though, because some systems will | |
4317 * break if you try to write to them after that, so we must | |
4318 * use dup() to replace them with something else -- webb | |
4319 * Connect stdin to /dev/null too, so ":n `cat`" doesn't hang, | |
4320 * waiting for input. | |
4321 */ | |
4322 fd = open("/dev/null", O_RDWR | O_EXTRA, 0); | |
4323 fclose(stdin); | |
4324 fclose(stdout); | |
4325 fclose(stderr); | |
4326 | |
4327 /* | |
4328 * If any of these open()'s and dup()'s fail, we just continue | |
4329 * anyway. It's not fatal, and on most systems it will make | |
4330 * no difference at all. On a few it will cause the execvp() | |
4331 * to exit with a non-zero status even when the completion | |
4332 * could be done, which is nothing too serious. If the open() | |
4333 * or dup() failed we'd just do the same thing ourselves | |
4334 * anyway -- webb | |
4335 */ | |
4336 if (fd >= 0) | |
4337 { | |
1757 | 4338 ignored = dup(fd); /* To replace stdin (fd 0) */ |
4339 ignored = dup(fd); /* To replace stdout (fd 1) */ | |
4340 ignored = dup(fd); /* To replace stderr (fd 2) */ | |
7 | 4341 |
4342 /* Don't need this now that we've duplicated it */ | |
4343 close(fd); | |
4344 } | |
4345 } | |
167 | 4346 else if ((options & (SHELL_READ|SHELL_WRITE)) |
7 | 4347 # ifdef FEAT_GUI |
167 | 4348 || gui.in_use |
4349 # endif | |
4350 ) | |
7 | 4351 { |
4352 | |
167 | 4353 # ifdef HAVE_SETSID |
602 | 4354 /* Create our own process group, so that the child and all its |
4355 * children can be kill()ed. Don't do this when using pipes, | |
1698 | 4356 * because stdin is not a tty, we would lose /dev/tty. */ |
602 | 4357 if (p_stmp) |
1799 | 4358 { |
602 | 4359 (void)setsid(); |
1799 | 4360 # if defined(SIGHUP) |
4361 /* When doing "!xterm&" and 'shell' is bash: the shell | |
4362 * will exit and send SIGHUP to all processes in its | |
4363 * group, killing the just started process. Ignore SIGHUP | |
4364 * to avoid that. (suggested by Simon Schubert) | |
4365 */ | |
4366 signal(SIGHUP, SIG_IGN); | |
4367 # endif | |
4368 } | |
167 | 4369 # endif |
4370 # ifdef FEAT_GUI | |
602 | 4371 if (pty_slave_fd >= 0) |
4372 { | |
4373 /* push stream discipline modules */ | |
4374 if (options & SHELL_COOKED) | |
4375 SetupSlavePTY(pty_slave_fd); | |
7 | 4376 # ifdef TIOCSCTTY |
602 | 4377 /* Try to become controlling tty (probably doesn't work, |
4378 * unless run by root) */ | |
4379 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); | |
7 | 4380 # endif |
602 | 4381 } |
167 | 4382 # endif |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4383 set_child_environment(); |
167 | 4384 |
557 | 4385 /* |
4386 * stderr is only redirected when using the GUI, so that a | |
4387 * program like gpg can still access the terminal to get a | |
4388 * passphrase using stderr. | |
4389 */ | |
167 | 4390 # ifdef FEAT_GUI |
7 | 4391 if (pty_master_fd >= 0) |
4392 { | |
4393 close(pty_master_fd); /* close master side of pty */ | |
4394 | |
4395 /* set up stdin/stdout/stderr for the child */ | |
4396 close(0); | |
1757 | 4397 ignored = dup(pty_slave_fd); |
7 | 4398 close(1); |
1757 | 4399 ignored = dup(pty_slave_fd); |
557 | 4400 if (gui.in_use) |
4401 { | |
4402 close(2); | |
1757 | 4403 ignored = dup(pty_slave_fd); |
557 | 4404 } |
7 | 4405 |
4406 close(pty_slave_fd); /* has been dupped, close it now */ | |
4407 } | |
4408 else | |
167 | 4409 # endif |
7 | 4410 { |
4411 /* set up stdin for the child */ | |
4412 close(fd_toshell[1]); | |
4413 close(0); | |
1757 | 4414 ignored = dup(fd_toshell[0]); |
7 | 4415 close(fd_toshell[0]); |
4416 | |
4417 /* set up stdout for the child */ | |
4418 close(fd_fromshell[0]); | |
4419 close(1); | |
1757 | 4420 ignored = dup(fd_fromshell[1]); |
7 | 4421 close(fd_fromshell[1]); |
4422 | |
557 | 4423 # ifdef FEAT_GUI |
4424 if (gui.in_use) | |
4425 { | |
4426 /* set up stderr for the child */ | |
4427 close(2); | |
1757 | 4428 ignored = dup(1); |
557 | 4429 } |
4430 # endif | |
7 | 4431 } |
4432 } | |
167 | 4433 |
7 | 4434 /* |
4435 * There is no type cast for the argv, because the type may be | |
4436 * different on different machines. This may cause a warning | |
4437 * message with strict compilers, don't worry about it. | |
4438 * Call _exit() instead of exit() to avoid closing the connection | |
4439 * to the X server (esp. with GTK, which uses atexit()). | |
4440 */ | |
4441 execvp(argv[0], argv); | |
4442 _exit(EXEC_FAILED); /* exec failed, return failure code */ | |
4443 } | |
4444 else /* parent */ | |
4445 { | |
4446 /* | |
4447 * While child is running, ignore terminating signals. | |
167 | 4448 * Do catch CTRL-C, so that "got_int" is set. |
7 | 4449 */ |
4450 catch_signals(SIG_IGN, SIG_ERR); | |
167 | 4451 catch_int_signal(); |
7 | 4452 |
4453 /* | |
4454 * For the GUI we redirect stdin, stdout and stderr to our window. | |
167 | 4455 * This is also used to pipe stdin/stdout to/from the external |
4456 * command. | |
7 | 4457 */ |
167 | 4458 if ((options & (SHELL_READ|SHELL_WRITE)) |
4459 # ifdef FEAT_GUI | |
4460 || (gui.in_use && show_shell_mess) | |
4461 # endif | |
4462 ) | |
7 | 4463 { |
167 | 4464 # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ |
7 | 4465 char_u buffer[BUFLEN + 1]; |
167 | 4466 # ifdef FEAT_MBYTE |
7 | 4467 int buffer_off = 0; /* valid bytes in buffer[] */ |
167 | 4468 # endif |
7 | 4469 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ |
4470 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4471 int len; | |
4472 int p_more_save; | |
4473 int old_State; | |
4474 int c; | |
4475 int toshell_fd; | |
4476 int fromshell_fd; | |
167 | 4477 garray_T ga; |
4478 int noread_cnt; | |
1823 | 4479 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) |
4480 struct timeval start_tv; | |
4481 # endif | |
167 | 4482 |
4483 # ifdef FEAT_GUI | |
7 | 4484 if (pty_master_fd >= 0) |
4485 { | |
4486 fromshell_fd = pty_master_fd; | |
4487 toshell_fd = dup(pty_master_fd); | |
4488 } | |
4489 else | |
167 | 4490 # endif |
7 | 4491 { |
4492 close(fd_toshell[0]); | |
4493 close(fd_fromshell[1]); | |
4494 toshell_fd = fd_toshell[1]; | |
4495 fromshell_fd = fd_fromshell[0]; | |
4496 } | |
4497 | |
4498 /* | |
4499 * Write to the child if there are typed characters. | |
4500 * Read from the child if there are characters available. | |
4501 * Repeat the reading a few times if more characters are | |
4502 * available. Need to check for typed keys now and then, but | |
4503 * not too often (delays when no chars are available). | |
4504 * This loop is quit if no characters can be read from the pty | |
4505 * (WaitForChar detected special condition), or there are no | |
4506 * characters available and the child has exited. | |
4507 * Only check if the child has exited when there is no more | |
4508 * output. The child may exit before all the output has | |
4509 * been printed. | |
4510 * | |
4511 * Currently this busy loops! | |
4512 * This can probably dead-lock when the write blocks! | |
4513 */ | |
4514 p_more_save = p_more; | |
4515 p_more = FALSE; | |
4516 old_State = State; | |
4517 State = EXTERNCMD; /* don't redraw at window resize */ | |
4518 | |
602 | 4519 if ((options & SHELL_WRITE) && toshell_fd >= 0) |
167 | 4520 { |
4521 /* Fork a process that will write the lines to the | |
4522 * external program. */ | |
4523 if ((wpid = fork()) == -1) | |
4524 { | |
4525 MSG_PUTS(_("\nCannot fork\n")); | |
4526 } | |
3048 | 4527 else if (wpid == 0) /* child */ |
167 | 4528 { |
4529 linenr_T lnum = curbuf->b_op_start.lnum; | |
4530 int written = 0; | |
944 | 4531 char_u *lp = ml_get(lnum); |
167 | 4532 size_t l; |
4533 | |
177 | 4534 close(fromshell_fd); |
167 | 4535 for (;;) |
4536 { | |
944 | 4537 l = STRLEN(lp + written); |
167 | 4538 if (l == 0) |
4539 len = 0; | |
944 | 4540 else if (lp[written] == NL) |
167 | 4541 /* NL -> NUL translation */ |
4542 len = write(toshell_fd, "", (size_t)1); | |
4543 else | |
4544 { | |
3263 | 4545 char_u *s = vim_strchr(lp + written, NL); |
4546 | |
944 | 4547 len = write(toshell_fd, (char *)lp + written, |
1877 | 4548 s == NULL ? l |
4549 : (size_t)(s - (lp + written))); | |
167 | 4550 } |
1877 | 4551 if (len == (int)l) |
167 | 4552 { |
4553 /* Finished a line, add a NL, unless this line | |
4554 * should not have one. */ | |
4555 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4556 || (!curbuf->b_p_bin |
4557 && curbuf->b_p_fixeol) | |
2707 | 4558 || (lnum != curbuf->b_no_eol_lnum |
167 | 4559 && (lnum != |
4560 curbuf->b_ml.ml_line_count | |
4561 || curbuf->b_p_eol))) | |
1757 | 4562 ignored = write(toshell_fd, "\n", |
4563 (size_t)1); | |
167 | 4564 ++lnum; |
4565 if (lnum > curbuf->b_op_end.lnum) | |
4566 { | |
4567 /* finished all the lines, close pipe */ | |
4568 close(toshell_fd); | |
4569 toshell_fd = -1; | |
4570 break; | |
4571 } | |
944 | 4572 lp = ml_get(lnum); |
167 | 4573 written = 0; |
4574 } | |
4575 else if (len > 0) | |
4576 written += len; | |
4577 } | |
4578 _exit(0); | |
4579 } | |
3048 | 4580 else /* parent */ |
167 | 4581 { |
4582 close(toshell_fd); | |
4583 toshell_fd = -1; | |
4584 } | |
4585 } | |
4586 | |
4587 if (options & SHELL_READ) | |
4588 ga_init2(&ga, 1, BUFLEN); | |
4589 | |
4590 noread_cnt = 0; | |
1823 | 4591 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) |
4592 gettimeofday(&start_tv, NULL); | |
4593 # endif | |
7 | 4594 for (;;) |
4595 { | |
4596 /* | |
4597 * Check if keys have been typed, write them to the child | |
592 | 4598 * if there are any. |
4599 * Don't do this if we are expanding wild cards (would eat | |
4600 * typeahead). | |
4601 * Don't do this when filtering and terminal is in cooked | |
4602 * mode, the shell command will handle the I/O. Avoids | |
4603 * that a typed password is echoed for ssh or gpg command. | |
602 | 4604 * Don't get characters when the child has already |
4605 * finished (wait_pid == 0). | |
167 | 4606 * Don't read characters unless we didn't get output for a |
1823 | 4607 * while (noread_cnt > 4), avoids that ":r !ls" eats |
4608 * typeahead. | |
7 | 4609 */ |
4610 len = 0; | |
4611 if (!(options & SHELL_EXPAND) | |
592 | 4612 && ((options & |
4613 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4614 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
1823 | 4615 # ifdef FEAT_GUI |
592 | 4616 || gui.in_use |
1823 | 4617 # endif |
592 | 4618 ) |
602 | 4619 && wait_pid == 0 |
1823 | 4620 && (ta_len > 0 || noread_cnt > 4)) |
7 | 4621 { |
1823 | 4622 if (ta_len == 0) |
4623 { | |
4624 /* Get extra characters when we don't have any. | |
4625 * Reset the counter and timer. */ | |
4626 noread_cnt = 0; | |
4627 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
4628 gettimeofday(&start_tv, NULL); | |
4629 # endif | |
4630 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4631 } | |
4632 if (ta_len > 0 || len > 0) | |
4633 { | |
7 | 4634 /* |
4635 * For pipes: | |
4636 * Check for CTRL-C: send interrupt signal to child. | |
4637 * Check for CTRL-D: EOF, close pipe to child. | |
4638 */ | |
4639 if (len == 1 && (pty_master_fd < 0 || cmd != NULL)) | |
4640 { | |
167 | 4641 # ifdef SIGINT |
7 | 4642 /* |
4643 * Send SIGINT to the child's group or all | |
4644 * processes in our group. | |
4645 */ | |
4646 if (ta_buf[ta_len] == Ctrl_C | |
4647 || ta_buf[ta_len] == intr_char) | |
167 | 4648 { |
4649 # ifdef HAVE_SETSID | |
7 | 4650 kill(-pid, SIGINT); |
167 | 4651 # else |
7 | 4652 kill(0, SIGINT); |
4653 # endif | |
167 | 4654 if (wpid > 0) |
4655 kill(wpid, SIGINT); | |
4656 } | |
4657 # endif | |
7 | 4658 if (pty_master_fd < 0 && toshell_fd >= 0 |
4659 && ta_buf[ta_len] == Ctrl_D) | |
4660 { | |
4661 close(toshell_fd); | |
4662 toshell_fd = -1; | |
4663 } | |
4664 } | |
4665 | |
4666 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4667 for (i = ta_len; i < ta_len + len; ++i) | |
4668 { | |
4669 if (ta_buf[i] == CSI && len - i > 2) | |
4670 { | |
4671 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4672 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4673 { | |
4674 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4675 (size_t)(len - i - 2)); | |
4676 if (c == K_DEL || c == K_KDEL) | |
4677 ta_buf[i] = DEL; | |
4678 else | |
4679 ta_buf[i] = Ctrl_H; | |
4680 len -= 2; | |
4681 } | |
4682 } | |
4683 else if (ta_buf[i] == '\r') | |
4684 ta_buf[i] = '\n'; | |
167 | 4685 # ifdef FEAT_MBYTE |
7 | 4686 if (has_mbyte) |
1903 | 4687 i += (*mb_ptr2len_len)(ta_buf + i, |
4688 ta_len + len - i) - 1; | |
167 | 4689 # endif |
7 | 4690 } |
4691 | |
4692 /* | |
4693 * For pipes: echo the typed characters. | |
4694 * For a pty this does not seem to work. | |
4695 */ | |
4696 if (pty_master_fd < 0) | |
4697 { | |
4698 for (i = ta_len; i < ta_len + len; ++i) | |
4699 { | |
4700 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4701 msg_putchar(ta_buf[i]); | |
167 | 4702 # ifdef FEAT_MBYTE |
7 | 4703 else if (has_mbyte) |
4704 { | |
474 | 4705 int l = (*mb_ptr2len)(ta_buf + i); |
7 | 4706 |
4707 msg_outtrans_len(ta_buf + i, l); | |
4708 i += l - 1; | |
4709 } | |
167 | 4710 # endif |
7 | 4711 else |
4712 msg_outtrans_len(ta_buf + i, 1); | |
4713 } | |
4714 windgoto(msg_row, msg_col); | |
4715 out_flush(); | |
4716 } | |
4717 | |
4718 ta_len += len; | |
4719 | |
4720 /* | |
4721 * Write the characters to the child, unless EOF has | |
4722 * been typed for pipes. Write one character at a | |
1698 | 4723 * time, to avoid losing too much typeahead. |
167 | 4724 * When writing buffer lines, drop the typed |
4725 * characters (only check for CTRL-C). | |
7 | 4726 */ |
167 | 4727 if (options & SHELL_WRITE) |
4728 ta_len = 0; | |
4729 else if (toshell_fd >= 0) | |
7 | 4730 { |
4731 len = write(toshell_fd, (char *)ta_buf, (size_t)1); | |
4732 if (len > 0) | |
4733 { | |
4734 ta_len -= len; | |
4735 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4736 } | |
4737 } | |
1823 | 4738 } |
7 | 4739 } |
4740 | |
167 | 4741 if (got_int) |
4742 { | |
4743 /* CTRL-C sends a signal to the child, we ignore it | |
4744 * ourselves */ | |
4745 # ifdef HAVE_SETSID | |
4746 kill(-pid, SIGINT); | |
4747 # else | |
4748 kill(0, SIGINT); | |
4749 # endif | |
4750 if (wpid > 0) | |
4751 kill(wpid, SIGINT); | |
4752 got_int = FALSE; | |
4753 } | |
4754 | |
7 | 4755 /* |
4756 * Check if the child has any characters to be printed. | |
4757 * Read them and write them to our window. Repeat this as | |
4758 * long as there is something to do, avoid the 10ms wait | |
4759 * for mch_inchar(), or sending typeahead characters to | |
4760 * the external process. | |
4761 * TODO: This should handle escape sequences, compatible | |
4762 * to some terminal (vt52?). | |
4763 */ | |
167 | 4764 ++noread_cnt; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
4765 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL)) |
7 | 4766 { |
2664 | 4767 len = read_eintr(fromshell_fd, buffer |
167 | 4768 # ifdef FEAT_MBYTE |
7 | 4769 + buffer_off, (size_t)(BUFLEN - buffer_off) |
167 | 4770 # else |
7 | 4771 , (size_t)BUFLEN |
167 | 4772 # endif |
7 | 4773 ); |
4774 if (len <= 0) /* end of file or error */ | |
4775 goto finished; | |
167 | 4776 |
4777 noread_cnt = 0; | |
4778 if (options & SHELL_READ) | |
4779 { | |
4780 /* Do NUL -> NL translation, append NL separated | |
4781 * lines to the current buffer. */ | |
4782 for (i = 0; i < len; ++i) | |
4783 { | |
4784 if (buffer[i] == NL) | |
4785 append_ga_line(&ga); | |
4786 else if (buffer[i] == NUL) | |
4787 ga_append(&ga, NL); | |
4788 else | |
4789 ga_append(&ga, buffer[i]); | |
4790 } | |
4791 } | |
4792 # ifdef FEAT_MBYTE | |
4793 else if (has_mbyte) | |
7 | 4794 { |
4795 int l; | |
4796 | |
167 | 4797 len += buffer_off; |
4798 buffer[len] = NUL; | |
4799 | |
7 | 4800 /* Check if the last character in buffer[] is |
4801 * incomplete, keep these bytes for the next | |
4802 * round. */ | |
4803 for (p = buffer; p < buffer + len; p += l) | |
4804 { | |
474 | 4805 l = mb_cptr2len(p); |
7 | 4806 if (l == 0) |
4807 l = 1; /* NUL byte? */ | |
4808 else if (MB_BYTE2LEN(*p) != l) | |
4809 break; | |
4810 } | |
4811 if (p == buffer) /* no complete character */ | |
4812 { | |
4813 /* avoid getting stuck at an illegal byte */ | |
4814 if (len >= 12) | |
4815 ++p; | |
4816 else | |
4817 { | |
4818 buffer_off = len; | |
4819 continue; | |
4820 } | |
4821 } | |
4822 c = *p; | |
4823 *p = NUL; | |
4824 msg_puts(buffer); | |
4825 if (p < buffer + len) | |
4826 { | |
4827 *p = c; | |
4828 buffer_off = (buffer + len) - p; | |
4829 mch_memmove(buffer, p, buffer_off); | |
4830 continue; | |
4831 } | |
4832 buffer_off = 0; | |
4833 } | |
167 | 4834 # endif /* FEAT_MBYTE */ |
7 | 4835 else |
4836 { | |
4837 buffer[len] = NUL; | |
4838 msg_puts(buffer); | |
4839 } | |
4840 | |
4841 windgoto(msg_row, msg_col); | |
4842 cursor_on(); | |
4843 out_flush(); | |
4844 if (got_int) | |
4845 break; | |
1823 | 4846 |
4847 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4848 if (wait_pid == 0) |
1823 | 4849 { |
4850 struct timeval now_tv; | |
4851 long msec; | |
4852 | |
4853 /* Avoid that we keep looping here without | |
4854 * checking for a CTRL-C for a long time. Don't | |
4855 * break out too often to avoid losing typeahead. */ | |
4856 gettimeofday(&now_tv, NULL); | |
4857 msec = (now_tv.tv_sec - start_tv.tv_sec) * 1000L | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4858 + (now_tv.tv_usec - start_tv.tv_usec) / 1000L; |
1823 | 4859 if (msec > 2000) |
4860 { | |
4861 noread_cnt = 5; | |
4862 break; | |
4863 } | |
4864 } | |
4865 # endif | |
7 | 4866 } |
4867 | |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4868 /* 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
|
4869 * 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
|
4870 * buffered. */ |
602 | 4871 if (wait_pid == pid) |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4872 { |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4873 if (noread_cnt < 5) |
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4874 continue; |
602 | 4875 break; |
8845
210e767296d9
commit https://github.com/vim/vim/commit/17fe5e1aecbeff5ca4b2a821ede9badd5dddae59
Christian Brabandt <cb@256bit.org>
parents:
8761
diff
changeset
|
4876 } |
602 | 4877 |
7 | 4878 /* |
4879 * Check if the child still exists, before checking for | |
1698 | 4880 * typed characters (otherwise we would lose typeahead). |
7 | 4881 */ |
167 | 4882 # ifdef __NeXT__ |
3048 | 4883 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); |
167 | 4884 # else |
7 | 4885 wait_pid = waitpid(pid, &status, WNOHANG); |
167 | 4886 # endif |
7 | 4887 if ((wait_pid == (pid_t)-1 && errno == ECHILD) |
4888 || (wait_pid == pid && WIFEXITED(status))) | |
4889 { | |
602 | 4890 /* Don't break the loop yet, try reading more |
4891 * characters from "fromshell_fd" first. When using | |
4892 * pipes there might still be something to read and | |
4893 * then we'll break the loop at the "break" above. */ | |
7 | 4894 wait_pid = pid; |
4895 } | |
602 | 4896 else |
4897 wait_pid = 0; | |
4230 | 4898 |
4248 | 4899 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 4900 /* Handle any X events, e.g. serving the clipboard. */ |
4901 clip_update(); | |
4902 # endif | |
7 | 4903 } |
4904 finished: | |
4905 p_more = p_more_save; | |
167 | 4906 if (options & SHELL_READ) |
4907 { | |
4908 if (ga.ga_len > 0) | |
4909 { | |
4910 append_ga_line(&ga); | |
4911 /* remember that the NL was missing */ | |
2707 | 4912 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
167 | 4913 } |
4914 else | |
2707 | 4915 curbuf->b_no_eol_lnum = 0; |
167 | 4916 ga_clear(&ga); |
4917 } | |
4918 | |
7 | 4919 /* |
4920 * Give all typeahead that wasn't used back to ui_inchar(). | |
4921 */ | |
4922 if (ta_len) | |
4923 ui_inchar_undo(ta_buf, ta_len); | |
4924 State = old_State; | |
4925 if (toshell_fd >= 0) | |
4926 close(toshell_fd); | |
4927 close(fromshell_fd); | |
4928 } | |
4248 | 4929 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) |
4230 | 4930 else |
4931 { | |
4932 /* | |
4933 * Similar to the loop above, but only handle X events, no | |
4934 * I/O. | |
4935 */ | |
4936 for (;;) | |
4937 { | |
4938 if (got_int) | |
4939 { | |
4940 /* CTRL-C sends a signal to the child, we ignore it | |
4941 * ourselves */ | |
4942 # ifdef HAVE_SETSID | |
4943 kill(-pid, SIGINT); | |
4944 # else | |
4945 kill(0, SIGINT); | |
4946 # endif | |
4947 got_int = FALSE; | |
4948 } | |
4949 # ifdef __NeXT__ | |
4950 wait_pid = wait4(pid, &status, WNOHANG, (struct rusage *)0); | |
4951 # else | |
4952 wait_pid = waitpid(pid, &status, WNOHANG); | |
4953 # endif | |
4954 if ((wait_pid == (pid_t)-1 && errno == ECHILD) | |
4955 || (wait_pid == pid && WIFEXITED(status))) | |
4956 { | |
4957 wait_pid = pid; | |
4958 break; | |
4959 } | |
4960 | |
4961 /* Handle any X events, e.g. serving the clipboard. */ | |
4962 clip_update(); | |
4963 | |
4964 mch_delay(10L, TRUE); | |
4965 } | |
4966 } | |
4967 # endif | |
7 | 4968 |
4969 /* | |
4970 * Wait until our child has exited. | |
4971 * Ignore wait() returning pids of other children and returning | |
4972 * because of some signal like SIGWINCH. | |
4973 * Don't wait if wait_pid was already set above, indicating the | |
4974 * child already exited. | |
4975 */ | |
3048 | 4976 if (wait_pid != pid) |
4977 wait_pid = wait4pid(pid, &status); | |
7 | 4978 |
2600 | 4979 # ifdef FEAT_GUI |
4980 /* Close slave side of pty. Only do this after the child has | |
4981 * exited, otherwise the child may hang when it tries to write on | |
4982 * the pty. */ | |
4983 if (pty_master_fd >= 0) | |
4984 close(pty_slave_fd); | |
4985 # endif | |
4986 | |
167 | 4987 /* Make sure the child that writes to the external program is |
4988 * dead. */ | |
4989 if (wpid > 0) | |
3048 | 4990 { |
167 | 4991 kill(wpid, SIGKILL); |
3048 | 4992 wait4pid(wpid, NULL); |
4993 } | |
167 | 4994 |
7 | 4995 /* |
4996 * Set to raw mode right now, otherwise a CTRL-C after | |
4997 * catch_signals() will kill Vim. | |
4998 */ | |
4999 if (tmode == TMODE_RAW) | |
5000 settmode(TMODE_RAW); | |
5001 did_settmode = TRUE; | |
5002 set_signals(); | |
5003 | |
5004 if (WIFEXITED(status)) | |
5005 { | |
129 | 5006 /* LINTED avoid "bitwise operation on signed value" */ |
7 | 5007 retval = WEXITSTATUS(status); |
4074 | 5008 if (retval != 0 && !emsg_silent) |
7 | 5009 { |
5010 if (retval == EXEC_FAILED) | |
5011 { | |
5012 MSG_PUTS(_("\nCannot execute shell ")); | |
5013 msg_outtrans(p_sh); | |
5014 msg_putchar('\n'); | |
5015 } | |
5016 else if (!(options & SHELL_SILENT)) | |
5017 { | |
5018 MSG_PUTS(_("\nshell returned ")); | |
5019 msg_outnum((long)retval); | |
5020 msg_putchar('\n'); | |
5021 } | |
5022 } | |
5023 } | |
5024 else | |
5025 MSG_PUTS(_("\nCommand terminated\n")); | |
5026 } | |
5027 } | |
5028 vim_free(argv); | |
2994 | 5029 vim_free(p_shcf_copy); |
7 | 5030 |
5031 error: | |
5032 if (!did_settmode) | |
5033 if (tmode == TMODE_RAW) | |
5034 settmode(TMODE_RAW); /* set to raw mode */ | |
5035 # ifdef FEAT_TITLE | |
5036 resettitle(); | |
5037 # endif | |
5038 vim_free(newcmd); | |
5039 | |
5040 return retval; | |
5041 | |
5042 #endif /* USE_SYSTEM */ | |
5043 } | |
5044 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5045 #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
|
5046 void |
8408
2f1a63269250
commit https://github.com/vim/vim/commit/802d559431e6003a46c7f19628213b7cec8ba6d0
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5047 mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5048 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5049 pid_t pid; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5050 int fd_in[2]; /* for stdin */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5051 int fd_out[2]; /* for stdout */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5052 int fd_err[2]; /* for stderr */ |
8049
15253130abd8
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Christian Brabandt <cb@256bit.org>
parents:
8047
diff
changeset
|
5053 channel_T *channel = NULL; |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5054 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
|
5055 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
|
5056 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
|
5057 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
|
5058 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
|
5059 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
|
5060 int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5061 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5062 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
|
5063 use_null_for_err = TRUE; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5064 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5065 /* default is to fail */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5066 job->jv_status = JOB_FAILED; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5067 fd_in[0] = -1; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5068 fd_in[1] = -1; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5069 fd_out[0] = -1; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5070 fd_out[1] = -1; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5071 fd_err[0] = -1; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5072 fd_err[1] = -1; |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5073 |
8068
9c6740f2204f
commit https://github.com/vim/vim/commit/12dcf024e90ab511f04a08b20fe7eedbe92096d2
Christian Brabandt <cb@256bit.org>
parents:
8049
diff
changeset
|
5074 /* 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
|
5075 /* 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
|
5076 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5077 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5078 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
|
5079 |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5080 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
|
5081 if (fd_in[0] < 0) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5082 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5083 EMSG2(_(e_notopen), fname); |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5084 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5085 } |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5086 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5087 else if (!use_null_for_in && pipe(fd_in) < 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5088 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5089 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5090 if (use_file_for_out) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5091 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5092 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
|
5093 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5094 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
|
5095 if (fd_out[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5096 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5097 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5098 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5099 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5100 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5101 else if (!use_null_for_out && pipe(fd_out) < 0) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8408
diff
changeset
|
5102 goto failed; |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5103 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5104 if (use_file_for_err) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5105 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5106 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
|
5107 |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5108 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
|
5109 if (fd_err[1] < 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5110 { |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5111 EMSG2(_(e_notopen), fname); |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5112 goto failed; |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5113 } |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5114 } |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5115 else if (!use_out_for_err && !use_null_for_err && pipe(fd_err) < 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5116 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5117 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5118 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
|
5119 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5120 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5121 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5122 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5123 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5124 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5125 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5126 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5127 channel = add_channel(); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5128 if (channel == NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5129 goto failed; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5130 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5131 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5132 pid = fork(); /* maybe we should use vfork() */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5133 if (pid == -1) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5134 { |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5135 /* failed to fork */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5136 goto failed; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5137 } |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5138 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5139 if (pid == 0) |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5140 { |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5141 int null_fd = -1; |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5142 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5143 /* child */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5144 reset_signals(); /* handle signals normally */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5145 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5146 # ifdef HAVE_SETSID |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5147 /* 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
|
5148 * 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
|
5149 * 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
|
5150 (void)setsid(); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5151 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5152 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5153 set_child_environment(); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5154 |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5155 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
|
5156 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
|
5157 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5158 /* set up stdin for the child */ |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5159 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
|
5160 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5161 close(0); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5162 ignored = dup(null_fd); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5163 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5164 else |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5165 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5166 if (!use_file_for_in) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5167 close(fd_in[1]); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5168 close(0); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5169 ignored = dup(fd_in[0]); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5170 close(fd_in[0]); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5171 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5172 |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5173 /* set up stderr for the child */ |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5174 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
|
5175 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5176 close(2); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5177 ignored = dup(null_fd); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5178 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5179 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
|
5180 { |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5181 close(2); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5182 ignored = dup(fd_out[1]); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5183 } |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5184 else |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5185 { |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5186 if (!use_file_for_err) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5187 close(fd_err[0]); |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5188 close(2); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5189 ignored = dup(fd_err[1]); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5190 close(fd_err[1]); |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5191 } |
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8360
diff
changeset
|
5192 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5193 /* set up stdout for the child */ |
8611
f12689430f4b
commit https://github.com/vim/vim/commit/c0a1d7f3ad4d41b64c6c881bb8ad7c201f8439a3
Christian Brabandt <cb@256bit.org>
parents:
8609
diff
changeset
|
5194 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
|
5195 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5196 close(0); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5197 ignored = dup(null_fd); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5198 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5199 else |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5200 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5201 if (!use_file_for_out) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5202 close(fd_out[0]); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5203 close(1); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5204 ignored = dup(fd_out[1]); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5205 close(fd_out[1]); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5206 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5207 if (null_fd >= 0) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5208 close(null_fd); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5209 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5210 /* See above for type of argv. */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5211 execvp(argv[0], argv); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5212 |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5213 // perror("executing job failed"); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5214 _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
|
5215 } |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5216 |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5217 /* parent */ |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5218 job->jv_pid = pid; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5219 job->jv_status = JOB_STARTED; |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5220 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
|
5221 |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5222 /* child stdin, stdout and stderr */ |
8671
8f6bc5626829
commit https://github.com/vim/vim/commit/be6aa46c4d8948e164f7d181dc19ed2fc4818395
Christian Brabandt <cb@256bit.org>
parents:
8611
diff
changeset
|
5223 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
|
5224 close(fd_in[0]); |
8671
8f6bc5626829
commit https://github.com/vim/vim/commit/be6aa46c4d8948e164f7d181dc19ed2fc4818395
Christian Brabandt <cb@256bit.org>
parents:
8611
diff
changeset
|
5225 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
|
5226 close(fd_out[1]); |
8671
8f6bc5626829
commit https://github.com/vim/vim/commit/be6aa46c4d8948e164f7d181dc19ed2fc4818395
Christian Brabandt <cb@256bit.org>
parents:
8611
diff
changeset
|
5227 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
|
5228 close(fd_err[1]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5229 if (channel != NULL) |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5230 { |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5231 channel_set_pipes(channel, |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5232 use_file_for_in || use_null_for_in |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5233 ? INVALID_FD : fd_in[1], |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5234 use_file_for_out || use_null_for_out |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5235 ? INVALID_FD : fd_out[0], |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5236 use_out_for_err || use_file_for_err || use_null_for_err |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5237 ? INVALID_FD : fd_err[0]); |
8455
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5238 channel_set_job(channel, job, options); |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5239 } |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5240 |
d0717262d802
commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents:
8447
diff
changeset
|
5241 /* success! */ |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5242 return; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5243 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5244 failed: |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8455
diff
changeset
|
5245 channel_unref(channel); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5246 if (fd_in[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5247 close(fd_in[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5248 if (fd_in[1] >= 0) |
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5249 close(fd_in[1]); |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5250 if (fd_out[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5251 close(fd_out[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5252 if (fd_out[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5253 close(fd_out[1]); |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5254 if (fd_err[0] >= 0) |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5255 close(fd_err[0]); |
8447
6f26b680c243
commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5256 if (fd_err[1] >= 0) |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5257 close(fd_err[1]); |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5258 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5259 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5260 char * |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5261 mch_job_status(job_T *job) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5262 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5263 # ifdef HAVE_UNION_WAIT |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5264 union wait status; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5265 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5266 int status = -1; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5267 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5268 pid_t wait_pid = 0; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5269 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5270 # ifdef __NeXT__ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5271 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
|
5272 # else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5273 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
|
5274 # endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5275 if (wait_pid == -1) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5276 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5277 /* process must have exited */ |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5278 job->jv_status = JOB_ENDED; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5279 return "dead"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5280 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5281 if (wait_pid == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5282 return "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5283 if (WIFEXITED(status)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5284 { |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5285 /* 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
|
5286 job->jv_exitval = WEXITSTATUS(status); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5287 job->jv_status = JOB_ENDED; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5288 return "dead"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5289 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5290 if (WIFSIGNALED(status)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5291 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5292 job->jv_exitval = -1; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5293 job->jv_status = JOB_ENDED; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5294 return "dead"; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5295 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5296 return "run"; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5297 } |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5298 |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5299 int |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5300 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
|
5301 { |
8031
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5302 int sig = -1; |
ece323e2b57f
commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5303 pid_t job_pid; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5304 |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5305 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
|
5306 sig = SIGTERM; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5307 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
|
5308 sig = SIGHUP; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5309 else if (STRCMP(how, "quit") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5310 sig = SIGQUIT; |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5311 else if (STRCMP(how, "int") == 0) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8112
diff
changeset
|
5312 sig = SIGINT; |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5313 else if (STRCMP(how, "kill") == 0) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5314 sig = SIGKILL; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5315 else if (isdigit(*how)) |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5316 sig = atoi((char *)how); |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5317 else |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5318 return FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5319 |
7999
92ad477c6ab3
commit https://github.com/vim/vim/commit/7280140c08799f683ef31a6c1019e283c3dc13aa
Christian Brabandt <cb@256bit.org>
parents:
7957
diff
changeset
|
5320 /* 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
|
5321 job_pid = job->jv_pid; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5322 if (job_pid == getpgid(job_pid)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5323 job_pid = -job_pid; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5324 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5325 kill(job_pid, sig); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5326 |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5327 return OK; |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5328 } |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5329 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5330 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5331 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5332 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5333 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5334 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5335 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5336 /* 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
|
5337 # ifdef __NeXT__ |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5338 (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
|
5339 # else |
8360
45740f83b3ce
commit https://github.com/vim/vim/commit/4ca812b15378f83e56a2dc42947a61d0aa40697f
Christian Brabandt <cb@256bit.org>
parents:
8336
diff
changeset
|
5340 (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
|
5341 # endif |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
7999
diff
changeset
|
5342 } |
7957
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5343 #endif |
b74549818500
commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
5344 |
7 | 5345 /* |
5346 * Check for CTRL-C typed by reading all available characters. | |
5347 * In cooked mode we should get SIGINT, no need to check. | |
5348 */ | |
5349 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5350 mch_breakcheck(void) |
7 | 5351 { |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5352 if (curr_tmode == TMODE_RAW && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL)) |
7 | 5353 fill_input_buf(FALSE); |
5354 } | |
5355 | |
5356 /* | |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5357 * 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
|
5358 * from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5359 * "msec" == -1 will block forever. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5360 * Invokes timer callbacks when needed. |
7 | 5361 * When a GUI is being used, this will never get called -- webb |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5362 * Returns TRUE when a character is available. |
7 | 5363 */ |
5364 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5365 WaitForChar(long msec) |
7 | 5366 { |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5367 #ifdef FEAT_TIMERS |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5368 long due_time; |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5369 long remaining = msec; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5370 int break_loop = FALSE; |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5371 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
|
5372 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5373 /* 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
|
5374 if (msec >= 0 && msec < 10L) |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5375 return WaitForCharOrMouse(msec, NULL); |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5376 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5377 while (msec < 0 || remaining > 0) |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5378 { |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5379 /* 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
|
5380 * due. Wait up to that time. */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5381 due_time = check_due_timer(); |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5382 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
|
5383 { |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5384 /* timer may have used feedkeys() */ |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5385 return FALSE; |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8845
diff
changeset
|
5386 } |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5387 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
|
5388 due_time = remaining; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5389 if (WaitForCharOrMouse(due_time, &break_loop)) |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5390 return TRUE; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5391 if (break_loop) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5392 /* 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
|
5393 * 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
|
5394 return FALSE; |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5395 if (msec > 0) |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5396 remaining -= due_time; |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5397 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5398 return FALSE; |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5399 #else |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5400 return WaitForCharOrMouse(msec, NULL); |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5401 #endif |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5402 } |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5403 |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5404 /* |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5405 * 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
|
5406 * or from inbuf[]. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5407 * "msec" == -1 will block forever. |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5408 * 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
|
5409 */ |
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5410 static int |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5411 WaitForCharOrMouse(long msec, int *break_loop) |
8609
40bb2619f5e2
commit https://github.com/vim/vim/commit/943bb2b8eb80266a5de143feeab4c842c4b68c61
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5412 { |
7 | 5413 #ifdef FEAT_MOUSE_GPM |
5414 int gpm_process_wanted; | |
5415 #endif | |
5416 #ifdef FEAT_XCLIPBOARD | |
5417 int rest; | |
5418 #endif | |
5419 int avail; | |
5420 | |
5421 if (input_available()) /* something in inbuf[] */ | |
5422 return 1; | |
5423 | |
5424 #if defined(FEAT_MOUSE_DEC) | |
5425 /* May need to query the mouse position. */ | |
5426 if (WantQueryMouse) | |
5427 { | |
227 | 5428 WantQueryMouse = FALSE; |
7 | 5429 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5); |
5430 } | |
5431 #endif | |
5432 | |
5433 /* | |
5434 * For FEAT_MOUSE_GPM and FEAT_XCLIPBOARD we loop here to process mouse | |
5435 * events. This is a bit complicated, because they might both be defined. | |
5436 */ | |
5437 #if defined(FEAT_MOUSE_GPM) || defined(FEAT_XCLIPBOARD) | |
5438 # ifdef FEAT_XCLIPBOARD | |
5439 rest = 0; | |
5440 if (do_xterm_trace()) | |
5441 rest = msec; | |
5442 # endif | |
5443 do | |
5444 { | |
5445 # ifdef FEAT_XCLIPBOARD | |
5446 if (rest != 0) | |
5447 { | |
5448 msec = XT_TRACE_DELAY; | |
5449 if (rest >= 0 && rest < XT_TRACE_DELAY) | |
5450 msec = rest; | |
5451 if (rest >= 0) | |
5452 rest -= msec; | |
5453 } | |
5454 # endif | |
5455 # ifdef FEAT_MOUSE_GPM | |
5456 gpm_process_wanted = 0; | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5457 avail = RealWaitForChar(read_cmd_fd, msec, |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5458 &gpm_process_wanted, break_loop); |
7 | 5459 # else |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5460 avail = RealWaitForChar(read_cmd_fd, msec, NULL, break_loop); |
7 | 5461 # endif |
5462 if (!avail) | |
5463 { | |
5464 if (input_available()) | |
5465 return 1; | |
5466 # ifdef FEAT_XCLIPBOARD | |
5467 if (rest == 0 || !do_xterm_trace()) | |
5468 # endif | |
5469 break; | |
5470 } | |
5471 } | |
5472 while (FALSE | |
5473 # ifdef FEAT_MOUSE_GPM | |
5474 || (gpm_process_wanted && mch_gpm_process() == 0) | |
5475 # endif | |
5476 # ifdef FEAT_XCLIPBOARD | |
5477 || (!avail && rest != 0) | |
5478 # endif | |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5479 ) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5480 ; |
7 | 5481 |
5482 #else | |
8740
a35b596cd7ac
commit https://github.com/vim/vim/commit/e1581307d281ceb35726e1b4ca30ef773a2ef23e
Christian Brabandt <cb@256bit.org>
parents:
8736
diff
changeset
|
5483 avail = RealWaitForChar(read_cmd_fd, msec, NULL, break_loop); |
7 | 5484 #endif |
5485 return avail; | |
5486 } | |
5487 | |
5541 | 5488 #ifndef VMS |
7 | 5489 /* |
5490 * Wait "msec" msec until a character is available from file descriptor "fd". | |
3046 | 5491 * "msec" == 0 will check for characters once. |
5492 * "msec" == -1 will block until a character is available. | |
7 | 5493 * When a GUI is being used, this will not be used for input -- webb |
5494 * 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
|
5495 * Or when a clientserver message is on the queue. |
7 | 5496 */ |
5497 #if defined(__BEOS__) | |
5498 int | |
5499 #else | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5500 static int |
7 | 5501 #endif |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5502 RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *break_loop) |
7 | 5503 { |
5504 int ret; | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5505 int result; |
14 | 5506 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) |
7 | 5507 static int busy = FALSE; |
5508 | |
5509 /* May retry getting characters after an event was handled. */ | |
5510 # define MAY_LOOP | |
5511 | |
5512 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
5513 /* Remember at what time we started, so that we know how much longer we | |
5514 * should wait after being interrupted. */ | |
5515 # define USE_START_TV | |
5516 struct timeval start_tv; | |
5517 | |
5518 if (msec > 0 && ( | |
5519 # ifdef FEAT_XCLIPBOARD | |
5520 xterm_Shell != (Widget)0 | |
14 | 5521 # if defined(USE_XSMP) || defined(FEAT_MZSCHEME) |
7 | 5522 || |
5523 # endif | |
5524 # endif | |
5525 # ifdef USE_XSMP | |
5526 xsmp_icefd != -1 | |
14 | 5527 # ifdef FEAT_MZSCHEME |
5528 || | |
5529 # endif | |
5530 # endif | |
5531 # ifdef FEAT_MZSCHEME | |
5532 (mzthreads_allowed() && p_mzq > 0) | |
7 | 5533 # endif |
5534 )) | |
5535 gettimeofday(&start_tv, NULL); | |
5536 # endif | |
5537 | |
5538 /* Handle being called recursively. This may happen for the session | |
5539 * manager stuff, it may save the file, which does a breakcheck. */ | |
5540 if (busy) | |
5541 return 0; | |
5542 #endif | |
5543 | |
5544 #ifdef MAY_LOOP | |
407 | 5545 for (;;) |
7 | 5546 #endif |
5547 { | |
5548 #ifdef MAY_LOOP | |
5549 int finished = TRUE; /* default is to 'loop' just once */ | |
14 | 5550 # ifdef FEAT_MZSCHEME |
5551 int mzquantum_used = FALSE; | |
5552 # endif | |
7 | 5553 #endif |
5554 #ifndef HAVE_SELECT | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5555 /* 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
|
5556 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; |
7 | 5557 int nfd; |
5558 # ifdef FEAT_XCLIPBOARD | |
5559 int xterm_idx = -1; | |
5560 # endif | |
5561 # ifdef FEAT_MOUSE_GPM | |
5562 int gpm_idx = -1; | |
5563 # endif | |
5564 # ifdef USE_XSMP | |
5565 int xsmp_idx = -1; | |
5566 # endif | |
14 | 5567 int towait = (int)msec; |
5568 | |
5569 # ifdef FEAT_MZSCHEME | |
5570 mzvim_check_threads(); | |
5571 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
5572 { | |
5573 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ | |
5574 mzquantum_used = TRUE; | |
5575 } | |
5576 # endif | |
7 | 5577 fds[0].fd = fd; |
5578 fds[0].events = POLLIN; | |
5579 nfd = 1; | |
5580 | |
5581 # ifdef FEAT_XCLIPBOARD | |
6383 | 5582 may_restore_clipboard(); |
7 | 5583 if (xterm_Shell != (Widget)0) |
5584 { | |
5585 xterm_idx = nfd; | |
5586 fds[nfd].fd = ConnectionNumber(xterm_dpy); | |
5587 fds[nfd].events = POLLIN; | |
5588 nfd++; | |
5589 } | |
5590 # endif | |
5591 # ifdef FEAT_MOUSE_GPM | |
5592 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
5593 { | |
5594 gpm_idx = nfd; | |
5595 fds[nfd].fd = gpm_fd; | |
5596 fds[nfd].events = POLLIN; | |
5597 nfd++; | |
5598 } | |
5599 # endif | |
5600 # ifdef USE_XSMP | |
5601 if (xsmp_icefd != -1) | |
5602 { | |
5603 xsmp_idx = nfd; | |
5604 fds[nfd].fd = xsmp_icefd; | |
5605 fds[nfd].events = POLLIN; | |
5606 nfd++; | |
5607 } | |
5608 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5609 #ifdef FEAT_JOB_CHANNEL |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5610 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
|
5611 #endif |
7 | 5612 |
14 | 5613 ret = poll(fds, nfd, towait); |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5614 |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5615 result = ret > 0 && (fds[0].revents & POLLIN); |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5616 if (break_loop != NULL && ret > 0) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5617 *break_loop = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5618 |
14 | 5619 # ifdef FEAT_MZSCHEME |
5620 if (ret == 0 && mzquantum_used) | |
1450 | 5621 /* MzThreads scheduling is required and timeout occurred */ |
14 | 5622 finished = FALSE; |
5623 # endif | |
7 | 5624 |
5625 # ifdef FEAT_XCLIPBOARD | |
5626 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) | |
5627 { | |
5628 xterm_update(); /* Maybe we should hand out clipboard */ | |
5629 if (--ret == 0 && !input_available()) | |
5630 /* Try again */ | |
5631 finished = FALSE; | |
5632 } | |
5633 # endif | |
5634 # ifdef FEAT_MOUSE_GPM | |
5635 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN)) | |
5636 { | |
5637 *check_for_gpm = 1; | |
5638 } | |
5639 # endif | |
5640 # ifdef USE_XSMP | |
5641 if (xsmp_idx >= 0 && (fds[xsmp_idx].revents & (POLLIN | POLLHUP))) | |
5642 { | |
5643 if (fds[xsmp_idx].revents & POLLIN) | |
5644 { | |
5645 busy = TRUE; | |
5646 xsmp_handle_requests(); | |
5647 busy = FALSE; | |
5648 } | |
5649 else if (fds[xsmp_idx].revents & POLLHUP) | |
5650 { | |
5651 if (p_verbose > 0) | |
292 | 5652 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 5653 xsmp_close(); |
5654 } | |
5655 if (--ret == 0) | |
14 | 5656 finished = FALSE; /* Try again */ |
7 | 5657 } |
5658 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5659 #ifdef FEAT_JOB_CHANNEL |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5660 if (ret > 0) |
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5661 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
|
5662 #endif |
7 | 5663 |
5664 | |
5665 #else /* HAVE_SELECT */ | |
5666 | |
5667 struct timeval tv; | |
14 | 5668 struct timeval *tvp; |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5669 fd_set rfds, wfds, efds; |
7 | 5670 int maxfd; |
14 | 5671 long towait = msec; |
5672 | |
5673 # ifdef FEAT_MZSCHEME | |
5674 mzvim_check_threads(); | |
5675 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) | |
5676 { | |
5677 towait = p_mzq; /* don't wait longer than 'mzquantum' */ | |
5678 mzquantum_used = TRUE; | |
5679 } | |
5680 # endif | |
7 | 5681 # ifdef __EMX__ |
5682 /* don't check for incoming chars if not in raw mode, because select() | |
5683 * always returns TRUE then (in some version of emx.dll) */ | |
5684 if (curr_tmode != TMODE_RAW) | |
5685 return 0; | |
5686 # endif | |
5687 | |
14 | 5688 if (towait >= 0) |
7 | 5689 { |
14 | 5690 tv.tv_sec = towait / 1000; |
5691 tv.tv_usec = (towait % 1000) * (1000000/1000); | |
5692 tvp = &tv; | |
7 | 5693 } |
14 | 5694 else |
5695 tvp = NULL; | |
7 | 5696 |
5697 /* | |
5698 * Select on ready for reading and exceptional condition (end of file). | |
5699 */ | |
3046 | 5700 select_eintr: |
5701 FD_ZERO(&rfds); | |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5702 FD_ZERO(&wfds); |
7 | 5703 FD_ZERO(&efds); |
5704 FD_SET(fd, &rfds); | |
5705 # if !defined(__QNX__) && !defined(__CYGWIN32__) | |
5706 /* For QNX select() always returns 1 if this is set. Why? */ | |
5707 FD_SET(fd, &efds); | |
5708 # endif | |
5709 maxfd = fd; | |
5710 | |
5711 # ifdef FEAT_XCLIPBOARD | |
6383 | 5712 may_restore_clipboard(); |
7 | 5713 if (xterm_Shell != (Widget)0) |
5714 { | |
5715 FD_SET(ConnectionNumber(xterm_dpy), &rfds); | |
5716 if (maxfd < ConnectionNumber(xterm_dpy)) | |
5717 maxfd = ConnectionNumber(xterm_dpy); | |
3748 | 5718 |
5719 /* An event may have already been read but not handled. In | |
5720 * particulary, XFlush may cause this. */ | |
5721 xterm_update(); | |
7 | 5722 } |
5723 # endif | |
5724 # ifdef FEAT_MOUSE_GPM | |
5725 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) | |
5726 { | |
5727 FD_SET(gpm_fd, &rfds); | |
5728 FD_SET(gpm_fd, &efds); | |
5729 if (maxfd < gpm_fd) | |
5730 maxfd = gpm_fd; | |
5731 } | |
5732 # endif | |
5733 # ifdef USE_XSMP | |
5734 if (xsmp_icefd != -1) | |
5735 { | |
5736 FD_SET(xsmp_icefd, &rfds); | |
5737 FD_SET(xsmp_icefd, &efds); | |
5738 if (maxfd < xsmp_icefd) | |
5739 maxfd = xsmp_icefd; | |
5740 } | |
5741 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5742 # ifdef FEAT_JOB_CHANNEL |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5743 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
|
5744 # endif |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5745 |
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5746 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
|
5747 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
|
5748 if (result) |
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5749 --ret; |
8736
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5750 if (break_loop != NULL && ret > 0) |
06bf71f13eb7
commit https://github.com/vim/vim/commit/8fdd7210479f0c486822ad8934087b4bfd8a4765
Christian Brabandt <cb@256bit.org>
parents:
8671
diff
changeset
|
5751 *break_loop = TRUE; |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5752 |
3046 | 5753 # ifdef EINTR |
5754 if (ret == -1 && errno == EINTR) | |
3133 | 5755 { |
5756 /* Check whether window has been resized, EINTR may be caused by | |
5757 * SIGWINCH. */ | |
5758 if (do_resize) | |
5759 handle_resize(); | |
5760 | |
3046 | 5761 /* Interrupted by a signal, need to try again. We ignore msec |
5762 * here, because we do want to check even after a timeout if | |
5763 * characters are available. Needed for reading output of an | |
5764 * external command after the process has finished. */ | |
5765 goto select_eintr; | |
3133 | 5766 } |
3046 | 5767 # endif |
1076 | 5768 # ifdef __TANDEM |
5769 if (ret == -1 && errno == ENOTSUP) | |
5770 { | |
5771 FD_ZERO(&rfds); | |
5772 FD_ZERO(&efds); | |
5773 ret = 0; | |
5774 } | |
3046 | 5775 # endif |
14 | 5776 # ifdef FEAT_MZSCHEME |
5777 if (ret == 0 && mzquantum_used) | |
1450 | 5778 /* loop if MzThreads must be scheduled and timeout occurred */ |
14 | 5779 finished = FALSE; |
7 | 5780 # endif |
5781 | |
5782 # ifdef FEAT_XCLIPBOARD | |
5783 if (ret > 0 && xterm_Shell != (Widget)0 | |
5784 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) | |
5785 { | |
5786 xterm_update(); /* Maybe we should hand out clipboard */ | |
5787 /* continue looping when we only got the X event and the input | |
5788 * buffer is empty */ | |
5789 if (--ret == 0 && !input_available()) | |
5790 { | |
5791 /* Try again */ | |
5792 finished = FALSE; | |
5793 } | |
5794 } | |
5795 # endif | |
5796 # ifdef FEAT_MOUSE_GPM | |
5797 if (ret > 0 && gpm_flag && check_for_gpm != NULL && gpm_fd >= 0) | |
5798 { | |
5799 if (FD_ISSET(gpm_fd, &efds)) | |
5800 gpm_close(); | |
5801 else if (FD_ISSET(gpm_fd, &rfds)) | |
5802 *check_for_gpm = 1; | |
5803 } | |
5804 # endif | |
5805 # ifdef USE_XSMP | |
5806 if (ret > 0 && xsmp_icefd != -1) | |
5807 { | |
5808 if (FD_ISSET(xsmp_icefd, &efds)) | |
5809 { | |
5810 if (p_verbose > 0) | |
292 | 5811 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 5812 xsmp_close(); |
5813 if (--ret == 0) | |
5814 finished = FALSE; /* keep going if event was only one */ | |
5815 } | |
5816 else if (FD_ISSET(xsmp_icefd, &rfds)) | |
5817 { | |
5818 busy = TRUE; | |
5819 xsmp_handle_requests(); | |
5820 busy = FALSE; | |
5821 if (--ret == 0) | |
5822 finished = FALSE; /* keep going if event was only one */ | |
5823 } | |
5824 } | |
5825 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5826 #ifdef FEAT_JOB_CHANNEL |
7743
6069f43cea4e
commit https://github.com/vim/vim/commit/e0874f8cbcddfcf9965a85ba35199964efb1d01a
Christian Brabandt <cb@256bit.org>
parents:
7629
diff
changeset
|
5827 if (ret > 0) |
8761
f8707ec9efe4
commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents:
8740
diff
changeset
|
5828 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
|
5829 #endif |
7 | 5830 |
5831 #endif /* HAVE_SELECT */ | |
5832 | |
5833 #ifdef MAY_LOOP | |
5834 if (finished || msec == 0) | |
5835 break; | |
5836 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
5837 # ifdef FEAT_CLIENTSERVER |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
5838 if (server_waiting()) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
5839 break; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
5840 # endif |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
5841 |
7 | 5842 /* We're going to loop around again, find out for how long */ |
5843 if (msec > 0) | |
5844 { | |
5845 # ifdef USE_START_TV | |
5846 struct timeval mtv; | |
5847 | |
5848 /* Compute remaining wait time. */ | |
5849 gettimeofday(&mtv, NULL); | |
5850 msec -= (mtv.tv_sec - start_tv.tv_sec) * 1000L | |
5851 + (mtv.tv_usec - start_tv.tv_usec) / 1000L; | |
5852 # else | |
5853 /* Guess we got interrupted halfway. */ | |
5854 msec = msec / 2; | |
5855 # endif | |
5856 if (msec <= 0) | |
5857 break; /* waited long enough */ | |
5858 } | |
5859 #endif | |
5860 } | |
5861 | |
8112
a62ff5ff60c1
commit https://github.com/vim/vim/commit/ec70bdd68a531762a62728747ab529d7a6dfc842
Christian Brabandt <cb@256bit.org>
parents:
8094
diff
changeset
|
5862 return result; |
7 | 5863 } |
5864 | |
5865 #ifndef NO_EXPANDPATH | |
5866 /* | |
444 | 5867 * Expand a path into all matching files and/or directories. Handles "*", |
5868 * "?", "[a-z]", "**", etc. | |
5869 * "path" has backslashes before chars that are not to be expanded. | |
5870 * Returns the number of matches found. | |
7 | 5871 */ |
5872 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5873 mch_expandpath( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5874 garray_T *gap, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5875 char_u *path, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5876 int flags) /* EW_* flags */ |
7 | 5877 { |
444 | 5878 return unix_expandpath(gap, path, 0, flags, FALSE); |
7 | 5879 } |
5880 #endif | |
5881 | |
5882 /* | |
5883 * mch_expand_wildcards() - this code does wild-card pattern matching using | |
5884 * the shell | |
5885 * | |
5886 * return OK for success, FAIL for error (you may lose some memory) and put | |
5887 * an error message in *file. | |
5888 * | |
5889 * num_pat is number of input patterns | |
5890 * pat is array of pointers to input patterns | |
5891 * num_file is pointer to number of matched file names | |
5892 * file is pointer to array of pointers to matched file names | |
5893 */ | |
5894 | |
5895 #ifndef SEEK_SET | |
5896 # define SEEK_SET 0 | |
5897 #endif | |
5898 #ifndef SEEK_END | |
5899 # define SEEK_END 2 | |
5900 #endif | |
5901 | |
822 | 5902 #define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
628 | 5903 |
7 | 5904 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5905 mch_expand_wildcards( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5906 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5907 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5908 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5909 char_u ***file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5910 int flags) /* EW_* flags */ |
7 | 5911 { |
5912 int i; | |
5913 size_t len; | |
5914 char_u *p; | |
5915 int dir; | |
5916 #ifdef __EMX__ | |
1508 | 5917 /* |
5918 * This is the OS/2 implementation. | |
5919 */ | |
7 | 5920 # define EXPL_ALLOC_INC 16 |
5921 char_u **expl_files; | |
5922 size_t files_alloced, files_free; | |
5923 char_u *buf; | |
5924 int has_wildcard; | |
5925 | |
5926 *num_file = 0; /* default: no files found */ | |
5927 files_alloced = EXPL_ALLOC_INC; /* how much space is allocated */ | |
5928 files_free = EXPL_ALLOC_INC; /* how much space is not used */ | |
5929 *file = (char_u **)alloc(sizeof(char_u **) * files_alloced); | |
5930 if (*file == NULL) | |
5931 return FAIL; | |
5932 | |
5933 for (; num_pat > 0; num_pat--, pat++) | |
5934 { | |
5935 expl_files = NULL; | |
5936 if (vim_strchr(*pat, '$') || vim_strchr(*pat, '~')) | |
5937 /* expand environment var or home dir */ | |
5938 buf = expand_env_save(*pat); | |
5939 else | |
5940 buf = vim_strsave(*pat); | |
5941 expl_files = NULL; | |
99 | 5942 has_wildcard = mch_has_exp_wildcard(buf); /* (still) wildcards? */ |
7 | 5943 if (has_wildcard) /* yes, so expand them */ |
5944 expl_files = (char_u **)_fnexplode(buf); | |
5945 | |
5946 /* | |
5947 * return value of buf if no wildcards left, | |
5948 * OR if no match AND EW_NOTFOUND is set. | |
5949 */ | |
5950 if ((!has_wildcard && ((flags & EW_NOTFOUND) || mch_getperm(buf) >= 0)) | |
5951 || (expl_files == NULL && (flags & EW_NOTFOUND))) | |
5952 { /* simply save the current contents of *buf */ | |
5953 expl_files = (char_u **)alloc(sizeof(char_u **) * 2); | |
5954 if (expl_files != NULL) | |
5955 { | |
5956 expl_files[0] = vim_strsave(buf); | |
5957 expl_files[1] = NULL; | |
5958 } | |
5959 } | |
5960 vim_free(buf); | |
5961 | |
5962 /* | |
5963 * Count number of names resulting from expansion, | |
5964 * At the same time add a backslash to the end of names that happen to | |
5965 * be directories, and replace slashes with backslashes. | |
5966 */ | |
5967 if (expl_files) | |
5968 { | |
5969 for (i = 0; (p = expl_files[i]) != NULL; i++) | |
5970 { | |
5971 dir = mch_isdir(p); | |
5972 /* If we don't want dirs and this is one, skip it */ | |
5973 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) | |
5974 continue; | |
5975 | |
715 | 5976 /* Skip files that are not executable if we check for that. */ |
6695 | 5977 if (!dir && (flags & EW_EXEC) |
5978 && !mch_can_exe(p, NULL, !(flags & EW_SHELLCMD))) | |
715 | 5979 continue; |
5980 | |
7 | 5981 if (--files_free == 0) |
5982 { | |
5983 /* need more room in table of pointers */ | |
5984 files_alloced += EXPL_ALLOC_INC; | |
5985 *file = (char_u **)vim_realloc(*file, | |
5986 sizeof(char_u **) * files_alloced); | |
5987 if (*file == NULL) | |
5988 { | |
5989 EMSG(_(e_outofmem)); | |
5990 *num_file = 0; | |
5991 return FAIL; | |
5992 } | |
5993 files_free = EXPL_ALLOC_INC; | |
5994 } | |
5995 slash_adjust(p); | |
5996 if (dir) | |
5997 { | |
5998 /* For a directory we add a '/', unless it's already | |
5999 * there. */ | |
6000 len = STRLEN(p); | |
6001 if (((*file)[*num_file] = alloc(len + 2)) != NULL) | |
6002 { | |
6003 STRCPY((*file)[*num_file], p); | |
902 | 6004 if (!after_pathsep((*file)[*num_file], |
6005 (*file)[*num_file] + len)) | |
7 | 6006 { |
6007 (*file)[*num_file][len] = psepc; | |
39 | 6008 (*file)[*num_file][len + 1] = NUL; |
7 | 6009 } |
6010 } | |
6011 } | |
6012 else | |
6013 { | |
6014 (*file)[*num_file] = vim_strsave(p); | |
6015 } | |
6016 | |
6017 /* | |
6018 * Error message already given by either alloc or vim_strsave. | |
6019 * Should return FAIL, but returning OK works also. | |
6020 */ | |
6021 if ((*file)[*num_file] == NULL) | |
6022 break; | |
6023 (*num_file)++; | |
6024 } | |
6025 _fnexplodefree((char **)expl_files); | |
6026 } | |
6027 } | |
6028 return OK; | |
6029 | |
6030 #else /* __EMX__ */ | |
1508 | 6031 /* |
6032 * This is the non-OS/2 implementation (really Unix). | |
6033 */ | |
7 | 6034 int j; |
6035 char_u *tempname; | |
6036 char_u *command; | |
6037 FILE *fd; | |
6038 char_u *buffer; | |
1508 | 6039 #define STYLE_ECHO 0 /* use "echo", the default */ |
6040 #define STYLE_GLOB 1 /* use "glob", for csh */ | |
6041 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
6042 #define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
6043 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
6044 * directly */ | |
7 | 6045 int shell_style = STYLE_ECHO; |
6046 int check_spaces; | |
6047 static int did_find_nul = FALSE; | |
6048 int ampersent = FALSE; | |
1508 | 6049 /* vimglob() function to define for Posix shell */ |
1620 | 6050 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; |
7 | 6051 |
6052 *num_file = 0; /* default: no files found */ | |
6053 *file = NULL; | |
6054 | |
6055 /* | |
6056 * If there are no wildcards, just copy the names to allocated memory. | |
6057 * Saves a lot of time, because we don't have to start a new shell. | |
6058 */ | |
6059 if (!have_wildcard(num_pat, pat)) | |
6060 return save_patterns(num_pat, pat, num_file, file); | |
6061 | |
428 | 6062 # ifdef HAVE_SANDBOX |
6063 /* Don't allow any shell command in the sandbox. */ | |
6064 if (sandbox != 0 && check_secure()) | |
6065 return FAIL; | |
6066 # endif | |
6067 | |
7 | 6068 /* |
6069 * Don't allow the use of backticks in secure and restricted mode. | |
6070 */ | |
428 | 6071 if (secure || restricted) |
7 | 6072 for (i = 0; i < num_pat; ++i) |
6073 if (vim_strchr(pat[i], '`') != NULL | |
6074 && (check_restricted() || check_secure())) | |
6075 return FAIL; | |
6076 | |
6077 /* | |
6078 * get a name for the temp file | |
6079 */ | |
6721 | 6080 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 6081 { |
6082 EMSG(_(e_notmp)); | |
6083 return FAIL; | |
6084 } | |
6085 | |
6086 /* | |
6087 * Let the shell expand the patterns and write the result into the temp | |
1508 | 6088 * file. |
6089 * STYLE_BT: NL separated | |
6090 * If expanding `cmd` execute it directly. | |
6091 * STYLE_GLOB: NUL separated | |
6092 * If we use *csh, "glob" will work better than "echo". | |
6093 * STYLE_PRINT: NL or NUL separated | |
6094 * If we use *zsh, "print -N" will work better than "glob". | |
6095 * STYLE_VIMGLOB: NL separated | |
6096 * If we use *sh*, we define "vimglob()". | |
6097 * STYLE_ECHO: space separated. | |
6098 * A shell we don't know, stay safe and use "echo". | |
7 | 6099 */ |
6100 if (num_pat == 1 && *pat[0] == '`' | |
6101 && (len = STRLEN(pat[0])) > 2 | |
6102 && *(pat[0] + len - 1) == '`') | |
6103 shell_style = STYLE_BT; | |
6104 else if ((len = STRLEN(p_sh)) >= 3) | |
6105 { | |
6106 if (STRCMP(p_sh + len - 3, "csh") == 0) | |
6107 shell_style = STYLE_GLOB; | |
6108 else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
6109 shell_style = STYLE_PRINT; | |
6110 } | |
1508 | 6111 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), |
6112 "sh") != NULL) | |
6113 shell_style = STYLE_VIMGLOB; | |
6114 | |
6115 /* Compute the length of the command. We need 2 extra bytes: for the | |
6116 * optional '&' and for the NUL. | |
6117 * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
7 | 6118 len = STRLEN(tempname) + 29; |
1508 | 6119 if (shell_style == STYLE_VIMGLOB) |
6120 len += STRLEN(sh_vimglob_func); | |
6121 | |
147 | 6122 for (i = 0; i < num_pat; ++i) |
6123 { | |
6124 /* Count the length of the patterns in the same way as they are put in | |
6125 * "command" below. */ | |
6126 #ifdef USE_SYSTEM | |
7 | 6127 len += STRLEN(pat[i]) + 3; /* add space and two quotes */ |
147 | 6128 #else |
6129 ++len; /* add space */ | |
628 | 6130 for (j = 0; pat[i][j] != NUL; ++j) |
6131 { | |
6132 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
6133 ++len; /* may add a backslash */ | |
6134 ++len; | |
6135 } | |
147 | 6136 #endif |
6137 } | |
7 | 6138 command = alloc(len); |
6139 if (command == NULL) | |
6140 { | |
6141 /* out of memory */ | |
6142 vim_free(tempname); | |
6143 return FAIL; | |
6144 } | |
6145 | |
6146 /* | |
6147 * Build the shell command: | |
6148 * - Set $nonomatch depending on EW_NOTFOUND (hopefully the shell | |
6149 * recognizes this). | |
6150 * - Add the shell command to print the expanded names. | |
6151 * - Add the temp file name. | |
6152 * - Add the file name patterns. | |
6153 */ | |
6154 if (shell_style == STYLE_BT) | |
6155 { | |
628 | 6156 /* change `command; command& ` to (command; command ) */ |
6157 STRCPY(command, "("); | |
6158 STRCAT(command, pat[0] + 1); /* exclude first backtick */ | |
7 | 6159 p = command + STRLEN(command) - 1; |
628 | 6160 *p-- = ')'; /* remove last backtick */ |
7 | 6161 while (p > command && vim_iswhite(*p)) |
6162 --p; | |
6163 if (*p == '&') /* remove trailing '&' */ | |
6164 { | |
6165 ampersent = TRUE; | |
6166 *p = ' '; | |
6167 } | |
6168 STRCAT(command, ">"); | |
6169 } | |
6170 else | |
6171 { | |
6172 if (flags & EW_NOTFOUND) | |
6173 STRCPY(command, "set nonomatch; "); | |
6174 else | |
6175 STRCPY(command, "unset nonomatch; "); | |
6176 if (shell_style == STYLE_GLOB) | |
6177 STRCAT(command, "glob >"); | |
6178 else if (shell_style == STYLE_PRINT) | |
6179 STRCAT(command, "print -N >"); | |
1508 | 6180 else if (shell_style == STYLE_VIMGLOB) |
6181 STRCAT(command, sh_vimglob_func); | |
7 | 6182 else |
6183 STRCAT(command, "echo >"); | |
6184 } | |
1508 | 6185 |
7 | 6186 STRCAT(command, tempname); |
1508 | 6187 |
7 | 6188 if (shell_style != STYLE_BT) |
6189 for (i = 0; i < num_pat; ++i) | |
6190 { | |
6191 /* When using system() always add extra quotes, because the shell | |
628 | 6192 * is started twice. Otherwise put a backslash before special |
1450 | 6193 * characters, except inside ``. */ |
7 | 6194 #ifdef USE_SYSTEM |
6195 STRCAT(command, " \""); | |
6196 STRCAT(command, pat[i]); | |
6197 STRCAT(command, "\""); | |
6198 #else | |
233 | 6199 int intick = FALSE; |
6200 | |
7 | 6201 p = command + STRLEN(command); |
6202 *p++ = ' '; | |
628 | 6203 for (j = 0; pat[i][j] != NUL; ++j) |
233 | 6204 { |
6205 if (pat[i][j] == '`') | |
6206 intick = !intick; | |
628 | 6207 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) |
6208 { | |
644 | 6209 /* Remove a backslash, take char literally. But keep |
652 | 6210 * backslash inside backticks, before a special character |
6211 * and before a backtick. */ | |
644 | 6212 if (intick |
652 | 6213 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL |
6214 || pat[i][j + 1] == '`') | |
644 | 6215 *p++ = '\\'; |
648 | 6216 ++j; |
628 | 6217 } |
6174 | 6218 else if (!intick |
6219 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') | |
6220 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) | |
628 | 6221 /* Put a backslash before a special character, but not |
6174 | 6222 * when inside ``. And not for $var when EW_KEEPDOLLAR is |
6223 * set. */ | |
628 | 6224 *p++ = '\\'; |
648 | 6225 |
6226 /* Copy one character. */ | |
6227 *p++ = pat[i][j]; | |
233 | 6228 } |
7 | 6229 *p = NUL; |
6230 #endif | |
6231 } | |
6232 if (flags & EW_SILENT) | |
6233 show_shell_mess = FALSE; | |
6234 if (ampersent) | |
1508 | 6235 STRCAT(command, "&"); /* put the '&' after the redirection */ |
7 | 6236 |
6237 /* | |
6238 * Using zsh -G: If a pattern has no matches, it is just deleted from | |
6239 * the argument list, otherwise zsh gives an error message and doesn't | |
6240 * expand any other pattern. | |
6241 */ | |
6242 if (shell_style == STYLE_PRINT) | |
6243 extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ | |
6244 | |
6245 /* | |
6246 * If we use -f then shell variables set in .cshrc won't get expanded. | |
6247 * vi can do it, so we will too, but it is only necessary if there is a "$" | |
6248 * in one of the patterns, otherwise we can still use the fast option. | |
6249 */ | |
6250 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) | |
6251 extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ | |
6252 | |
6253 /* | |
6254 * execute the shell command | |
6255 */ | |
6256 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); | |
6257 | |
6258 /* When running in the background, give it some time to create the temp | |
6259 * file, but don't wait for it to finish. */ | |
6260 if (ampersent) | |
6261 mch_delay(10L, TRUE); | |
6262 | |
6263 extra_shell_arg = NULL; /* cleanup */ | |
6264 show_shell_mess = TRUE; | |
6265 vim_free(command); | |
6266 | |
1508 | 6267 if (i != 0) /* mch_call_shell() failed */ |
7 | 6268 { |
6269 mch_remove(tempname); | |
6270 vim_free(tempname); | |
6271 /* | |
6272 * With interactive completion, the error message is not printed. | |
6273 * However with USE_SYSTEM, I don't know how to turn off error messages | |
6274 * from the shell, so screen may still get messed up -- webb. | |
6275 */ | |
6276 #ifndef USE_SYSTEM | |
6277 if (!(flags & EW_SILENT)) | |
6278 #endif | |
6279 { | |
6280 redraw_later_clear(); /* probably messed up screen */ | |
6281 msg_putchar('\n'); /* clear bottom line quickly */ | |
6282 cmdline_row = Rows - 1; /* continue on last line */ | |
6283 #ifdef USE_SYSTEM | |
6284 if (!(flags & EW_SILENT)) | |
6285 #endif | |
6286 { | |
6287 MSG(_(e_wildexpand)); | |
6288 msg_start(); /* don't overwrite this message */ | |
6289 } | |
6290 } | |
6291 /* If a `cmd` expansion failed, don't list `cmd` as a match, even when | |
6292 * EW_NOTFOUND is given */ | |
6293 if (shell_style == STYLE_BT) | |
6294 return FAIL; | |
6295 goto notfound; | |
6296 } | |
6297 | |
6298 /* | |
6299 * read the names from the file into memory | |
6300 */ | |
6301 fd = fopen((char *)tempname, READBIN); | |
6302 if (fd == NULL) | |
6303 { | |
6304 /* Something went wrong, perhaps a file name with a special char. */ | |
6305 if (!(flags & EW_SILENT)) | |
6306 { | |
6307 MSG(_(e_wildexpand)); | |
6308 msg_start(); /* don't overwrite this message */ | |
6309 } | |
6310 vim_free(tempname); | |
6311 goto notfound; | |
6312 } | |
6313 fseek(fd, 0L, SEEK_END); | |
6314 len = ftell(fd); /* get size of temp file */ | |
6315 fseek(fd, 0L, SEEK_SET); | |
6316 buffer = alloc(len + 1); | |
6317 if (buffer == NULL) | |
6318 { | |
6319 /* out of memory */ | |
6320 mch_remove(tempname); | |
6321 vim_free(tempname); | |
6322 fclose(fd); | |
6323 return FAIL; | |
6324 } | |
6325 i = fread((char *)buffer, 1, len, fd); | |
6326 fclose(fd); | |
6327 mch_remove(tempname); | |
1877 | 6328 if (i != (int)len) |
7 | 6329 { |
6330 /* unexpected read error */ | |
6331 EMSG2(_(e_notread), tempname); | |
6332 vim_free(tempname); | |
6333 vim_free(buffer); | |
6334 return FAIL; | |
6335 } | |
6336 vim_free(tempname); | |
6337 | |
1508 | 6338 # if defined(__CYGWIN__) || defined(__CYGWIN32__) |
7 | 6339 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ |
6340 p = buffer; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4299
diff
changeset
|
6341 for (i = 0; i < (int)len; ++i) |
7 | 6342 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) |
6343 *p++ = buffer[i]; | |
6344 len = p - buffer; | |
6345 # endif | |
6346 | |
6347 | |
6348 /* file names are separated with Space */ | |
6349 if (shell_style == STYLE_ECHO) | |
6350 { | |
6351 buffer[len] = '\n'; /* make sure the buffer ends in NL */ | |
6352 p = buffer; | |
6353 for (i = 0; *p != '\n'; ++i) /* count number of entries */ | |
6354 { | |
6355 while (*p != ' ' && *p != '\n') | |
6356 ++p; | |
6357 p = skipwhite(p); /* skip to next entry */ | |
6358 } | |
6359 } | |
6360 /* file names are separated with NL */ | |
1508 | 6361 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) |
7 | 6362 { |
6363 buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
6364 p = buffer; | |
6365 for (i = 0; *p != NUL; ++i) /* count number of entries */ | |
6366 { | |
6367 while (*p != '\n' && *p != NUL) | |
6368 ++p; | |
6369 if (*p != NUL) | |
6370 ++p; | |
6371 p = skipwhite(p); /* skip leading white space */ | |
6372 } | |
6373 } | |
6374 /* file names are separated with NUL */ | |
6375 else | |
6376 { | |
6377 /* | |
6378 * Some versions of zsh use spaces instead of NULs to separate | |
6379 * results. Only do this when there is no NUL before the end of the | |
6380 * buffer, otherwise we would never be able to use file names with | |
6381 * embedded spaces when zsh does use NULs. | |
6382 * When we found a NUL once, we know zsh is OK, set did_find_nul and | |
6383 * don't check for spaces again. | |
6384 */ | |
6385 check_spaces = FALSE; | |
6386 if (shell_style == STYLE_PRINT && !did_find_nul) | |
6387 { | |
6388 /* If there is a NUL, set did_find_nul, else set check_spaces */ | |
2768 | 6389 buffer[len] = NUL; |
5533 | 6390 if (len && (int)STRLEN(buffer) < (int)len) |
7 | 6391 did_find_nul = TRUE; |
6392 else | |
6393 check_spaces = TRUE; | |
6394 } | |
6395 | |
6396 /* | |
6397 * Make sure the buffer ends with a NUL. For STYLE_PRINT there | |
6398 * already is one, for STYLE_GLOB it needs to be added. | |
6399 */ | |
6400 if (len && buffer[len - 1] == NUL) | |
6401 --len; | |
6402 else | |
6403 buffer[len] = NUL; | |
6404 i = 0; | |
6405 for (p = buffer; p < buffer + len; ++p) | |
6406 if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ | |
6407 { | |
6408 ++i; | |
6409 *p = NUL; | |
6410 } | |
6411 if (len) | |
6412 ++i; /* count last entry */ | |
6413 } | |
6414 if (i == 0) | |
6415 { | |
6416 /* | |
6417 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I". | |
6418 * /bin/sh will happily expand it to nothing rather than returning an | |
6419 * error; and hey, it's good to check anyway -- webb. | |
6420 */ | |
6421 vim_free(buffer); | |
6422 goto notfound; | |
6423 } | |
6424 *num_file = i; | |
6425 *file = (char_u **)alloc(sizeof(char_u *) * i); | |
6426 if (*file == NULL) | |
6427 { | |
6428 /* out of memory */ | |
6429 vim_free(buffer); | |
6430 return FAIL; | |
6431 } | |
6432 | |
6433 /* | |
6434 * Isolate the individual file names. | |
6435 */ | |
6436 p = buffer; | |
6437 for (i = 0; i < *num_file; ++i) | |
6438 { | |
6439 (*file)[i] = p; | |
6440 /* Space or NL separates */ | |
1508 | 6441 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT |
6442 || shell_style == STYLE_VIMGLOB) | |
7 | 6443 { |
652 | 6444 while (!(shell_style == STYLE_ECHO && *p == ' ') |
6445 && *p != '\n' && *p != NUL) | |
7 | 6446 ++p; |
6447 if (p == buffer + len) /* last entry */ | |
6448 *p = NUL; | |
6449 else | |
6450 { | |
6451 *p++ = NUL; | |
6452 p = skipwhite(p); /* skip to next entry */ | |
6453 } | |
6454 } | |
6455 else /* NUL separates */ | |
6456 { | |
6457 while (*p && p < buffer + len) /* skip entry */ | |
6458 ++p; | |
6459 ++p; /* skip NUL */ | |
6460 } | |
6461 } | |
6462 | |
6463 /* | |
6464 * Move the file names to allocated memory. | |
6465 */ | |
6466 for (j = 0, i = 0; i < *num_file; ++i) | |
6467 { | |
6468 /* Require the files to exist. Helps when using /bin/sh */ | |
6469 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) | |
6470 continue; | |
6471 | |
6472 /* check if this entry should be included */ | |
6473 dir = (mch_isdir((*file)[i])); | |
6474 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) | |
6475 continue; | |
6476 | |
715 | 6477 /* Skip files that are not executable if we check for that. */ |
6695 | 6478 if (!dir && (flags & EW_EXEC) |
6479 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) | |
715 | 6480 continue; |
6481 | |
7 | 6482 p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); |
6483 if (p) | |
6484 { | |
6485 STRCPY(p, (*file)[i]); | |
6486 if (dir) | |
1479 | 6487 add_pathsep(p); /* add '/' to a directory name */ |
7 | 6488 (*file)[j++] = p; |
6489 } | |
6490 } | |
6491 vim_free(buffer); | |
6492 *num_file = j; | |
6493 | |
6494 if (*num_file == 0) /* rejected all entries */ | |
6495 { | |
6496 vim_free(*file); | |
6497 *file = NULL; | |
6498 goto notfound; | |
6499 } | |
6500 | |
6501 return OK; | |
6502 | |
6503 notfound: | |
6504 if (flags & EW_NOTFOUND) | |
6505 return save_patterns(num_pat, pat, num_file, file); | |
6506 return FAIL; | |
6507 | |
6508 #endif /* __EMX__ */ | |
6509 } | |
6510 | |
6511 #endif /* VMS */ | |
6512 | |
6513 #ifndef __EMX__ | |
6514 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6515 save_patterns( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6516 int num_pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6517 char_u **pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6518 int *num_file, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6519 char_u ***file) |
7 | 6520 { |
6521 int i; | |
99 | 6522 char_u *s; |
7 | 6523 |
6524 *file = (char_u **)alloc(num_pat * sizeof(char_u *)); | |
6525 if (*file == NULL) | |
6526 return FAIL; | |
6527 for (i = 0; i < num_pat; i++) | |
99 | 6528 { |
6529 s = vim_strsave(pat[i]); | |
6530 if (s != NULL) | |
6531 /* Be compatible with expand_filename(): halve the number of | |
6532 * backslashes. */ | |
6533 backslash_halve(s); | |
6534 (*file)[i] = s; | |
6535 } | |
7 | 6536 *num_file = num_pat; |
6537 return OK; | |
6538 } | |
6539 #endif | |
6540 | |
6541 /* | |
6542 * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can | |
6543 * expand. | |
6544 */ | |
6545 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6546 mch_has_exp_wildcard(char_u *p) |
7 | 6547 { |
39 | 6548 for ( ; *p; mb_ptr_adv(p)) |
7 | 6549 { |
6550 if (*p == '\\' && p[1] != NUL) | |
6551 ++p; | |
6552 else | |
6553 if (vim_strchr((char_u *) | |
6554 #ifdef VMS | |
6555 "*?%" | |
6556 #else | |
6557 "*?[{'" | |
6558 #endif | |
6559 , *p) != NULL) | |
6560 return TRUE; | |
6561 } | |
6562 return FALSE; | |
6563 } | |
6564 | |
6565 /* | |
6566 * Return TRUE if the string "p" contains a wildcard. | |
6567 * Don't recognize '~' at the end as a wildcard. | |
6568 */ | |
6569 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6570 mch_has_wildcard(char_u *p) |
7 | 6571 { |
39 | 6572 for ( ; *p; mb_ptr_adv(p)) |
7 | 6573 { |
6574 if (*p == '\\' && p[1] != NUL) | |
6575 ++p; | |
6576 else | |
6577 if (vim_strchr((char_u *) | |
6578 #ifdef VMS | |
6579 "*?%$" | |
6580 #else | |
6581 "*?[{`'$" | |
6582 #endif | |
6583 , *p) != NULL | |
6584 || (*p == '~' && p[1] != NUL)) | |
6585 return TRUE; | |
6586 } | |
6587 return FALSE; | |
6588 } | |
6589 | |
6590 #ifndef __EMX__ | |
6591 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6592 have_wildcard(int num, char_u **file) |
7 | 6593 { |
6594 int i; | |
6595 | |
6596 for (i = 0; i < num; i++) | |
6597 if (mch_has_wildcard(file[i])) | |
6598 return 1; | |
6599 return 0; | |
6600 } | |
6601 | |
6602 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6603 have_dollars(int num, char_u **file) |
7 | 6604 { |
6605 int i; | |
6606 | |
6607 for (i = 0; i < num; i++) | |
6608 if (vim_strchr(file[i], '$') != NULL) | |
6609 return TRUE; | |
6610 return FALSE; | |
6611 } | |
6612 #endif /* ifndef __EMX__ */ | |
6613 | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
6614 #if !defined(HAVE_RENAME) || defined(PROTO) |
7 | 6615 /* |
6616 * Scaled-down version of rename(), which is missing in Xenix. | |
6617 * This version can only move regular files and will fail if the | |
6618 * destination exists. | |
6619 */ | |
6620 int | |
8336
d44ff1525ff0
commit https://github.com/vim/vim/commit/fdcc9afb71ea88fe63bbed8bad0d5bae607bfb73
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
6621 mch_rename(const char *src, const char *dest) |
7 | 6622 { |
6623 struct stat st; | |
6624 | |
6625 if (stat(dest, &st) >= 0) /* fail if destination exists */ | |
6626 return -1; | |
6627 if (link(src, dest) != 0) /* link file to new name */ | |
6628 return -1; | |
6629 if (mch_remove(src) == 0) /* delete link to old name */ | |
6630 return 0; | |
6631 return -1; | |
6632 } | |
6633 #endif /* !HAVE_RENAME */ | |
6634 | |
6635 #ifdef FEAT_MOUSE_GPM | |
6636 /* | |
6637 * Initializes connection with gpm (if it isn't already opened) | |
6638 * Return 1 if succeeded (or connection already opened), 0 if failed | |
6639 */ | |
6640 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6641 gpm_open(void) |
7 | 6642 { |
6643 static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ | |
6644 | |
6645 if (!gpm_flag) | |
6646 { | |
6647 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); | |
6648 gpm_connect.defaultMask = ~GPM_HARD; | |
6649 /* Default handling for mouse move*/ | |
6650 gpm_connect.minMod = 0; /* Handle any modifier keys */ | |
6651 gpm_connect.maxMod = 0xffff; | |
6652 if (Gpm_Open(&gpm_connect, 0) > 0) | |
6653 { | |
6654 /* gpm library tries to handling TSTP causes | |
6655 * problems. Anyways, we close connection to Gpm whenever | |
6656 * we are going to suspend or starting an external process | |
1450 | 6657 * so we shouldn't have problem with this |
7 | 6658 */ |
1832 | 6659 # ifdef SIGTSTP |
7 | 6660 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); |
1832 | 6661 # endif |
7 | 6662 return 1; /* succeed */ |
6663 } | |
6664 if (gpm_fd == -2) | |
6665 Gpm_Close(); /* We don't want to talk to xterm via gpm */ | |
6666 return 0; | |
6667 } | |
6668 return 1; /* already open */ | |
6669 } | |
6670 | |
6671 /* | |
6672 * Closes connection to gpm | |
6673 */ | |
6674 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6675 gpm_close(void) |
7 | 6676 { |
6677 if (gpm_flag && gpm_fd >= 0) /* if Open */ | |
6678 Gpm_Close(); | |
6679 } | |
6680 | |
6681 /* Reads gpm event and adds special keys to input buf. Returns length of | |
6682 * generated key sequence. | |
5782 | 6683 * This function is styled after gui_send_mouse_event(). |
7 | 6684 */ |
6685 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6686 mch_gpm_process(void) |
7 | 6687 { |
6688 int button; | |
6689 static Gpm_Event gpm_event; | |
6690 char_u string[6]; | |
6691 int_u vim_modifiers; | |
6692 int row,col; | |
6693 unsigned char buttons_mask; | |
6694 unsigned char gpm_modifiers; | |
6695 static unsigned char old_buttons = 0; | |
6696 | |
6697 Gpm_GetEvent(&gpm_event); | |
6698 | |
6699 #ifdef FEAT_GUI | |
6700 /* Don't put events in the input queue now. */ | |
6701 if (hold_gui_events) | |
6702 return 0; | |
6703 #endif | |
6704 | |
6705 row = gpm_event.y - 1; | |
6706 col = gpm_event.x - 1; | |
6707 | |
6708 string[0] = ESC; /* Our termcode */ | |
6709 string[1] = 'M'; | |
6710 string[2] = 'G'; | |
6711 switch (GPM_BARE_EVENTS(gpm_event.type)) | |
6712 { | |
6713 case GPM_DRAG: | |
6714 string[3] = MOUSE_DRAG; | |
6715 break; | |
6716 case GPM_DOWN: | |
6717 buttons_mask = gpm_event.buttons & ~old_buttons; | |
6718 old_buttons = gpm_event.buttons; | |
6719 switch (buttons_mask) | |
6720 { | |
6721 case GPM_B_LEFT: | |
6722 button = MOUSE_LEFT; | |
6723 break; | |
6724 case GPM_B_MIDDLE: | |
6725 button = MOUSE_MIDDLE; | |
6726 break; | |
6727 case GPM_B_RIGHT: | |
6728 button = MOUSE_RIGHT; | |
6729 break; | |
6730 default: | |
6731 return 0; | |
6732 /*Don't know what to do. Can more than one button be | |
6733 * reported in one event? */ | |
6734 } | |
6735 string[3] = (char_u)(button | 0x20); | |
6736 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); | |
6737 break; | |
6738 case GPM_UP: | |
6739 string[3] = MOUSE_RELEASE; | |
6740 old_buttons &= ~gpm_event.buttons; | |
6741 break; | |
6742 default: | |
6743 return 0; | |
6744 } | |
6745 /*This code is based on gui_x11_mouse_cb in gui_x11.c */ | |
6746 gpm_modifiers = gpm_event.modifiers; | |
6747 vim_modifiers = 0x0; | |
6748 /* I ignore capslock stats. Aren't we all just hate capslock mixing with | |
6749 * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and | |
6750 * K_CAPSSHIFT is defined 8, so it probably isn't even reported | |
6751 */ | |
6752 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) | |
6753 vim_modifiers |= MOUSE_SHIFT; | |
6754 | |
6755 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL))) | |
6756 vim_modifiers |= MOUSE_CTRL; | |
6757 if (gpm_modifiers & ((1 << KG_ALT) | (1 << KG_ALTGR))) | |
6758 vim_modifiers |= MOUSE_ALT; | |
6759 string[3] |= vim_modifiers; | |
6760 string[4] = (char_u)(col + ' ' + 1); | |
6761 string[5] = (char_u)(row + ' ' + 1); | |
6762 add_to_input_buf(string, 6); | |
6763 return 6; | |
6764 } | |
6765 #endif /* FEAT_MOUSE_GPM */ | |
6766 | |
1620 | 6767 #ifdef FEAT_SYSMOUSE |
6768 /* | |
6769 * Initialize connection with sysmouse. | |
6770 * Let virtual console inform us with SIGUSR2 for pending sysmouse | |
6771 * output, any sysmouse output than will be processed via sig_sysmouse(). | |
6772 * Return OK if succeeded, FAIL if failed. | |
6773 */ | |
6774 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6775 sysmouse_open(void) |
1620 | 6776 { |
6777 struct mouse_info mouse; | |
6778 | |
6779 mouse.operation = MOUSE_MODE; | |
6780 mouse.u.mode.mode = 0; | |
6781 mouse.u.mode.signal = SIGUSR2; | |
6782 if (ioctl(1, CONS_MOUSECTL, &mouse) != -1) | |
6783 { | |
6784 signal(SIGUSR2, (RETSIGTYPE (*)())sig_sysmouse); | |
6785 mouse.operation = MOUSE_SHOW; | |
6786 ioctl(1, CONS_MOUSECTL, &mouse); | |
6787 return OK; | |
6788 } | |
6789 return FAIL; | |
6790 } | |
6791 | |
6792 /* | |
6793 * Stop processing SIGUSR2 signals, and also make sure that | |
6794 * virtual console do not send us any sysmouse related signal. | |
6795 */ | |
6796 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6797 sysmouse_close(void) |
1620 | 6798 { |
6799 struct mouse_info mouse; | |
6800 | |
6801 signal(SIGUSR2, restricted ? SIG_IGN : SIG_DFL); | |
6802 mouse.operation = MOUSE_MODE; | |
6803 mouse.u.mode.mode = 0; | |
6804 mouse.u.mode.signal = 0; | |
6805 ioctl(1, CONS_MOUSECTL, &mouse); | |
6806 } | |
6807 | |
6808 /* | |
6809 * Gets info from sysmouse and adds special keys to input buf. | |
6810 */ | |
6811 static RETSIGTYPE | |
6812 sig_sysmouse SIGDEFARG(sigarg) | |
6813 { | |
6814 struct mouse_info mouse; | |
6815 struct video_info video; | |
6816 char_u string[6]; | |
6817 int row, col; | |
6818 int button; | |
6819 int buttons; | |
6820 static int oldbuttons = 0; | |
6821 | |
6822 #ifdef FEAT_GUI | |
6823 /* Don't put events in the input queue now. */ | |
6824 if (hold_gui_events) | |
6825 return; | |
6826 #endif | |
6827 | |
6828 mouse.operation = MOUSE_GETINFO; | |
6829 if (ioctl(1, FBIO_GETMODE, &video.vi_mode) != -1 | |
6830 && ioctl(1, FBIO_MODEINFO, &video) != -1 | |
6831 && ioctl(1, CONS_MOUSECTL, &mouse) != -1 | |
6832 && video.vi_cheight > 0 && video.vi_cwidth > 0) | |
6833 { | |
6834 row = mouse.u.data.y / video.vi_cheight; | |
6835 col = mouse.u.data.x / video.vi_cwidth; | |
6836 buttons = mouse.u.data.buttons; | |
6837 string[0] = ESC; /* Our termcode */ | |
6838 string[1] = 'M'; | |
6839 string[2] = 'S'; | |
6840 if (oldbuttons == buttons && buttons != 0) | |
6841 { | |
6842 button = MOUSE_DRAG; | |
6843 } | |
6844 else | |
6845 { | |
6846 switch (buttons) | |
6847 { | |
6848 case 0: | |
6849 button = MOUSE_RELEASE; | |
6850 break; | |
6851 case 1: | |
6852 button = MOUSE_LEFT; | |
6853 break; | |
6854 case 2: | |
6855 button = MOUSE_MIDDLE; | |
6856 break; | |
6857 case 4: | |
6858 button = MOUSE_RIGHT; | |
6859 break; | |
6860 default: | |
6861 return; | |
6862 } | |
6863 oldbuttons = buttons; | |
6864 } | |
6865 string[3] = (char_u)(button); | |
6866 string[4] = (char_u)(col + ' ' + 1); | |
6867 string[5] = (char_u)(row + ' ' + 1); | |
6868 add_to_input_buf(string, 6); | |
6869 } | |
6870 return; | |
6871 } | |
6872 #endif /* FEAT_SYSMOUSE */ | |
6873 | |
7 | 6874 #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
|
6875 typedef char_u * (*STRPROCSTR)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6876 typedef char_u * (*INTPROCSTR)(int); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6877 typedef int (*STRPROCINT)(char_u *); |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6878 typedef int (*INTPROCINT)(int); |
7 | 6879 |
6880 /* | |
6881 * Call a DLL routine which takes either a string or int param | |
6882 * and returns an allocated string. | |
6883 */ | |
6884 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6885 mch_libcall( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6886 char_u *libname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6887 char_u *funcname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6888 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
|
6889 int argint, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6890 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
|
6891 int *number_result) |
7 | 6892 { |
6893 # if defined(USE_DLOPEN) | |
6894 void *hinstLib; | |
12 | 6895 char *dlerr = NULL; |
7 | 6896 # else |
6897 shl_t hinstLib; | |
6898 # endif | |
6899 STRPROCSTR ProcAdd; | |
6900 INTPROCSTR ProcAddI; | |
6901 char_u *retval_str = NULL; | |
6902 int retval_int = 0; | |
6903 int success = FALSE; | |
6904 | |
900 | 6905 /* |
6906 * Get a handle to the DLL module. | |
6907 */ | |
7 | 6908 # if defined(USE_DLOPEN) |
900 | 6909 /* First clear any error, it's not cleared by the dlopen() call. */ |
6910 (void)dlerror(); | |
6911 | |
7 | 6912 hinstLib = dlopen((char *)libname, RTLD_LAZY |
6913 # ifdef RTLD_LOCAL | |
6914 | RTLD_LOCAL | |
6915 # endif | |
6916 ); | |
12 | 6917 if (hinstLib == NULL) |
6918 { | |
6919 /* "dlerr" must be used before dlclose() */ | |
6920 dlerr = (char *)dlerror(); | |
6921 if (dlerr != NULL) | |
6922 EMSG2(_("dlerror = \"%s\""), dlerr); | |
6923 } | |
7 | 6924 # else |
6925 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); | |
6926 # endif | |
6927 | |
6928 /* If the handle is valid, try to get the function address. */ | |
6929 if (hinstLib != NULL) | |
6930 { | |
6931 # ifdef HAVE_SETJMP_H | |
6932 /* | |
6933 * Catch a crash when calling the library function. For example when | |
6934 * using a number where a string pointer is expected. | |
6935 */ | |
6936 mch_startjmp(); | |
6937 if (SETJMP(lc_jump_env) != 0) | |
6938 { | |
6939 success = FALSE; | |
857 | 6940 # if defined(USE_DLOPEN) |
12 | 6941 dlerr = NULL; |
857 | 6942 # endif |
7 | 6943 mch_didjmp(); |
6944 } | |
6945 else | |
6946 # endif | |
6947 { | |
6948 retval_str = NULL; | |
6949 retval_int = 0; | |
6950 | |
6951 if (argstring != NULL) | |
6952 { | |
6953 # if defined(USE_DLOPEN) | |
6954 ProcAdd = (STRPROCSTR)dlsym(hinstLib, (const char *)funcname); | |
12 | 6955 dlerr = (char *)dlerror(); |
7 | 6956 # else |
6957 if (shl_findsym(&hinstLib, (const char *)funcname, | |
6958 TYPE_PROCEDURE, (void *)&ProcAdd) < 0) | |
6959 ProcAdd = NULL; | |
6960 # endif | |
12 | 6961 if ((success = (ProcAdd != NULL |
6962 # if defined(USE_DLOPEN) | |
6963 && dlerr == NULL | |
6964 # endif | |
6965 ))) | |
7 | 6966 { |
6967 if (string_result == NULL) | |
6968 retval_int = ((STRPROCINT)ProcAdd)(argstring); | |
6969 else | |
6970 retval_str = (ProcAdd)(argstring); | |
6971 } | |
6972 } | |
6973 else | |
6974 { | |
6975 # if defined(USE_DLOPEN) | |
6976 ProcAddI = (INTPROCSTR)dlsym(hinstLib, (const char *)funcname); | |
12 | 6977 dlerr = (char *)dlerror(); |
7 | 6978 # else |
6979 if (shl_findsym(&hinstLib, (const char *)funcname, | |
6980 TYPE_PROCEDURE, (void *)&ProcAddI) < 0) | |
6981 ProcAddI = NULL; | |
6982 # endif | |
12 | 6983 if ((success = (ProcAddI != NULL |
6984 # if defined(USE_DLOPEN) | |
6985 && dlerr == NULL | |
6986 # endif | |
6987 ))) | |
7 | 6988 { |
6989 if (string_result == NULL) | |
6990 retval_int = ((INTPROCINT)ProcAddI)(argint); | |
6991 else | |
6992 retval_str = (ProcAddI)(argint); | |
6993 } | |
6994 } | |
6995 | |
6996 /* Save the string before we free the library. */ | |
6997 /* Assume that a "1" or "-1" result is an illegal pointer. */ | |
6998 if (string_result == NULL) | |
6999 *number_result = retval_int; | |
7000 else if (retval_str != NULL | |
7001 && retval_str != (char_u *)1 | |
7002 && retval_str != (char_u *)-1) | |
7003 *string_result = vim_strsave(retval_str); | |
7004 } | |
7005 | |
7006 # ifdef HAVE_SETJMP_H | |
7007 mch_endjmp(); | |
7008 # ifdef SIGHASARG | |
7009 if (lc_signal != 0) | |
7010 { | |
7011 int i; | |
7012 | |
7013 /* try to find the name of this signal */ | |
7014 for (i = 0; signal_info[i].sig != -1; i++) | |
7015 if (lc_signal == signal_info[i].sig) | |
7016 break; | |
7017 EMSG2("E368: got SIG%s in libcall()", signal_info[i].name); | |
7018 } | |
7019 # endif | |
7020 # endif | |
7021 | |
12 | 7022 # if defined(USE_DLOPEN) |
7023 /* "dlerr" must be used before dlclose() */ | |
7024 if (dlerr != NULL) | |
7025 EMSG2(_("dlerror = \"%s\""), dlerr); | |
7026 | |
7 | 7027 /* Free the DLL module. */ |
7028 (void)dlclose(hinstLib); | |
7029 # else | |
7030 (void)shl_unload(hinstLib); | |
7031 # endif | |
7032 } | |
7033 | |
7034 if (!success) | |
7035 { | |
7036 EMSG2(_(e_libcall), funcname); | |
7037 return FAIL; | |
7038 } | |
7039 | |
7040 return OK; | |
7041 } | |
7042 #endif | |
7043 | |
7044 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) | |
7045 static int xterm_trace = -1; /* default: disabled */ | |
7046 static int xterm_button; | |
7047 | |
7048 /* | |
7049 * Setup a dummy window for X selections in a terminal. | |
7050 */ | |
7051 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7052 setup_term_clip(void) |
7 | 7053 { |
7054 int z = 0; | |
7055 char *strp = ""; | |
7056 Widget AppShell; | |
7057 | |
7058 if (!x_connect_to_server()) | |
7059 return; | |
7060 | |
7061 open_app_context(); | |
7062 if (app_context != NULL && xterm_Shell == (Widget)0) | |
7063 { | |
7064 int (*oldhandler)(); | |
7065 #if defined(HAVE_SETJMP_H) | |
7066 int (*oldIOhandler)(); | |
7067 #endif | |
7068 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
7069 struct timeval start_tv; | |
7070 | |
7071 if (p_verbose > 0) | |
7072 gettimeofday(&start_tv, NULL); | |
7073 # endif | |
7074 | |
7075 /* Ignore X errors while opening the display */ | |
7076 oldhandler = XSetErrorHandler(x_error_check); | |
7077 | |
7078 #if defined(HAVE_SETJMP_H) | |
7079 /* Ignore X IO errors while opening the display */ | |
7080 oldIOhandler = XSetIOErrorHandler(x_IOerror_check); | |
7081 mch_startjmp(); | |
7082 if (SETJMP(lc_jump_env) != 0) | |
7083 { | |
7084 mch_didjmp(); | |
7085 xterm_dpy = NULL; | |
7086 } | |
7087 else | |
7088 #endif | |
7089 { | |
7090 xterm_dpy = XtOpenDisplay(app_context, xterm_display, | |
7091 "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); | |
7092 #if defined(HAVE_SETJMP_H) | |
7093 mch_endjmp(); | |
7094 #endif | |
7095 } | |
7096 | |
7097 #if defined(HAVE_SETJMP_H) | |
7098 /* Now handle X IO errors normally. */ | |
7099 (void)XSetIOErrorHandler(oldIOhandler); | |
7100 #endif | |
7101 /* Now handle X errors normally. */ | |
7102 (void)XSetErrorHandler(oldhandler); | |
7103 | |
7104 if (xterm_dpy == NULL) | |
7105 { | |
7106 if (p_verbose > 0) | |
292 | 7107 verb_msg((char_u *)_("Opening the X display failed")); |
7 | 7108 return; |
7109 } | |
7110 | |
7111 /* Catch terminating error of the X server connection. */ | |
7112 (void)XSetIOErrorHandler(x_IOerror_handler); | |
7113 | |
7114 # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) | |
7115 if (p_verbose > 0) | |
292 | 7116 { |
7117 verbose_enter(); | |
7 | 7118 xopen_message(&start_tv); |
292 | 7119 verbose_leave(); |
7120 } | |
7 | 7121 # endif |
7122 | |
7123 /* Create a Shell to make converters work. */ | |
7124 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", | |
7125 applicationShellWidgetClass, xterm_dpy, | |
7126 NULL); | |
7127 if (AppShell == (Widget)0) | |
7128 return; | |
7129 xterm_Shell = XtVaCreatePopupShell("VIM", | |
7130 topLevelShellWidgetClass, AppShell, | |
7131 XtNmappedWhenManaged, 0, | |
7132 XtNwidth, 1, | |
7133 XtNheight, 1, | |
7134 NULL); | |
7135 if (xterm_Shell == (Widget)0) | |
7136 return; | |
7137 | |
7138 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
|
7139 x11_setup_selection(xterm_Shell); |
7 | 7140 if (x11_display == NULL) |
7141 x11_display = xterm_dpy; | |
7142 | |
7143 XtRealizeWidget(xterm_Shell); | |
7144 XSync(xterm_dpy, False); | |
7145 xterm_update(); | |
7146 } | |
7147 if (xterm_Shell != (Widget)0) | |
7148 { | |
7149 clip_init(TRUE); | |
7150 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) | |
7151 x11_window = (Window)atol(strp); | |
7152 /* Check if $WINDOWID is valid. */ | |
7153 if (test_x11_window(xterm_dpy) == FAIL) | |
7154 x11_window = 0; | |
7155 if (x11_window != 0) | |
7156 xterm_trace = 0; | |
7157 } | |
7158 } | |
7159 | |
7160 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7161 start_xterm_trace(int button) |
7 | 7162 { |
7163 if (x11_window == 0 || xterm_trace < 0 || xterm_Shell == (Widget)0) | |
7164 return; | |
7165 xterm_trace = 1; | |
7166 xterm_button = button; | |
7167 do_xterm_trace(); | |
7168 } | |
7169 | |
7170 | |
7171 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7172 stop_xterm_trace(void) |
7 | 7173 { |
7174 if (xterm_trace < 0) | |
7175 return; | |
7176 xterm_trace = 0; | |
7177 } | |
7178 | |
7179 /* | |
7180 * Query the xterm pointer and generate mouse termcodes if necessary | |
7181 * return TRUE if dragging is active, else FALSE | |
7182 */ | |
7183 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7184 do_xterm_trace(void) |
7 | 7185 { |
7186 Window root, child; | |
7187 int root_x, root_y; | |
7188 int win_x, win_y; | |
7189 int row, col; | |
7190 int_u mask_return; | |
7191 char_u buf[50]; | |
7192 char_u *strp; | |
7193 long got_hints; | |
7194 static char_u *mouse_code; | |
7195 static char_u mouse_name[2] = {KS_MOUSE, KE_FILLER}; | |
7196 static int prev_row = 0, prev_col = 0; | |
7197 static XSizeHints xterm_hints; | |
7198 | |
7199 if (xterm_trace <= 0) | |
7200 return FALSE; | |
7201 | |
7202 if (xterm_trace == 1) | |
7203 { | |
7204 /* Get the hints just before tracking starts. The font size might | |
1510 | 7205 * have changed recently. */ |
7206 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) | |
7207 || !(got_hints & PResizeInc) | |
7 | 7208 || xterm_hints.width_inc <= 1 |
7209 || xterm_hints.height_inc <= 1) | |
7210 { | |
7211 xterm_trace = -1; /* Not enough data -- disable tracing */ | |
7212 return FALSE; | |
7213 } | |
7214 | |
7215 /* Rely on the same mouse code for the duration of this */ | |
7216 mouse_code = find_termcode(mouse_name); | |
7217 prev_row = mouse_row; | |
7009 | 7218 prev_col = mouse_col; |
7 | 7219 xterm_trace = 2; |
7220 | |
7221 /* Find the offset of the chars, there might be a scrollbar on the | |
7222 * left of the window and/or a menu on the top (eterm etc.) */ | |
7223 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7224 &win_x, &win_y, &mask_return); | |
7225 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) | |
7226 - (xterm_hints.height_inc / 2); | |
7227 if (xterm_hints.y <= xterm_hints.height_inc / 2) | |
7228 xterm_hints.y = 2; | |
7229 xterm_hints.x = win_x - (xterm_hints.width_inc * mouse_col) | |
7230 - (xterm_hints.width_inc / 2); | |
7231 if (xterm_hints.x <= xterm_hints.width_inc / 2) | |
7232 xterm_hints.x = 2; | |
7233 return TRUE; | |
7234 } | |
2768 | 7235 if (mouse_code == NULL || STRLEN(mouse_code) > 45) |
7 | 7236 { |
7237 xterm_trace = 0; | |
7238 return FALSE; | |
7239 } | |
7240 | |
7241 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, | |
7242 &win_x, &win_y, &mask_return); | |
7243 | |
7244 row = check_row((win_y - xterm_hints.y) / xterm_hints.height_inc); | |
7245 col = check_col((win_x - xterm_hints.x) / xterm_hints.width_inc); | |
7246 if (row == prev_row && col == prev_col) | |
7247 return TRUE; | |
7248 | |
7249 STRCPY(buf, mouse_code); | |
7250 strp = buf + STRLEN(buf); | |
7251 *strp++ = (xterm_button | MOUSE_DRAG) & ~0x20; | |
7252 *strp++ = (char_u)(col + ' ' + 1); | |
7253 *strp++ = (char_u)(row + ' ' + 1); | |
7254 *strp = 0; | |
7255 add_to_input_buf(buf, STRLEN(buf)); | |
7256 | |
7257 prev_row = row; | |
7258 prev_col = col; | |
7259 return TRUE; | |
7260 } | |
7261 | |
7262 # if defined(FEAT_GUI) || defined(PROTO) | |
7263 /* | |
7264 * Destroy the display, window and app_context. Required for GTK. | |
7265 */ | |
7266 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7267 clear_xterm_clip(void) |
7 | 7268 { |
7269 if (xterm_Shell != (Widget)0) | |
7270 { | |
7271 XtDestroyWidget(xterm_Shell); | |
7272 xterm_Shell = (Widget)0; | |
7273 } | |
7274 if (xterm_dpy != NULL) | |
7275 { | |
1605 | 7276 # if 0 |
7 | 7277 /* Lesstif and Solaris crash here, lose some memory */ |
7278 XtCloseDisplay(xterm_dpy); | |
1605 | 7279 # endif |
7 | 7280 if (x11_display == xterm_dpy) |
7281 x11_display = NULL; | |
7282 xterm_dpy = NULL; | |
7283 } | |
1605 | 7284 # if 0 |
7 | 7285 if (app_context != (XtAppContext)NULL) |
7286 { | |
7287 /* Lesstif and Solaris crash here, lose some memory */ | |
7288 XtDestroyApplicationContext(app_context); | |
7289 app_context = (XtAppContext)NULL; | |
7290 } | |
1605 | 7291 # endif |
7 | 7292 } |
7293 # endif | |
7294 | |
7295 /* | |
4230 | 7296 * Catch up with GUI or X events. |
7297 */ | |
7298 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7299 clip_update(void) |
4230 | 7300 { |
7301 # ifdef FEAT_GUI | |
7302 if (gui.in_use) | |
7303 gui_mch_update(); | |
7304 else | |
7305 # endif | |
7306 if (xterm_Shell != (Widget)0) | |
7307 xterm_update(); | |
7308 } | |
7309 | |
7310 /* | |
7 | 7311 * Catch up with any queued X events. This may put keyboard input into the |
7312 * input buffer, call resize call-backs, trigger timers etc. If there is | |
7313 * nothing in the X event queue (& no timers pending), then we return | |
7314 * immediately. | |
7315 */ | |
7316 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7317 xterm_update(void) |
7 | 7318 { |
7319 XEvent event; | |
7320 | |
6683 | 7321 for (;;) |
7 | 7322 { |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7323 XtInputMask mask = XtAppPending(app_context); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7324 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7325 if (mask == 0 || vim_is_input_buf_full()) |
6683 | 7326 break; |
7327 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7328 if (mask & XtIMXEvent) |
7 | 7329 { |
6683 | 7330 /* 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
|
7331 XtAppNextEvent(app_context, &event); |
6683 | 7332 #ifdef FEAT_CLIENTSERVER |
7333 { | |
7334 XPropertyEvent *e = (XPropertyEvent *)&event; | |
7335 | |
7336 if (e->type == PropertyNotify && e->window == commWindow | |
7 | 7337 && 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
|
7338 serverEventProc(xterm_dpy, &event, 0); |
6683 | 7339 } |
7340 #endif | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7341 XtDispatchEvent(&event); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7342 } |
6683 | 7343 else |
7344 { | |
7345 /* 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
|
7346 XtAppProcessEvent(app_context, mask); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
7347 } |
7 | 7348 } |
7349 } | |
7350 | |
7351 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7352 clip_xterm_own_selection(VimClipboard *cbd) |
7 | 7353 { |
7354 if (xterm_Shell != (Widget)0) | |
7355 return clip_x11_own_selection(xterm_Shell, cbd); | |
7356 return FAIL; | |
7357 } | |
7358 | |
7359 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7360 clip_xterm_lose_selection(VimClipboard *cbd) |
7 | 7361 { |
7362 if (xterm_Shell != (Widget)0) | |
7363 clip_x11_lose_selection(xterm_Shell, cbd); | |
7364 } | |
7365 | |
7366 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7367 clip_xterm_request_selection(VimClipboard *cbd) |
7 | 7368 { |
7369 if (xterm_Shell != (Widget)0) | |
7370 clip_x11_request_selection(xterm_Shell, xterm_dpy, cbd); | |
7371 } | |
7372 | |
7373 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7374 clip_xterm_set_selection(VimClipboard *cbd) |
7 | 7375 { |
7376 clip_x11_set_selection(cbd); | |
7377 } | |
7378 #endif | |
7379 | |
7380 | |
7381 #if defined(USE_XSMP) || defined(PROTO) | |
7382 /* | |
7383 * Code for X Session Management Protocol. | |
7384 */ | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7778
diff
changeset
|
7385 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
|
7386 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
|
7387 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
|
7388 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
|
7389 static void xsmp_ice_connection(IceConn iceConn, IcePointer clientData, Bool opening, IcePointer *watchData); |
7 | 7390 |
7391 | |
7392 # 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
|
7393 static void xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data); |
7 | 7394 |
7395 /* | |
7396 * This is our chance to ask the user if they want to save, | |
7397 * or abort the logout | |
7398 */ | |
7399 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7400 xsmp_handle_interaction(SmcConn smc_conn, SmPointer client_data UNUSED) |
7 | 7401 { |
7402 cmdmod_T save_cmdmod; | |
7403 int cancel_shutdown = False; | |
7404 | |
7405 save_cmdmod = cmdmod; | |
7406 cmdmod.confirm = TRUE; | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7420
diff
changeset
|
7407 if (check_changed_any(FALSE, FALSE)) |
7 | 7408 /* Mustn't logout */ |
7409 cancel_shutdown = True; | |
7410 cmdmod = save_cmdmod; | |
7411 setcursor(); /* position cursor */ | |
7412 out_flush(); | |
7413 | |
7414 /* Done interaction */ | |
7415 SmcInteractDone(smc_conn, cancel_shutdown); | |
7416 | |
7417 /* Finish off | |
7418 * Only end save-yourself here if we're not cancelling shutdown; | |
7419 * we'll get a cancelled callback later in which we'll end it. | |
7420 * Hopefully get around glitchy SMs (like GNOME-1) | |
7421 */ | |
7422 if (!cancel_shutdown) | |
7423 { | |
7424 xsmp.save_yourself = False; | |
7425 SmcSaveYourselfDone(smc_conn, True); | |
7426 } | |
7427 } | |
7428 # endif | |
7429 | |
7430 /* | |
7431 * Callback that starts save-yourself. | |
7432 */ | |
7433 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7434 xsmp_handle_save_yourself( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7435 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7436 SmPointer client_data UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7437 int save_type UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7438 Bool shutdown, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7439 int interact_style UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7440 Bool fast UNUSED) |
7 | 7441 { |
7442 /* Handle already being in saveyourself */ | |
7443 if (xsmp.save_yourself) | |
7444 SmcSaveYourselfDone(smc_conn, True); | |
7445 xsmp.save_yourself = True; | |
7446 xsmp.shutdown = shutdown; | |
7447 | |
7448 /* First up, preserve all files */ | |
7449 out_flush(); | |
7450 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
7451 | |
7452 if (p_verbose > 0) | |
292 | 7453 verb_msg((char_u *)_("XSMP handling save-yourself request")); |
7 | 7454 |
7455 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) | |
7456 /* Now see if we can ask about unsaved files */ | |
7457 if (shutdown && !fast && gui.in_use) | |
7458 /* Need to interact with user, but need SM's permission */ | |
7459 SmcInteractRequest(smc_conn, SmDialogError, | |
7460 xsmp_handle_interaction, client_data); | |
7461 else | |
7462 # endif | |
7463 { | |
7464 /* Can stop the cycle here */ | |
7465 SmcSaveYourselfDone(smc_conn, True); | |
7466 xsmp.save_yourself = False; | |
7467 } | |
7468 } | |
7469 | |
7470 | |
7471 /* | |
7472 * Callback to warn us of imminent death. | |
7473 */ | |
7474 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7475 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED) |
7 | 7476 { |
7477 xsmp_close(); | |
7478 | |
7479 /* quit quickly leaving swapfiles for modified buffers behind */ | |
7480 getout_preserve_modified(0); | |
7481 } | |
7482 | |
7483 | |
7484 /* | |
7485 * Callback to tell us that save-yourself has completed. | |
7486 */ | |
7487 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7488 xsmp_save_complete( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7489 SmcConn smc_conn UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7490 SmPointer client_data UNUSED) |
7 | 7491 { |
7492 xsmp.save_yourself = False; | |
7493 } | |
7494 | |
7495 | |
7496 /* | |
7497 * Callback to tell us that an instigated shutdown was cancelled | |
7498 * (maybe even by us) | |
7499 */ | |
7500 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7501 xsmp_shutdown_cancelled( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7502 SmcConn smc_conn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7503 SmPointer client_data UNUSED) |
7 | 7504 { |
7505 if (xsmp.save_yourself) | |
7506 SmcSaveYourselfDone(smc_conn, True); | |
7507 xsmp.save_yourself = False; | |
7508 xsmp.shutdown = False; | |
7509 } | |
7510 | |
7511 | |
7512 /* | |
7513 * Callback to tell us that a new ICE connection has been established. | |
7514 */ | |
7515 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7516 xsmp_ice_connection( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7517 IceConn iceConn, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7518 IcePointer clientData UNUSED, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7519 Bool opening, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7520 IcePointer *watchData UNUSED) |
7 | 7521 { |
7522 /* Intercept creation of ICE connection fd */ | |
7523 if (opening) | |
7524 { | |
7525 xsmp_icefd = IceConnectionNumber(iceConn); | |
7526 IceRemoveConnectionWatch(xsmp_ice_connection, NULL); | |
7527 } | |
7528 } | |
7529 | |
7530 | |
7531 /* Handle any ICE processing that's required; return FAIL if SM lost */ | |
7532 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7533 xsmp_handle_requests(void) |
7 | 7534 { |
7535 Bool rep; | |
7536 | |
7537 if (IceProcessMessages(xsmp.iceconn, NULL, &rep) | |
7538 == IceProcessMessagesIOError) | |
7539 { | |
7540 /* Lost ICE */ | |
7541 if (p_verbose > 0) | |
292 | 7542 verb_msg((char_u *)_("XSMP lost ICE connection")); |
7 | 7543 xsmp_close(); |
7544 return FAIL; | |
7545 } | |
7546 else | |
7547 return OK; | |
7548 } | |
7549 | |
7550 static int dummy; | |
7551 | |
7552 /* Set up X Session Management Protocol */ | |
7553 void | |
7554 xsmp_init(void) | |
7555 { | |
7556 char errorstring[80]; | |
7557 SmcCallbacks smcallbacks; | |
7558 #if 0 | |
7559 SmPropValue smname; | |
7560 SmProp smnameprop; | |
7561 SmProp *smprops[1]; | |
7562 #endif | |
7563 | |
7564 if (p_verbose > 0) | |
292 | 7565 verb_msg((char_u *)_("XSMP opening connection")); |
7 | 7566 |
7567 xsmp.save_yourself = xsmp.shutdown = False; | |
7568 | |
7569 /* Set up SM callbacks - must have all, even if they're not used */ | |
7570 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; | |
7571 smcallbacks.save_yourself.client_data = NULL; | |
7572 smcallbacks.die.callback = xsmp_die; | |
7573 smcallbacks.die.client_data = NULL; | |
7574 smcallbacks.save_complete.callback = xsmp_save_complete; | |
7575 smcallbacks.save_complete.client_data = NULL; | |
7576 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; | |
7577 smcallbacks.shutdown_cancelled.client_data = NULL; | |
7578 | |
7579 /* Set up a watch on ICE connection creations. The "dummy" argument is | |
7580 * apparently required for FreeBSD (we get a BUS error when using NULL). */ | |
7581 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) | |
7582 { | |
7583 if (p_verbose > 0) | |
292 | 7584 verb_msg((char_u *)_("XSMP ICE connection watch failed")); |
7 | 7585 return; |
7586 } | |
7587 | |
7588 /* Create an SM connection */ | |
7589 xsmp.smcconn = SmcOpenConnection( | |
7590 NULL, | |
7591 NULL, | |
7592 SmProtoMajor, | |
7593 SmProtoMinor, | |
7594 SmcSaveYourselfProcMask | SmcDieProcMask | |
7595 | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
7596 &smcallbacks, | |
7597 NULL, | |
1605 | 7598 &xsmp.clientid, |
7 | 7599 sizeof(errorstring), |
7600 errorstring); | |
7601 if (xsmp.smcconn == NULL) | |
7602 { | |
7603 char errorreport[132]; | |
273 | 7604 |
292 | 7605 if (p_verbose > 0) |
7606 { | |
7607 vim_snprintf(errorreport, sizeof(errorreport), | |
273 | 7608 _("XSMP SmcOpenConnection failed: %s"), errorstring); |
292 | 7609 verb_msg((char_u *)errorreport); |
7610 } | |
7 | 7611 return; |
7612 } | |
7613 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); | |
7614 | |
7615 #if 0 | |
7616 /* ID ourselves */ | |
7617 smname.value = "vim"; | |
7618 smname.length = 3; | |
7619 smnameprop.name = "SmProgram"; | |
7620 smnameprop.type = "SmARRAY8"; | |
7621 smnameprop.num_vals = 1; | |
7622 smnameprop.vals = &smname; | |
7623 | |
7624 smprops[0] = &smnameprop; | |
7625 SmcSetProperties(xsmp.smcconn, 1, smprops); | |
7626 #endif | |
7627 } | |
7628 | |
7629 | |
7630 /* Shut down XSMP comms. */ | |
7631 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7632 xsmp_close(void) |
7 | 7633 { |
7634 if (xsmp_icefd != -1) | |
7635 { | |
7636 SmcCloseConnection(xsmp.smcconn, 0, NULL); | |
1737 | 7637 if (xsmp.clientid != NULL) |
7638 free(xsmp.clientid); | |
1605 | 7639 xsmp.clientid = NULL; |
7 | 7640 xsmp_icefd = -1; |
7641 } | |
7642 } | |
7643 #endif /* USE_XSMP */ | |
7644 | |
7645 | |
7646 #ifdef EBCDIC | |
7647 /* Translate character to its CTRL- value */ | |
7648 char CtrlTable[] = | |
7649 { | |
7650 /* 00 - 5E */ | |
7651 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7652 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7653 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7654 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7655 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7656 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7657 /* ^ */ 0x1E, | |
7658 /* - */ 0x1F, | |
7659 /* 61 - 6C */ | |
7660 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7661 /* _ */ 0x1F, | |
7662 /* 6E - 80 */ | |
7663 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7664 /* a */ 0x01, | |
7665 /* b */ 0x02, | |
7666 /* c */ 0x03, | |
7667 /* d */ 0x37, | |
7668 /* e */ 0x2D, | |
7669 /* f */ 0x2E, | |
7670 /* g */ 0x2F, | |
7671 /* h */ 0x16, | |
7672 /* i */ 0x05, | |
7673 /* 8A - 90 */ | |
7674 0, 0, 0, 0, 0, 0, 0, | |
7675 /* j */ 0x15, | |
7676 /* k */ 0x0B, | |
7677 /* l */ 0x0C, | |
7678 /* m */ 0x0D, | |
7679 /* n */ 0x0E, | |
7680 /* o */ 0x0F, | |
7681 /* p */ 0x10, | |
7682 /* q */ 0x11, | |
7683 /* r */ 0x12, | |
7684 /* 9A - A1 */ | |
7685 0, 0, 0, 0, 0, 0, 0, 0, | |
7686 /* s */ 0x13, | |
7687 /* t */ 0x3C, | |
7688 /* u */ 0x3D, | |
7689 /* v */ 0x32, | |
7690 /* w */ 0x26, | |
7691 /* x */ 0x18, | |
7692 /* y */ 0x19, | |
7693 /* z */ 0x3F, | |
7694 /* AA - AC */ | |
7695 0, 0, 0, | |
7696 /* [ */ 0x27, | |
7697 /* AE - BC */ | |
7698 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7699 /* ] */ 0x1D, | |
7700 /* BE - C0 */ 0, 0, 0, | |
7701 /* A */ 0x01, | |
7702 /* B */ 0x02, | |
7703 /* C */ 0x03, | |
7704 /* D */ 0x37, | |
7705 /* E */ 0x2D, | |
7706 /* F */ 0x2E, | |
7707 /* G */ 0x2F, | |
7708 /* H */ 0x16, | |
7709 /* I */ 0x05, | |
7710 /* CA - D0 */ 0, 0, 0, 0, 0, 0, 0, | |
7711 /* J */ 0x15, | |
7712 /* K */ 0x0B, | |
7713 /* L */ 0x0C, | |
7714 /* M */ 0x0D, | |
7715 /* N */ 0x0E, | |
7716 /* O */ 0x0F, | |
7717 /* P */ 0x10, | |
7718 /* Q */ 0x11, | |
7719 /* R */ 0x12, | |
7720 /* DA - DF */ 0, 0, 0, 0, 0, 0, | |
7721 /* \ */ 0x1C, | |
7722 /* E1 */ 0, | |
7723 /* S */ 0x13, | |
7724 /* T */ 0x3C, | |
7725 /* U */ 0x3D, | |
7726 /* V */ 0x32, | |
7727 /* W */ 0x26, | |
7728 /* X */ 0x18, | |
7729 /* Y */ 0x19, | |
7730 /* Z */ 0x3F, | |
7731 /* EA - FF*/ 0, 0, 0, 0, 0, 0, | |
7732 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
7733 }; | |
7734 | |
7735 char MetaCharTable[]= | |
7736 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
7737 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, | |
7738 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, | |
7739 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, | |
7740 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0 | |
7741 }; | |
7742 | |
7743 | |
7744 /* TODO: Use characters NOT numbers!!! */ | |
7745 char CtrlCharTable[]= | |
7746 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | |
7747 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, | |
7748 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, | |
7749 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, | |
7750 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233, | |
7751 }; | |
7752 | |
7753 | |
7754 #endif |