annotate src/if_xcmdsrv.c @ 40:01573c245f15

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