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