annotate src/if_xcmdsrv.c @ 10744:f49773e0c392

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