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