Mercurial > vim
annotate src/if_xcmdsrv.c @ 11177:76fb679a310e v8.0.0475
patch 8.0.0475: not enough testing for the client-server feature
commit https://github.com/vim/vim/commit/7416f3e73ab2c4e7ae3adc2ff6e70234f7d40d2e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 18 18:10:13 2017 +0100
patch 8.0.0475: not enough testing for the client-server feature
Problem: Not enough testing for the client-server feature.
Solution: Add more tests. Add the remote_startserver() function. Fix that
a locally evaluated expression uses function-local variables.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 18 Mar 2017 18:15:04 +0100 |
parents | 501f46f7644c |
children | 13544aa85dc0 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8732
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * X command server by Flemming Madsen | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 * | |
10 * if_xcmdsrv.c: Functions for passing commands through an X11 display. | |
11 * | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
17 #if defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
18 | |
19 # ifdef FEAT_X11 | |
20 # include <X11/Intrinsic.h> | |
21 # include <X11/Xatom.h> | |
22 # endif | |
23 | |
24 /* | |
1121 | 25 * This file provides procedures that implement the command server |
26 * functionality of Vim when in contact with an X11 server. | |
7 | 27 * |
28 * Adapted from TCL/TK's send command in tkSend.c of the tk 3.6 distribution. | |
29 * Adapted for use in Vim by Flemming Madsen. Protocol changed to that of tk 4 | |
30 */ | |
31 | |
32 /* | |
33 * Copyright (c) 1989-1993 The Regents of the University of California. | |
34 * All rights reserved. | |
35 * | |
36 * Permission is hereby granted, without written agreement and without | |
37 * license or royalty fees, to use, copy, modify, and distribute this | |
38 * software and its documentation for any purpose, provided that the | |
39 * above copyright notice and the following two paragraphs appear in | |
40 * all copies of this software. | |
41 * | |
42 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR | |
43 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT | |
44 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF | |
45 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
46 * | |
47 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, | |
48 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | |
49 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | |
50 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO | |
51 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
52 */ | |
53 | |
54 | |
55 /* | |
56 * When a result is being awaited from a sent command, one of | |
57 * the following structures is present on a list of all outstanding | |
58 * sent commands. The information in the structure is used to | |
59 * process the result when it arrives. You're probably wondering | |
60 * how there could ever be multiple outstanding sent commands. | |
61 * This could happen if Vim instances invoke each other recursively. | |
62 * It's unlikely, but possible. | |
63 */ | |
64 | |
65 typedef struct PendingCommand | |
66 { | |
67 int serial; /* Serial number expected in result. */ | |
68 int code; /* Result Code. 0 is OK */ | |
69 char_u *result; /* String result for command (malloc'ed). | |
70 * NULL means command still pending. */ | |
71 struct PendingCommand *nextPtr; | |
72 /* Next in list of all outstanding commands. | |
73 * NULL means end of list. */ | |
74 } PendingCommand; | |
75 | |
76 static PendingCommand *pendingCommands = NULL; | |
77 /* List of all commands currently | |
78 * being waited for. */ | |
79 | |
80 /* | |
81 * The information below is used for communication between processes | |
82 * during "send" commands. Each process keeps a private window, never | |
83 * even mapped, with one property, "Comm". When a command is sent to | |
84 * an interpreter, the command is appended to the comm property of the | |
85 * communication window associated with the interp's process. Similarly, | |
86 * when a result is returned from a sent command, it is also appended | |
87 * to the comm property. | |
88 * | |
89 * Each command and each result takes the form of ASCII text. For a | |
90 * command, the text consists of a nul character followed by several | |
39 | 91 * nul-terminated ASCII strings. The first string consists of a |
92 * single letter: | |
93 * "c" for an expression | |
94 * "k" for keystrokes | |
95 * "r" for reply | |
96 * "n" for notification. | |
97 * Subsequent strings have the form "option value" where the following options | |
98 * are supported: | |
7 | 99 * |
100 * -r commWindow serial | |
101 * | |
102 * This option means that a response should be sent to the window | |
103 * whose X identifier is "commWindow" (in hex), and the response should | |
104 * be identified with the serial number given by "serial" (in decimal). | |
105 * If this option isn't specified then the send is asynchronous and | |
106 * no response is sent. | |
107 * | |
108 * -n name | |
109 * "Name" gives the name of the application for which the command is | |
110 * intended. This option must be present. | |
111 * | |
39 | 112 * -E encoding |
113 * Encoding name used for the text. This is the 'encoding' of the | |
114 * sender. The receiver may want to do conversion to his 'encoding'. | |
115 * | |
7 | 116 * -s script |
117 * "Script" is the script to be executed. This option must be | |
118 * present. Taken as a series of keystrokes in a "k" command where | |
119 * <Key>'s are expanded | |
120 * | |
121 * The options may appear in any order. The -n and -s options must be | |
122 * present, but -r may be omitted for asynchronous RPCs. For compatibility | |
123 * with future releases that may add new features, there may be additional | |
124 * options present; as long as they start with a "-" character, they will | |
125 * be ignored. | |
126 * | |
127 * A result also consists of a zero character followed by several null- | |
128 * terminated ASCII strings. The first string consists of the single | |
129 * letter "r". Subsequent strings have the form "option value" where | |
130 * the following options are supported: | |
131 * | |
132 * -s serial | |
133 * Identifies the command for which this is the result. It is the | |
134 * same as the "serial" field from the -s option in the command. This | |
135 * option must be present. | |
136 * | |
137 * -r result | |
138 * "Result" is the result string for the script, which may be either | |
139 * a result or an error message. If this field is omitted then it | |
140 * defaults to an empty string. | |
141 * | |
142 * -c code | |
143 * 0: for OK. This is the default. | |
144 * 1: for error: Result is the last error | |
145 * | |
146 * -i errorInfo | |
147 * -e errorCode | |
148 * Not applicable for Vim | |
149 * | |
150 * Options may appear in any order, and only the -s option must be | |
151 * present. As with commands, there may be additional options besides | |
152 * these; unknown options are ignored. | |
153 */ | |
154 | |
155 /* | |
156 * Maximum size property that can be read at one time by | |
157 * this module: | |
158 */ | |
159 | |
160 #define MAX_PROP_WORDS 100000 | |
161 | |
162 struct ServerReply | |
163 { | |
164 Window id; | |
165 garray_T strings; | |
166 }; | |
167 static garray_T serverReply = { 0, 0, 0, 0, 0 }; | |
168 enum ServerReplyOp { SROP_Find, SROP_Add, SROP_Delete }; | |
169 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
170 typedef int (*EndCond)(void *); |
7 | 171 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
172 struct x_cmdqueue |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
173 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
174 char_u *propInfo; |
7123
077ae8b63e15
commit https://github.com/vim/vim/commit/b8603882b1679385b287f14c527fa61eee60a9dd
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
175 long_u len; |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
176 struct x_cmdqueue *next; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
177 struct x_cmdqueue *prev; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
178 }; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
179 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
180 typedef struct x_cmdqueue x_queue_T; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
181 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
182 /* dummy node, header for circular queue */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
183 static x_queue_T head = {NULL, 0, NULL, NULL}; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
184 |
7 | 185 /* |
186 * Forward declarations for procedures defined later in this file: | |
187 */ | |
188 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
189 static Window LookupName(Display *dpy, char_u *name, int delete, char_u **loose); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
190 static int SendInit(Display *dpy); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
191 static int DoRegisterName(Display *dpy, char_u *name); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
192 static void DeleteAnyLingerer(Display *dpy, Window w); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
193 static int GetRegProp(Display *dpy, char_u **regPropp, long_u *numItemsp, int domsg); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
194 static int WaitForPend(void *p); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
195 static int WaitForReply(void *p); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
196 static int WindowValid(Display *dpy, Window w); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
197 static void ServerWait(Display *dpy, Window w, EndCond endCond, void *endData, int localLoop, int seconds); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
198 static struct ServerReply *ServerReplyFind(Window w, enum ServerReplyOp op); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
199 static int AppendPropCarefully(Display *display, Window window, Atom property, char_u *value, int length); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
200 static int x_error_check(Display *dpy, XErrorEvent *error_event); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
201 static int IsSerialName(char_u *name); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
202 static void save_in_queue(char_u *buf, long_u len); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7172
diff
changeset
|
203 static void server_parse_message(Display *dpy, char_u *propInfo, long_u numItems); |
7 | 204 |
205 /* Private variables for the "server" functionality */ | |
206 static Atom registryProperty = None; | |
207 static Atom vimProperty = None; | |
208 static int got_x_error = FALSE; | |
209 | |
210 static char_u *empty_prop = (char_u *)""; /* empty GetRegProp() result */ | |
211 | |
212 /* | |
213 * Associate an ASCII name with Vim. Try real hard to get a unique one. | |
214 * Returns FAIL or OK. | |
215 */ | |
216 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
217 serverRegisterName( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
218 Display *dpy, /* display to register with */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
219 char_u *name) /* the name that will be used as a base */ |
7 | 220 { |
221 int i; | |
222 int res; | |
223 char_u *p = NULL; | |
224 | |
225 res = DoRegisterName(dpy, name); | |
226 if (res < 0) | |
227 { | |
228 i = 1; | |
229 do | |
230 { | |
231 if (res < -1 || i >= 1000) | |
232 { | |
233 MSG_ATTR(_("Unable to register a command server name"), | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
234 HL_ATTR(HLF_W)); |
7 | 235 return FAIL; |
236 } | |
237 if (p == NULL) | |
238 p = alloc(STRLEN(name) + 10); | |
239 if (p == NULL) | |
240 { | |
241 res = -10; | |
242 continue; | |
243 } | |
244 sprintf((char *)p, "%s%d", name, i++); | |
245 res = DoRegisterName(dpy, p); | |
246 } | |
247 while (res < 0) | |
248 ; | |
249 vim_free(p); | |
250 } | |
251 return OK; | |
252 } | |
253 | |
254 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
255 DoRegisterName(Display *dpy, char_u *name) |
7 | 256 { |
257 Window w; | |
258 XErrorHandler old_handler; | |
259 #define MAX_NAME_LENGTH 100 | |
260 char_u propInfo[MAX_NAME_LENGTH + 20]; | |
261 | |
262 if (commProperty == None) | |
263 { | |
264 if (SendInit(dpy) < 0) | |
265 return -2; | |
266 } | |
267 | |
268 /* | |
269 * Make sure the name is unique, and append info about it to | |
270 * the registry property. It's important to lock the server | |
271 * here to prevent conflicting changes to the registry property. | |
272 * WARNING: Do not step through this while debugging, it will hangup the X | |
273 * server! | |
274 */ | |
275 XGrabServer(dpy); | |
276 w = LookupName(dpy, name, FALSE, NULL); | |
277 if (w != (Window)0) | |
278 { | |
279 Status status; | |
280 int dummyInt; | |
281 unsigned int dummyUns; | |
282 Window dummyWin; | |
283 | |
284 /* | |
285 * The name is currently registered. See if the commWindow | |
286 * associated with the name exists. If not, or if the commWindow | |
287 * is *our* commWindow, then just unregister the old name (this | |
288 * could happen if an application dies without cleaning up the | |
289 * registry). | |
290 */ | |
291 old_handler = XSetErrorHandler(x_error_check); | |
292 status = XGetGeometry(dpy, w, &dummyWin, &dummyInt, &dummyInt, | |
293 &dummyUns, &dummyUns, &dummyUns, &dummyUns); | |
294 (void)XSetErrorHandler(old_handler); | |
295 if (status != Success && w != commWindow) | |
296 { | |
297 XUngrabServer(dpy); | |
298 XFlush(dpy); | |
299 return -1; | |
300 } | |
301 (void)LookupName(dpy, name, /*delete=*/TRUE, NULL); | |
302 } | |
303 sprintf((char *)propInfo, "%x %.*s", (int_u)commWindow, | |
304 MAX_NAME_LENGTH, name); | |
305 old_handler = XSetErrorHandler(x_error_check); | |
306 got_x_error = FALSE; | |
307 XChangeProperty(dpy, RootWindow(dpy, 0), registryProperty, XA_STRING, 8, | |
308 PropModeAppend, propInfo, STRLEN(propInfo) + 1); | |
309 XUngrabServer(dpy); | |
310 XSync(dpy, False); | |
311 (void)XSetErrorHandler(old_handler); | |
312 | |
313 if (!got_x_error) | |
314 { | |
315 #ifdef FEAT_EVAL | |
316 set_vim_var_string(VV_SEND_SERVER, name, -1); | |
317 #endif | |
318 serverName = vim_strsave(name); | |
319 #ifdef FEAT_TITLE | |
320 need_maketitle = TRUE; | |
321 #endif | |
322 return 0; | |
323 } | |
324 return -2; | |
325 } | |
326 | |
327 #if defined(FEAT_GUI) || defined(PROTO) | |
328 /* | |
329 * Clean out new ID from registry and set it as comm win. | |
330 * Change any registered window ID. | |
331 */ | |
332 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
333 serverChangeRegisteredWindow( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
334 Display *dpy, /* Display to register with */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
335 Window newwin) /* Re-register to this ID */ |
7 | 336 { |
337 char_u propInfo[MAX_NAME_LENGTH + 20]; | |
338 | |
339 commWindow = newwin; | |
340 | |
341 /* Always call SendInit() here, to make sure commWindow is marked as a Vim | |
342 * window. */ | |
343 if (SendInit(dpy) < 0) | |
344 return; | |
345 | |
346 /* WARNING: Do not step through this while debugging, it will hangup the X | |
347 * server! */ | |
348 XGrabServer(dpy); | |
349 DeleteAnyLingerer(dpy, newwin); | |
350 if (serverName != NULL) | |
351 { | |
352 /* Reinsert name if we was already registered */ | |
353 (void)LookupName(dpy, serverName, /*delete=*/TRUE, NULL); | |
354 sprintf((char *)propInfo, "%x %.*s", | |
355 (int_u)newwin, MAX_NAME_LENGTH, serverName); | |
356 XChangeProperty(dpy, RootWindow(dpy, 0), registryProperty, XA_STRING, 8, | |
357 PropModeAppend, (char_u *)propInfo, | |
358 STRLEN(propInfo) + 1); | |
359 } | |
360 XUngrabServer(dpy); | |
361 } | |
362 #endif | |
363 | |
364 /* | |
365 * Send to an instance of Vim via the X display. | |
366 * Returns 0 for OK, negative for an error. | |
367 */ | |
368 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
369 serverSendToVim( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
370 Display *dpy, /* Where to send. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
371 char_u *name, /* Where to send. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
372 char_u *cmd, /* What to send. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
373 char_u **result, /* Result of eval'ed expression */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
374 Window *server, /* Actual ID of receiving app */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
375 Bool asExpr, /* Interpret as keystrokes or expr ? */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
376 Bool localLoop, /* Throw away everything but result */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
377 int silent) /* don't complain about no server */ |
7 | 378 { |
379 Window w; | |
380 char_u *property; | |
381 int length; | |
382 int res; | |
383 static int serial = 0; /* Running count of sent commands. | |
384 * Used to give each command a | |
385 * different serial number. */ | |
386 PendingCommand pending; | |
387 char_u *loosename = NULL; | |
388 | |
389 if (result != NULL) | |
390 *result = NULL; | |
391 if (name == NULL || *name == NUL) | |
392 name = (char_u *)"GVIM"; /* use a default name */ | |
393 | |
394 if (commProperty == None && dpy != NULL) | |
395 { | |
396 if (SendInit(dpy) < 0) | |
397 return -1; | |
398 } | |
399 | |
400 /* Execute locally if no display or target is ourselves */ | |
401 if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0)) | |
11177
76fb679a310e
patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
402 return sendToLocalVim(cmd, asExpr, result); |
7 | 403 |
404 /* | |
405 * Bind the server name to a communication window. | |
406 * | |
407 * Find any survivor with a serialno attached to the name if the | |
408 * original registrant of the wanted name is no longer present. | |
409 * | |
410 * Delete any lingering names from dead editors. | |
411 */ | |
412 while (TRUE) | |
413 { | |
414 w = LookupName(dpy, name, FALSE, &loosename); | |
415 /* Check that the window is hot */ | |
416 if (w != None) | |
417 { | |
418 if (!WindowValid(dpy, w)) | |
419 { | |
420 LookupName(dpy, loosename ? loosename : name, | |
421 /*DELETE=*/TRUE, NULL); | |
422 continue; | |
423 } | |
424 } | |
425 break; | |
426 } | |
427 if (w == None) | |
428 { | |
429 if (!silent) | |
430 EMSG2(_(e_noserver), name); | |
431 return -1; | |
432 } | |
433 else if (loosename != NULL) | |
434 name = loosename; | |
435 if (server != NULL) | |
436 *server = w; | |
437 | |
438 /* | |
439 * Send the command to target interpreter by appending it to the | |
440 * comm window in the communication window. | |
500 | 441 * Length must be computed exactly! |
7 | 442 */ |
39 | 443 #ifdef FEAT_MBYTE |
500 | 444 length = STRLEN(name) + STRLEN(p_enc) + STRLEN(cmd) + 14; |
445 #else | |
446 length = STRLEN(name) + STRLEN(cmd) + 10; | |
39 | 447 #endif |
448 property = (char_u *)alloc((unsigned)length + 30); | |
7 | 449 |
39 | 450 #ifdef FEAT_MBYTE |
451 sprintf((char *)property, "%c%c%c-n %s%c-E %s%c-s %s", | |
452 0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd); | |
453 #else | |
7 | 454 sprintf((char *)property, "%c%c%c-n %s%c-s %s", |
455 0, asExpr ? 'c' : 'k', 0, name, 0, cmd); | |
39 | 456 #endif |
7 | 457 if (name == loosename) |
458 vim_free(loosename); | |
459 /* Add a back reference to our comm window */ | |
460 serial++; | |
461 sprintf((char *)property + length, "%c-r %x %d", | |
462 0, (int_u)commWindow, serial); | |
500 | 463 /* Add length of what "-r %x %d" resulted in, skipping the NUL. */ |
7 | 464 length += STRLEN(property + length + 1) + 1; |
465 | |
466 res = AppendPropCarefully(dpy, w, commProperty, property, length + 1); | |
467 vim_free(property); | |
468 if (res < 0) | |
469 { | |
470 EMSG(_("E248: Failed to send command to the destination program")); | |
471 return -1; | |
472 } | |
473 | |
474 if (!asExpr) /* There is no answer for this - Keys are sent async */ | |
475 return 0; | |
476 | |
477 /* | |
478 * Register the fact that we're waiting for a command to | |
479 * complete (this is needed by SendEventProc and by | |
480 * AppendErrorProc to pass back the command's results). | |
481 */ | |
482 pending.serial = serial; | |
483 pending.code = 0; | |
484 pending.result = NULL; | |
485 pending.nextPtr = pendingCommands; | |
486 pendingCommands = &pending; | |
487 | |
488 ServerWait(dpy, w, WaitForPend, &pending, localLoop, 600); | |
489 | |
490 /* | |
491 * Unregister the information about the pending command | |
492 * and return the result. | |
493 */ | |
494 if (pendingCommands == &pending) | |
495 pendingCommands = pending.nextPtr; | |
496 else | |
497 { | |
498 PendingCommand *pcPtr; | |
499 | |
500 for (pcPtr = pendingCommands; pcPtr != NULL; pcPtr = pcPtr->nextPtr) | |
501 if (pcPtr->nextPtr == &pending) | |
502 { | |
503 pcPtr->nextPtr = pending.nextPtr; | |
504 break; | |
505 } | |
506 } | |
507 if (result != NULL) | |
508 *result = pending.result; | |
509 else | |
510 vim_free(pending.result); | |
511 | |
512 return pending.code == 0 ? 0 : -1; | |
513 } | |
514 | |
515 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
516 WaitForPend(void *p) |
7 | 517 { |
518 PendingCommand *pending = (PendingCommand *) p; | |
519 return pending->result != NULL; | |
520 } | |
521 | |
522 /* | |
523 * Return TRUE if window "w" exists and has a "Vim" property on it. | |
524 */ | |
525 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
526 WindowValid(Display *dpy, Window w) |
7 | 527 { |
528 XErrorHandler old_handler; | |
529 Atom *plist; | |
530 int numProp; | |
531 int i; | |
532 | |
533 old_handler = XSetErrorHandler(x_error_check); | |
534 got_x_error = 0; | |
535 plist = XListProperties(dpy, w, &numProp); | |
536 XSync(dpy, False); | |
537 XSetErrorHandler(old_handler); | |
538 if (plist == NULL || got_x_error) | |
539 return FALSE; | |
540 | |
541 for (i = 0; i < numProp; i++) | |
542 if (plist[i] == vimProperty) | |
543 { | |
544 XFree(plist); | |
545 return TRUE; | |
546 } | |
547 XFree(plist); | |
548 return FALSE; | |
549 } | |
550 | |
551 /* | |
552 * Enter a loop processing X events & polling chars until we see a result | |
553 */ | |
554 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
555 ServerWait( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
556 Display *dpy, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
557 Window w, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
558 EndCond endCond, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
559 void *endData, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
560 int localLoop, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
561 int seconds) |
7 | 562 { |
563 time_t start; | |
564 time_t now; | |
565 XEvent event; | |
3670 | 566 |
567 #define UI_MSEC_DELAY 50 | |
568 #define SEND_MSEC_POLL 500 | |
569 #ifndef HAVE_SELECT | |
570 struct pollfd fds; | |
571 | |
572 fds.fd = ConnectionNumber(dpy); | |
573 fds.events = POLLIN; | |
574 #else | |
575 fd_set fds; | |
576 struct timeval tv; | |
577 | |
578 tv.tv_sec = 0; | |
579 tv.tv_usec = SEND_MSEC_POLL * 1000; | |
580 FD_ZERO(&fds); | |
581 FD_SET(ConnectionNumber(dpy), &fds); | |
582 #endif | |
7 | 583 |
584 time(&start); | |
3670 | 585 while (TRUE) |
7 | 586 { |
3670 | 587 while (XCheckWindowEvent(dpy, commWindow, PropertyChangeMask, &event)) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
588 serverEventProc(dpy, &event, 1); |
8732
29765df3a866
commit https://github.com/vim/vim/commit/1e7885abe8daa793fd9328d0fd6c456214cb467e
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
589 server_parse_messages(); |
3670 | 590 |
591 if (endCond(endData) != 0) | |
592 break; | |
593 if (!WindowValid(dpy, w)) | |
594 break; | |
7 | 595 time(&now); |
596 if (seconds >= 0 && (now - start) >= seconds) | |
597 break; | |
3670 | 598 |
599 /* Just look out for the answer without calling back into Vim */ | |
7 | 600 if (localLoop) |
601 { | |
602 #ifndef HAVE_SELECT | |
603 if (poll(&fds, 1, SEND_MSEC_POLL) < 0) | |
604 break; | |
605 #else | |
3670 | 606 if (select(FD_SETSIZE, &fds, NULL, NULL, &tv) < 0) |
7 | 607 break; |
608 #endif | |
609 } | |
610 else | |
611 { | |
612 if (got_int) | |
613 break; | |
3670 | 614 ui_delay((long)UI_MSEC_DELAY, TRUE); |
7 | 615 ui_breakcheck(); |
616 } | |
617 } | |
618 } | |
619 | |
620 | |
621 /* | |
622 * Fetch a list of all the Vim instance names currently registered for the | |
623 * display. | |
624 * | |
625 * Returns a newline separated list in allocated memory or NULL. | |
626 */ | |
627 char_u * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
628 serverGetVimNames(Display *dpy) |
7 | 629 { |
630 char_u *regProp; | |
631 char_u *entry; | |
632 char_u *p; | |
633 long_u numItems; | |
634 int_u w; | |
635 garray_T ga; | |
636 | |
637 if (registryProperty == None) | |
638 { | |
639 if (SendInit(dpy) < 0) | |
640 return NULL; | |
641 } | |
642 | |
643 /* | |
644 * Read the registry property. | |
645 */ | |
646 if (GetRegProp(dpy, ®Prop, &numItems, TRUE) == FAIL) | |
647 return NULL; | |
648 | |
649 /* | |
650 * Scan all of the names out of the property. | |
651 */ | |
652 ga_init2(&ga, 1, 100); | |
1880 | 653 for (p = regProp; (long_u)(p - regProp) < numItems; p++) |
7 | 654 { |
655 entry = p; | |
656 while (*p != 0 && !isspace(*p)) | |
657 p++; | |
658 if (*p != 0) | |
659 { | |
660 w = None; | |
661 sscanf((char *)entry, "%x", &w); | |
662 if (WindowValid(dpy, (Window)w)) | |
663 { | |
664 ga_concat(&ga, p + 1); | |
665 ga_concat(&ga, (char_u *)"\n"); | |
666 } | |
667 while (*p != 0) | |
668 p++; | |
669 } | |
670 } | |
671 if (regProp != empty_prop) | |
672 XFree(regProp); | |
21 | 673 ga_append(&ga, NUL); |
7 | 674 return ga.ga_data; |
675 } | |
676 | |
677 /* ---------------------------------------------------------- | |
678 * Reply stuff | |
679 */ | |
680 | |
681 static struct ServerReply * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
682 ServerReplyFind(Window w, enum ServerReplyOp op) |
7 | 683 { |
684 struct ServerReply *p; | |
685 struct ServerReply e; | |
686 int i; | |
687 | |
688 p = (struct ServerReply *) serverReply.ga_data; | |
689 for (i = 0; i < serverReply.ga_len; i++, p++) | |
690 if (p->id == w) | |
691 break; | |
692 if (i >= serverReply.ga_len) | |
693 p = NULL; | |
694 | |
695 if (p == NULL && op == SROP_Add) | |
696 { | |
697 if (serverReply.ga_growsize == 0) | |
698 ga_init2(&serverReply, sizeof(struct ServerReply), 1); | |
699 if (ga_grow(&serverReply, 1) == OK) | |
700 { | |
701 p = ((struct ServerReply *) serverReply.ga_data) | |
702 + serverReply.ga_len; | |
703 e.id = w; | |
704 ga_init2(&e.strings, 1, 100); | |
1740 | 705 mch_memmove(p, &e, sizeof(e)); |
7 | 706 serverReply.ga_len++; |
707 } | |
708 } | |
709 else if (p != NULL && op == SROP_Delete) | |
710 { | |
711 ga_clear(&p->strings); | |
712 mch_memmove(p, p + 1, (serverReply.ga_len - i - 1) * sizeof(*p)); | |
713 serverReply.ga_len--; | |
714 } | |
715 | |
716 return p; | |
717 } | |
718 | |
719 /* | |
720 * Convert string to windowid. | |
721 * Issue an error if the id is invalid. | |
722 */ | |
723 Window | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
724 serverStrToWin(char_u *str) |
7 | 725 { |
726 unsigned id = None; | |
727 | |
728 sscanf((char *)str, "0x%x", &id); | |
729 if (id == None) | |
730 EMSG2(_("E573: Invalid server id used: %s"), str); | |
731 | |
732 return (Window)id; | |
733 } | |
734 | |
735 /* | |
39 | 736 * Send a reply string (notification) to client with id "name". |
7 | 737 * Return -1 if the window is invalid. |
738 */ | |
739 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
740 serverSendReply(char_u *name, char_u *str) |
7 | 741 { |
742 char_u *property; | |
743 int length; | |
744 int res; | |
745 Display *dpy = X_DISPLAY; | |
746 Window win = serverStrToWin(name); | |
747 | |
748 if (commProperty == None) | |
749 { | |
750 if (SendInit(dpy) < 0) | |
751 return -2; | |
752 } | |
753 if (!WindowValid(dpy, win)) | |
754 return -1; | |
755 | |
39 | 756 #ifdef FEAT_MBYTE |
500 | 757 length = STRLEN(p_enc) + STRLEN(str) + 14; |
758 #else | |
759 length = STRLEN(str) + 10; | |
39 | 760 #endif |
761 if ((property = (char_u *)alloc((unsigned)length + 30)) != NULL) | |
7 | 762 { |
39 | 763 #ifdef FEAT_MBYTE |
764 sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", | |
765 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); | |
766 #else | |
767 sprintf((char *)property, "%cn%c-n %s%c-w %x", | |
768 0, 0, str, 0, (unsigned int)commWindow); | |
769 #endif | |
500 | 770 /* Add length of what "%x" resulted in. */ |
7 | 771 length += STRLEN(property + length); |
772 res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); | |
773 vim_free(property); | |
774 return res; | |
775 } | |
776 return -1; | |
777 } | |
778 | |
779 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
780 WaitForReply(void *p) |
7 | 781 { |
782 Window *w = (Window *) p; | |
11177
76fb679a310e
patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
783 |
7 | 784 return ServerReplyFind(*w, SROP_Find) != NULL; |
785 } | |
786 | |
787 /* | |
788 * Wait for replies from id (win) | |
789 * Return 0 and the malloc'ed string when a reply is available. | |
790 * Return -1 if the window becomes invalid while waiting. | |
791 */ | |
792 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
793 serverReadReply( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
794 Display *dpy, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
795 Window win, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
796 char_u **str, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
797 int localLoop) |
7 | 798 { |
799 int len; | |
800 char_u *s; | |
801 struct ServerReply *p; | |
802 | |
803 ServerWait(dpy, win, WaitForReply, &win, localLoop, -1); | |
804 | |
805 if ((p = ServerReplyFind(win, SROP_Find)) != NULL && p->strings.ga_len > 0) | |
806 { | |
807 *str = vim_strsave(p->strings.ga_data); | |
808 len = STRLEN(*str) + 1; | |
809 if (len < p->strings.ga_len) | |
810 { | |
811 s = (char_u *) p->strings.ga_data; | |
812 mch_memmove(s, s + len, p->strings.ga_len - len); | |
813 p->strings.ga_len -= len; | |
814 } | |
815 else | |
816 { | |
817 /* Last string read. Remove from list */ | |
818 ga_clear(&p->strings); | |
819 ServerReplyFind(win, SROP_Delete); | |
820 } | |
821 return 0; | |
822 } | |
823 return -1; | |
824 } | |
825 | |
826 /* | |
827 * Check for replies from id (win). | |
828 * Return TRUE and a non-malloc'ed string if there is. Else return FALSE. | |
829 */ | |
830 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
831 serverPeekReply(Display *dpy, Window win, char_u **str) |
7 | 832 { |
833 struct ServerReply *p; | |
834 | |
835 if ((p = ServerReplyFind(win, SROP_Find)) != NULL && p->strings.ga_len > 0) | |
836 { | |
837 if (str != NULL) | |
838 *str = p->strings.ga_data; | |
839 return 1; | |
840 } | |
841 if (!WindowValid(dpy, win)) | |
842 return -1; | |
843 return 0; | |
844 } | |
845 | |
846 | |
847 /* | |
848 * Initialize the communication channels for sending commands and receiving | |
849 * results. | |
850 */ | |
851 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
852 SendInit(Display *dpy) |
7 | 853 { |
854 XErrorHandler old_handler; | |
855 | |
856 /* | |
857 * Create the window used for communication, and set up an | |
858 * event handler for it. | |
859 */ | |
860 old_handler = XSetErrorHandler(x_error_check); | |
861 got_x_error = FALSE; | |
862 | |
863 if (commProperty == None) | |
864 commProperty = XInternAtom(dpy, "Comm", False); | |
865 if (vimProperty == None) | |
866 vimProperty = XInternAtom(dpy, "Vim", False); | |
867 if (registryProperty == None) | |
868 registryProperty = XInternAtom(dpy, "VimRegistry", False); | |
869 | |
870 if (commWindow == None) | |
871 { | |
872 commWindow = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), | |
873 getpid(), 0, 10, 10, 0, | |
874 WhitePixel(dpy, DefaultScreen(dpy)), | |
875 WhitePixel(dpy, DefaultScreen(dpy))); | |
876 XSelectInput(dpy, commWindow, PropertyChangeMask); | |
877 /* WARNING: Do not step through this while debugging, it will hangup | |
878 * the X server! */ | |
879 XGrabServer(dpy); | |
880 DeleteAnyLingerer(dpy, commWindow); | |
881 XUngrabServer(dpy); | |
882 } | |
883 | |
884 /* Make window recognizable as a vim window */ | |
885 XChangeProperty(dpy, commWindow, vimProperty, XA_STRING, | |
886 8, PropModeReplace, (char_u *)VIM_VERSION_SHORT, | |
887 (int)STRLEN(VIM_VERSION_SHORT) + 1); | |
888 | |
889 XSync(dpy, False); | |
890 (void)XSetErrorHandler(old_handler); | |
891 | |
892 return got_x_error ? -1 : 0; | |
893 } | |
894 | |
895 /* | |
896 * Given a server name, see if the name exists in the registry for a | |
897 * particular display. | |
898 * | |
899 * If the given name is registered, return the ID of the window associated | |
900 * with the name. If the name isn't registered, then return 0. | |
901 * | |
902 * Side effects: | |
903 * If the registry property is improperly formed, then it is deleted. | |
904 * If "delete" is non-zero, then if the named server is found it is | |
905 * removed from the registry property. | |
906 */ | |
907 static Window | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
908 LookupName( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
909 Display *dpy, /* Display whose registry to check. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
910 char_u *name, /* Name of a server. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
911 int delete, /* If non-zero, delete info about name. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
912 char_u **loose) /* Do another search matching -999 if not found |
7 | 913 Return result here if a match is found */ |
914 { | |
915 char_u *regProp, *entry; | |
916 char_u *p; | |
917 long_u numItems; | |
918 int_u returnValue; | |
919 | |
920 /* | |
921 * Read the registry property. | |
922 */ | |
923 if (GetRegProp(dpy, ®Prop, &numItems, FALSE) == FAIL) | |
924 return 0; | |
925 | |
926 /* | |
927 * Scan the property for the desired name. | |
928 */ | |
929 returnValue = (int_u)None; | |
930 entry = NULL; /* Not needed, but eliminates compiler warning. */ | |
1880 | 931 for (p = regProp; (long_u)(p - regProp) < numItems; ) |
7 | 932 { |
933 entry = p; | |
934 while (*p != 0 && !isspace(*p)) | |
935 p++; | |
936 if (*p != 0 && STRICMP(name, p + 1) == 0) | |
937 { | |
938 sscanf((char *)entry, "%x", &returnValue); | |
939 break; | |
940 } | |
941 while (*p != 0) | |
942 p++; | |
943 p++; | |
944 } | |
945 | |
946 if (loose != NULL && returnValue == (int_u)None && !IsSerialName(name)) | |
947 { | |
1880 | 948 for (p = regProp; (long_u)(p - regProp) < numItems; ) |
7 | 949 { |
950 entry = p; | |
951 while (*p != 0 && !isspace(*p)) | |
952 p++; | |
953 if (*p != 0 && IsSerialName(p + 1) | |
954 && STRNICMP(name, p + 1, STRLEN(name)) == 0) | |
955 { | |
956 sscanf((char *)entry, "%x", &returnValue); | |
957 *loose = vim_strsave(p + 1); | |
958 break; | |
959 } | |
960 while (*p != 0) | |
961 p++; | |
962 p++; | |
963 } | |
964 } | |
965 | |
966 /* | |
967 * Delete the property, if that is desired (copy down the | |
968 * remainder of the registry property to overlay the deleted | |
969 * info, then rewrite the property). | |
970 */ | |
971 if (delete && returnValue != (int_u)None) | |
972 { | |
973 int count; | |
974 | |
975 while (*p != 0) | |
976 p++; | |
977 p++; | |
978 count = numItems - (p - regProp); | |
979 if (count > 0) | |
1740 | 980 mch_memmove(entry, p, count); |
7 | 981 XChangeProperty(dpy, RootWindow(dpy, 0), registryProperty, XA_STRING, |
982 8, PropModeReplace, regProp, | |
983 (int)(numItems - (p - entry))); | |
984 XSync(dpy, False); | |
985 } | |
986 | |
987 if (regProp != empty_prop) | |
988 XFree(regProp); | |
989 return (Window)returnValue; | |
990 } | |
991 | |
992 /* | |
1197 | 993 * Delete any lingering occurrence of window id. We promise that any |
994 * occurrence is not ours since it is not yet put into the registry (by us) | |
7 | 995 * |
996 * This is necessary in the following scenario: | |
997 * 1. There is an old windowid for an exit'ed vim in the registry | |
998 * 2. We get that id for our commWindow but only want to send, not register. | |
999 * 3. The window will mistakenly be regarded valid because of own commWindow | |
1000 */ | |
1001 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1002 DeleteAnyLingerer( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1003 Display *dpy, /* Display whose registry to check. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1004 Window win) /* Window to remove */ |
7 | 1005 { |
1006 char_u *regProp, *entry = NULL; | |
1007 char_u *p; | |
1008 long_u numItems; | |
28 | 1009 int_u wwin; |
7 | 1010 |
1011 /* | |
1012 * Read the registry property. | |
1013 */ | |
1014 if (GetRegProp(dpy, ®Prop, &numItems, FALSE) == FAIL) | |
1015 return; | |
1016 | |
1017 /* Scan the property for the window id. */ | |
1880 | 1018 for (p = regProp; (long_u)(p - regProp) < numItems; ) |
7 | 1019 { |
1020 if (*p != 0) | |
1021 { | |
28 | 1022 sscanf((char *)p, "%x", &wwin); |
1023 if ((Window)wwin == win) | |
7 | 1024 { |
1025 int lastHalf; | |
1026 | |
1027 /* Copy down the remainder to delete entry */ | |
1028 entry = p; | |
1029 while (*p != 0) | |
1030 p++; | |
1031 p++; | |
1032 lastHalf = numItems - (p - regProp); | |
1033 if (lastHalf > 0) | |
1740 | 1034 mch_memmove(entry, p, lastHalf); |
7 | 1035 numItems = (entry - regProp) + lastHalf; |
1036 p = entry; | |
1037 continue; | |
1038 } | |
1039 } | |
1040 while (*p != 0) | |
1041 p++; | |
1042 p++; | |
1043 } | |
1044 | |
1045 if (entry != NULL) | |
1046 { | |
1047 XChangeProperty(dpy, RootWindow(dpy, 0), registryProperty, | |
1048 XA_STRING, 8, PropModeReplace, regProp, | |
1049 (int)(p - regProp)); | |
1050 XSync(dpy, False); | |
1051 } | |
1052 | |
1053 if (regProp != empty_prop) | |
1054 XFree(regProp); | |
1055 } | |
1056 | |
1057 /* | |
1058 * Read the registry property. Delete it when it's formatted wrong. | |
1059 * Return the property in "regPropp". "empty_prop" is used when it doesn't | |
1060 * exist yet. | |
1061 * Return OK when successful. | |
1062 */ | |
1063 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1064 GetRegProp( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1065 Display *dpy, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1066 char_u **regPropp, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1067 long_u *numItemsp, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1068 int domsg) /* When TRUE give error message. */ |
7 | 1069 { |
1070 int result, actualFormat; | |
1071 long_u bytesAfter; | |
1072 Atom actualType; | |
819 | 1073 XErrorHandler old_handler; |
7 | 1074 |
1075 *regPropp = NULL; | |
819 | 1076 old_handler = XSetErrorHandler(x_error_check); |
1077 got_x_error = FALSE; | |
1078 | |
7 | 1079 result = XGetWindowProperty(dpy, RootWindow(dpy, 0), registryProperty, 0L, |
1080 (long)MAX_PROP_WORDS, False, | |
1081 XA_STRING, &actualType, | |
1082 &actualFormat, numItemsp, &bytesAfter, | |
1083 regPropp); | |
1084 | |
819 | 1085 XSync(dpy, FALSE); |
1086 (void)XSetErrorHandler(old_handler); | |
1087 if (got_x_error) | |
1088 return FAIL; | |
1089 | |
7 | 1090 if (actualType == None) |
1091 { | |
1092 /* No prop yet. Logically equal to the empty list */ | |
1093 *numItemsp = 0; | |
1094 *regPropp = empty_prop; | |
1095 return OK; | |
1096 } | |
1097 | |
1098 /* If the property is improperly formed, then delete it. */ | |
1099 if (result != Success || actualFormat != 8 || actualType != XA_STRING) | |
1100 { | |
1101 if (*regPropp != NULL) | |
1102 XFree(*regPropp); | |
1103 XDeleteProperty(dpy, RootWindow(dpy, 0), registryProperty); | |
1104 if (domsg) | |
1105 EMSG(_("E251: VIM instance registry property is badly formed. Deleted!")); | |
1106 return FAIL; | |
1107 } | |
1108 return OK; | |
1109 } | |
1110 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1111 |
7 | 1112 /* |
1197 | 1113 * This procedure is invoked by the various X event loops throughout Vims when |
7 | 1114 * a property changes on the communication window. This procedure reads the |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1115 * property and enqueues command requests and responses. If immediate is true, |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1116 * it runs the event immediatly instead of enqueuing it. Immediate can cause |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1117 * unintended behavior and should only be used for code that blocks for a |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1118 * response. |
7 | 1119 */ |
1120 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1121 serverEventProc( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1122 Display *dpy, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1123 XEvent *eventPtr, /* Information about event. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1124 int immediate) /* Run event immediately. Should mostly be 0. */ |
7 | 1125 { |
1126 char_u *propInfo; | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1127 int result, actualFormat; |
7 | 1128 long_u numItems, bytesAfter; |
1129 Atom actualType; | |
1130 | |
1131 if (eventPtr != NULL) | |
1132 { | |
1133 if (eventPtr->xproperty.atom != commProperty | |
1134 || eventPtr->xproperty.state != PropertyNewValue) | |
1135 return; | |
1136 } | |
1137 | |
1138 /* | |
1139 * Read the comm property and delete it. | |
1140 */ | |
1141 propInfo = NULL; | |
1142 result = XGetWindowProperty(dpy, commWindow, commProperty, 0L, | |
1143 (long)MAX_PROP_WORDS, True, | |
1144 XA_STRING, &actualType, | |
1145 &actualFormat, &numItems, &bytesAfter, | |
1146 &propInfo); | |
1147 | |
1148 /* If the property doesn't exist or is improperly formed then ignore it. */ | |
1149 if (result != Success || actualType != XA_STRING || actualFormat != 8) | |
1150 { | |
1151 if (propInfo != NULL) | |
1152 XFree(propInfo); | |
1153 return; | |
1154 } | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1155 if (immediate) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1156 server_parse_message(dpy, propInfo, numItems); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1157 else |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1158 save_in_queue(propInfo, numItems); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1159 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1160 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1161 /* |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1162 * Saves x clientserver commands in a queue so that they can be called when |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1163 * vim is idle. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1164 */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1165 static void |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1166 save_in_queue(char_u *propInfo, long_u len) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1167 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1168 x_queue_T *node; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1169 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1170 node = (x_queue_T *)alloc(sizeof(x_queue_T)); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1171 if (node == NULL) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1172 return; /* out of memory */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1173 node->propInfo = propInfo; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1174 node->len = len; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1175 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1176 if (head.next == NULL) /* initialize circular queue */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1177 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1178 head.next = &head; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1179 head.prev = &head; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1180 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1181 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1182 /* insert node at tail of queue */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1183 node->next = &head; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1184 node->prev = head.prev; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1185 head.prev->next = node; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1186 head.prev = node; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1187 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1188 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1189 /* |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1190 * Parses queued clientserver messages. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1191 */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1192 void |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1193 server_parse_messages(void) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1194 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1195 x_queue_T *node; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1196 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1197 if (!X_DISPLAY) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1198 return; /* cannot happen? */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1199 while (head.next != NULL && head.next != &head) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1200 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1201 node = head.next; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1202 head.next = node->next; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1203 node->next->prev = node->prev; |
7172
ad57f5b5bd6c
commit https://github.com/vim/vim/commit/4e86150ec5b5158da92b28938ea55819dc890a14
Christian Brabandt <cb@256bit.org>
parents:
7123
diff
changeset
|
1204 server_parse_message(X_DISPLAY, node->propInfo, node->len); |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1205 vim_free(node); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1206 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1207 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1208 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1209 /* |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1210 * Returns a non-zero value if there are clientserver messages waiting |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1211 * int the queue. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1212 */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1213 int |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1214 server_waiting(void) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1215 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1216 return head.next != NULL && head.next != &head; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1217 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1218 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1219 /* |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1220 * Prases a single clientserver message. A single message may contain multiple |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1221 * commands. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1222 * "propInfo" will be freed. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1223 */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1224 static void |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1225 server_parse_message( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1226 Display *dpy, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1227 char_u *propInfo, /* A string containing 0 or more X commands */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1228 long_u numItems) /* The size of propInfo in bytes. */ |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1229 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1230 char_u *p; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1231 int code; |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1232 char_u *tofree; |
7 | 1233 |
1234 /* | |
1235 * Several commands and results could arrive in the property at | |
1236 * one time; each iteration through the outer loop handles a | |
1237 * single command or result. | |
1238 */ | |
1880 | 1239 for (p = propInfo; (long_u)(p - propInfo) < numItems; ) |
7 | 1240 { |
1241 /* | |
1242 * Ignore leading NULs; each command or result starts with a | |
1243 * NUL so that no matter how badly formed a preceding command | |
1244 * is, we'll be able to tell that a new command/result is | |
1245 * starting. | |
1246 */ | |
1247 if (*p == 0) | |
1248 { | |
1249 p++; | |
1250 continue; | |
1251 } | |
1252 | |
1253 if ((*p == 'c' || *p == 'k') && (p[1] == 0)) | |
1254 { | |
1255 Window resWindow; | |
3668 | 1256 char_u *name, *script, *serial, *end; |
7 | 1257 Bool asKeys = *p == 'k'; |
39 | 1258 char_u *enc; |
7 | 1259 |
1260 /* | |
1261 * This is an incoming command from some other application. | |
1262 * Iterate over all of its options. Stop when we reach | |
1263 * the end of the property or something that doesn't look | |
1264 * like an option. | |
1265 */ | |
1266 p += 2; | |
1267 name = NULL; | |
1268 resWindow = None; | |
1269 serial = (char_u *)""; | |
1270 script = NULL; | |
39 | 1271 enc = NULL; |
1880 | 1272 while ((long_u)(p - propInfo) < numItems && *p == '-') |
7 | 1273 { |
1274 switch (p[1]) | |
1275 { | |
1276 case 'r': | |
1277 end = skipwhite(p + 2); | |
1278 resWindow = 0; | |
1279 while (vim_isxdigit(*end)) | |
1280 { | |
1281 resWindow = 16 * resWindow + (long_u)hex2nr(*end); | |
1282 ++end; | |
1283 } | |
1284 if (end == p + 2 || *end != ' ') | |
1285 resWindow = None; | |
1286 else | |
1287 { | |
1288 p = serial = end + 1; | |
1289 clientWindow = resWindow; /* Remember in global */ | |
1290 } | |
1291 break; | |
1292 case 'n': | |
1293 if (p[2] == ' ') | |
1294 name = p + 3; | |
1295 break; | |
1296 case 's': | |
1297 if (p[2] == ' ') | |
1298 script = p + 3; | |
1299 break; | |
39 | 1300 case 'E': |
1301 if (p[2] == ' ') | |
1302 enc = p + 3; | |
1303 break; | |
7 | 1304 } |
1305 while (*p != 0) | |
1306 p++; | |
1307 p++; | |
1308 } | |
1309 | |
1310 if (script == NULL || name == NULL) | |
1311 continue; | |
1312 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1313 if (serverName != NULL && STRICMP(name, serverName) == 0) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1314 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1315 script = serverConvert(enc, script, &tofree); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1316 if (asKeys) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1317 server_to_input_buf(script); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1318 else |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1319 { |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1320 char_u *res; |
3668 | 1321 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1322 res = eval_client_expr_to_string(script); |
3668 | 1323 if (resWindow != None) |
1324 { | |
1325 garray_T reply; | |
1326 | |
1327 /* Initialize the result property. */ | |
1328 ga_init2(&reply, 1, 100); | |
39 | 1329 #ifdef FEAT_MBYTE |
7009 | 1330 (void)ga_grow(&reply, 50 + STRLEN(p_enc)); |
3668 | 1331 sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ", |
39 | 1332 0, 0, p_enc, 0, serial, 0); |
3668 | 1333 reply.ga_len = 14 + STRLEN(p_enc) + STRLEN(serial); |
39 | 1334 #else |
7009 | 1335 (void)ga_grow(&reply, 50); |
3668 | 1336 sprintf(reply.ga_data, "%cr%c-s %s%c-r ", |
1337 0, 0, serial, 0); | |
1338 reply.ga_len = 10 + STRLEN(serial); | |
39 | 1339 #endif |
3668 | 1340 |
1341 /* Evaluate the expression and return the result. */ | |
1342 if (res != NULL) | |
1343 ga_concat(&reply, res); | |
1344 else | |
1345 { | |
1346 ga_concat(&reply, (char_u *)_(e_invexprmsg)); | |
1347 ga_append(&reply, 0); | |
1348 ga_concat(&reply, (char_u *)"-c 1"); | |
1349 } | |
1350 ga_append(&reply, NUL); | |
1351 (void)AppendPropCarefully(dpy, resWindow, commProperty, | |
1352 reply.ga_data, reply.ga_len); | |
1353 ga_clear(&reply); | |
1354 } | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1355 vim_free(res); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1356 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1357 vim_free(tofree); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1358 } |
7 | 1359 } |
1360 else if (*p == 'r' && p[1] == 0) | |
1361 { | |
39 | 1362 int serial, gotSerial; |
1363 char_u *res; | |
1364 PendingCommand *pcPtr; | |
1365 char_u *enc; | |
7 | 1366 |
1367 /* | |
1368 * This is a reply to some command that we sent out. Iterate | |
1369 * over all of its options. Stop when we reach the end of the | |
1370 * property or something that doesn't look like an option. | |
1371 */ | |
1372 p += 2; | |
1373 gotSerial = 0; | |
1374 res = (char_u *)""; | |
1375 code = 0; | |
39 | 1376 enc = NULL; |
1880 | 1377 while ((long_u)(p - propInfo) < numItems && *p == '-') |
7 | 1378 { |
1379 switch (p[1]) | |
1380 { | |
1381 case 'r': | |
1382 if (p[2] == ' ') | |
1383 res = p + 3; | |
1384 break; | |
39 | 1385 case 'E': |
1386 if (p[2] == ' ') | |
1387 enc = p + 3; | |
1388 break; | |
7 | 1389 case 's': |
1390 if (sscanf((char *)p + 2, " %d", &serial) == 1) | |
1391 gotSerial = 1; | |
1392 break; | |
1393 case 'c': | |
1394 if (sscanf((char *)p + 2, " %d", &code) != 1) | |
1395 code = 0; | |
1396 break; | |
1397 } | |
1398 while (*p != 0) | |
1399 p++; | |
1400 p++; | |
1401 } | |
1402 | |
1403 if (!gotSerial) | |
1404 continue; | |
1405 | |
1406 /* | |
1407 * Give the result information to anyone who's | |
1408 * waiting for it. | |
1409 */ | |
1410 for (pcPtr = pendingCommands; pcPtr != NULL; pcPtr = pcPtr->nextPtr) | |
1411 { | |
1412 if (serial != pcPtr->serial || pcPtr->result != NULL) | |
1413 continue; | |
1414 | |
1415 pcPtr->code = code; | |
7009 | 1416 res = serverConvert(enc, res, &tofree); |
1417 if (tofree == NULL) | |
1418 res = vim_strsave(res); | |
1419 pcPtr->result = res; | |
7 | 1420 break; |
1421 } | |
1422 } | |
1423 else if (*p == 'n' && p[1] == 0) | |
1424 { | |
1425 Window win = 0; | |
1426 unsigned int u; | |
1427 int gotWindow; | |
1428 char_u *str; | |
1429 struct ServerReply *r; | |
39 | 1430 char_u *enc; |
7 | 1431 |
1432 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1433 * This is a (n)otification. Sent with serverreply_send in Vim |
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1434 * script. Execute any autocommand and save it for later retrieval |
7 | 1435 */ |
1436 p += 2; | |
1437 gotWindow = 0; | |
1438 str = (char_u *)""; | |
39 | 1439 enc = NULL; |
1880 | 1440 while ((long_u)(p - propInfo) < numItems && *p == '-') |
7 | 1441 { |
1442 switch (p[1]) | |
1443 { | |
1444 case 'n': | |
1445 if (p[2] == ' ') | |
1446 str = p + 3; | |
1447 break; | |
39 | 1448 case 'E': |
1449 if (p[2] == ' ') | |
1450 enc = p + 3; | |
1451 break; | |
7 | 1452 case 'w': |
1453 if (sscanf((char *)p + 2, " %x", &u) == 1) | |
1454 { | |
1455 win = u; | |
1456 gotWindow = 1; | |
1457 } | |
1458 break; | |
1459 } | |
1460 while (*p != 0) | |
1461 p++; | |
1462 p++; | |
1463 } | |
1464 | |
1465 if (!gotWindow) | |
1466 continue; | |
39 | 1467 str = serverConvert(enc, str, &tofree); |
7 | 1468 if ((r = ServerReplyFind(win, SROP_Add)) != NULL) |
1469 { | |
1470 ga_concat(&(r->strings), str); | |
21 | 1471 ga_append(&(r->strings), NUL); |
7 | 1472 } |
1473 #ifdef FEAT_AUTOCMD | |
1698 | 1474 { |
1475 char_u winstr[30]; | |
1476 | |
1477 sprintf((char *)winstr, "0x%x", (unsigned int)win); | |
1478 apply_autocmds(EVENT_REMOTEREPLY, winstr, str, TRUE, curbuf); | |
1479 } | |
7 | 1480 #endif |
39 | 1481 vim_free(tofree); |
7 | 1482 } |
1483 else | |
1484 { | |
1485 /* | |
1486 * Didn't recognize this thing. Just skip through the next | |
1487 * null character and try again. | |
1488 * Even if we get an 'r'(eply) we will throw it away as we | |
1489 * never specify (and thus expect) one | |
1490 */ | |
1491 while (*p != 0) | |
1492 p++; | |
1493 p++; | |
1494 } | |
1495 } | |
1496 XFree(propInfo); | |
1497 } | |
1498 | |
1499 /* | |
1500 * Append a given property to a given window, but set up an X error handler so | |
1501 * that if the append fails this procedure can return an error code rather | |
1502 * than having Xlib panic. | |
1503 * Return: 0 for OK, -1 for error | |
1504 */ | |
1505 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1506 AppendPropCarefully( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1507 Display *dpy, /* Display on which to operate. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1508 Window window, /* Window whose property is to be modified. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1509 Atom property, /* Name of property. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1510 char_u *value, /* Characters to append to property. */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1511 int length) /* How much to append */ |
7 | 1512 { |
1513 XErrorHandler old_handler; | |
1514 | |
1515 old_handler = XSetErrorHandler(x_error_check); | |
1516 got_x_error = FALSE; | |
1517 XChangeProperty(dpy, window, property, XA_STRING, 8, | |
1518 PropModeAppend, value, length); | |
1519 XSync(dpy, False); | |
1520 (void) XSetErrorHandler(old_handler); | |
1521 return got_x_error ? -1 : 0; | |
1522 } | |
1523 | |
1524 | |
1525 /* | |
1526 * Another X Error handler, just used to check for errors. | |
1527 */ | |
1528 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1529 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
7 | 1530 { |
1531 got_x_error = TRUE; | |
1532 return 0; | |
1533 } | |
1534 | |
1535 /* | |
1536 * Check if "str" looks like it had a serial number appended. | |
1537 * Actually just checks if the name ends in a digit. | |
1538 */ | |
1539 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1540 IsSerialName(char_u *str) |
7 | 1541 { |
1542 int len = STRLEN(str); | |
1543 | |
1544 return (len > 1 && vim_isdigit(str[len - 1])); | |
1545 } | |
1546 #endif /* FEAT_CLIENTSERVER */ |