Mercurial > vim
comparison src/if_xcmdsrv.c @ 39:410fa1a31baf v7.0023
updated for version 7.0023
author | vimboss |
---|---|
date | Sun, 19 Dec 2004 22:46:22 +0000 |
parents | 726bdc53fa49 |
children | f529edb9bab3 |
comparison
equal
deleted
inserted
replaced
38:c524f99c7925 | 39:410fa1a31baf |
---|---|
101 * when a result is returned from a sent command, it is also appended | 101 * when a result is returned from a sent command, it is also appended |
102 * to the comm property. | 102 * to the comm property. |
103 * | 103 * |
104 * Each command and each result takes the form of ASCII text. For a | 104 * Each command and each result takes the form of ASCII text. For a |
105 * command, the text consists of a nul character followed by several | 105 * command, the text consists of a nul character followed by several |
106 * nul-terminated ASCII strings. The first string consists of the | 106 * nul-terminated ASCII strings. The first string consists of a |
107 * single letter "c" for an expression, or "k" for keystrokes. Subsequent | 107 * single letter: |
108 * strings have the form "option value" where the following options are | 108 * "c" for an expression |
109 * supported: | 109 * "k" for keystrokes |
110 * "r" for reply | |
111 * "n" for notification. | |
112 * Subsequent strings have the form "option value" where the following options | |
113 * are supported: | |
110 * | 114 * |
111 * -r commWindow serial | 115 * -r commWindow serial |
112 * | 116 * |
113 * This option means that a response should be sent to the window | 117 * This option means that a response should be sent to the window |
114 * whose X identifier is "commWindow" (in hex), and the response should | 118 * whose X identifier is "commWindow" (in hex), and the response should |
117 * no response is sent. | 121 * no response is sent. |
118 * | 122 * |
119 * -n name | 123 * -n name |
120 * "Name" gives the name of the application for which the command is | 124 * "Name" gives the name of the application for which the command is |
121 * intended. This option must be present. | 125 * intended. This option must be present. |
126 * | |
127 * -E encoding | |
128 * Encoding name used for the text. This is the 'encoding' of the | |
129 * sender. The receiver may want to do conversion to his 'encoding'. | |
122 * | 130 * |
123 * -s script | 131 * -s script |
124 * "Script" is the script to be executed. This option must be | 132 * "Script" is the script to be executed. This option must be |
125 * present. Taken as a series of keystrokes in a "k" command where | 133 * present. Taken as a series of keystrokes in a "k" command where |
126 * <Key>'s are expanded | 134 * <Key>'s are expanded |
451 | 459 |
452 /* | 460 /* |
453 * Send the command to target interpreter by appending it to the | 461 * Send the command to target interpreter by appending it to the |
454 * comm window in the communication window. | 462 * comm window in the communication window. |
455 */ | 463 */ |
456 length = STRLEN(name) + STRLEN(cmd) + 10; | 464 length = STRLEN(name) + STRLEN(cmd) + 14; |
457 property = (char_u *)alloc((unsigned) length + 30); | 465 #ifdef FEAT_MBYTE |
458 | 466 length += STRLEN(p_enc); |
467 #endif | |
468 property = (char_u *)alloc((unsigned)length + 30); | |
469 | |
470 #ifdef FEAT_MBYTE | |
471 sprintf((char *)property, "%c%c%c-n %s%c-E %s%c-s %s", | |
472 0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd); | |
473 #else | |
459 sprintf((char *)property, "%c%c%c-n %s%c-s %s", | 474 sprintf((char *)property, "%c%c%c-n %s%c-s %s", |
460 0, asExpr ? 'c' : 'k', 0, name, 0, cmd); | 475 0, asExpr ? 'c' : 'k', 0, name, 0, cmd); |
476 #endif | |
461 if (name == loosename) | 477 if (name == loosename) |
462 vim_free(loosename); | 478 vim_free(loosename); |
463 /* Add a back reference to our comm window */ | 479 /* Add a back reference to our comm window */ |
464 serial++; | 480 serial++; |
465 sprintf((char *)property + length, "%c-r %x %d", | 481 sprintf((char *)property + length, "%c-r %x %d", |
749 | 765 |
750 return (Window)id; | 766 return (Window)id; |
751 } | 767 } |
752 | 768 |
753 /* | 769 /* |
754 * Send a reply string to client with id "name". | 770 * Send a reply string (notification) to client with id "name". |
755 * Return -1 if the window is invalid. | 771 * Return -1 if the window is invalid. |
756 */ | 772 */ |
757 int | 773 int |
758 serverSendReply(name, str) | 774 serverSendReply(name, str) |
759 char_u *name; | 775 char_u *name; |
771 return -2; | 787 return -2; |
772 } | 788 } |
773 if (!WindowValid(dpy, win)) | 789 if (!WindowValid(dpy, win)) |
774 return -1; | 790 return -1; |
775 | 791 |
776 length = STRLEN(str) + 7; | 792 length = STRLEN(str) + 11; |
777 if ((property = (char_u *)alloc((unsigned) length + 30)) != NULL) | 793 #ifdef FEAT_MBYTE |
778 { | 794 length += STRLEN(p_enc); |
779 sprintf((char *)property, "%c%c%c-n %s%c-w %x", | 795 #endif |
780 0, 'n', 0, str, 0, (unsigned int)commWindow); | 796 if ((property = (char_u *)alloc((unsigned)length + 30)) != NULL) |
797 { | |
798 #ifdef FEAT_MBYTE | |
799 sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", | |
800 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); | |
801 #else | |
802 sprintf((char *)property, "%cn%c-n %s%c-w %x", | |
803 0, 0, str, 0, (unsigned int)commWindow); | |
804 #endif | |
781 length += STRLEN(property + length); | 805 length += STRLEN(property + length); |
782 res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); | 806 res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); |
783 vim_free(property); | 807 vim_free(property); |
784 return res; | 808 return res; |
785 } | 809 } |
1127 char_u *propInfo; | 1151 char_u *propInfo; |
1128 char_u *p; | 1152 char_u *p; |
1129 int result, actualFormat, code; | 1153 int result, actualFormat, code; |
1130 long_u numItems, bytesAfter; | 1154 long_u numItems, bytesAfter; |
1131 Atom actualType; | 1155 Atom actualType; |
1156 char_u *tofree; | |
1132 | 1157 |
1133 if (eventPtr != NULL) | 1158 if (eventPtr != NULL) |
1134 { | 1159 { |
1135 if (eventPtr->xproperty.atom != commProperty | 1160 if (eventPtr->xproperty.atom != commProperty |
1136 || eventPtr->xproperty.state != PropertyNewValue) | 1161 || eventPtr->xproperty.state != PropertyNewValue) |
1178 { | 1203 { |
1179 Window resWindow; | 1204 Window resWindow; |
1180 char_u *name, *script, *serial, *end, *res; | 1205 char_u *name, *script, *serial, *end, *res; |
1181 Bool asKeys = *p == 'k'; | 1206 Bool asKeys = *p == 'k'; |
1182 garray_T reply; | 1207 garray_T reply; |
1208 char_u *enc; | |
1183 | 1209 |
1184 /* | 1210 /* |
1185 * This is an incoming command from some other application. | 1211 * This is an incoming command from some other application. |
1186 * Iterate over all of its options. Stop when we reach | 1212 * Iterate over all of its options. Stop when we reach |
1187 * the end of the property or something that doesn't look | 1213 * the end of the property or something that doesn't look |
1190 p += 2; | 1216 p += 2; |
1191 name = NULL; | 1217 name = NULL; |
1192 resWindow = None; | 1218 resWindow = None; |
1193 serial = (char_u *)""; | 1219 serial = (char_u *)""; |
1194 script = NULL; | 1220 script = NULL; |
1221 enc = NULL; | |
1195 while (p - propInfo < numItems && *p == '-') | 1222 while (p - propInfo < numItems && *p == '-') |
1196 { | 1223 { |
1197 switch (p[1]) | 1224 switch (p[1]) |
1198 { | 1225 { |
1199 case 'r': | 1226 case 'r': |
1218 break; | 1245 break; |
1219 case 's': | 1246 case 's': |
1220 if (p[2] == ' ') | 1247 if (p[2] == ' ') |
1221 script = p + 3; | 1248 script = p + 3; |
1222 break; | 1249 break; |
1250 case 'E': | |
1251 if (p[2] == ' ') | |
1252 enc = p + 3; | |
1253 break; | |
1223 } | 1254 } |
1224 while (*p != 0) | 1255 while (*p != 0) |
1225 p++; | 1256 p++; |
1226 p++; | 1257 p++; |
1227 } | 1258 } |
1234 * time if we need to return an error. | 1265 * time if we need to return an error. |
1235 */ | 1266 */ |
1236 if (resWindow != None) | 1267 if (resWindow != None) |
1237 { | 1268 { |
1238 ga_init2(&reply, 1, 100); | 1269 ga_init2(&reply, 1, 100); |
1270 #ifdef FEAT_MBYTE | |
1271 ga_grow(&reply, 50 + STRLEN(p_enc)); | |
1272 sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ", | |
1273 0, 0, p_enc, 0, serial, 0); | |
1274 #else | |
1239 ga_grow(&reply, 50); | 1275 ga_grow(&reply, 50); |
1240 sprintf(reply.ga_data, "%cr%c-s %s%c-r ", 0, 0, serial, 0); | 1276 sprintf(reply.ga_data, "%cr%c-s %s%c-r ", 0, 0, serial, 0); |
1277 #endif | |
1241 reply.ga_len = 10 + STRLEN(serial); | 1278 reply.ga_len = 10 + STRLEN(serial); |
1242 reply.ga_room -= reply.ga_len; | 1279 reply.ga_room -= reply.ga_len; |
1243 } | 1280 } |
1244 res = NULL; | 1281 res = NULL; |
1245 if (serverName != NULL && STRICMP(name, serverName) == 0) | 1282 if (serverName != NULL && STRICMP(name, serverName) == 0) |
1246 { | 1283 { |
1284 script = serverConvert(enc, script, &tofree); | |
1247 if (asKeys) | 1285 if (asKeys) |
1248 server_to_input_buf(script); | 1286 server_to_input_buf(script); |
1249 else | 1287 else |
1250 res = eval_client_expr_to_string(script); | 1288 res = eval_client_expr_to_string(script); |
1289 vim_free(tofree); | |
1251 } | 1290 } |
1252 if (resWindow != None) | 1291 if (resWindow != None) |
1253 { | 1292 { |
1254 if (res != NULL) | 1293 if (res != NULL) |
1255 ga_concat(&reply, res); | 1294 ga_concat(&reply, res); |
1260 ga_concat(&reply, (char_u *)"-c 1"); | 1299 ga_concat(&reply, (char_u *)"-c 1"); |
1261 } | 1300 } |
1262 ga_append(&reply, NUL); | 1301 ga_append(&reply, NUL); |
1263 (void)AppendPropCarefully(dpy, resWindow, commProperty, | 1302 (void)AppendPropCarefully(dpy, resWindow, commProperty, |
1264 reply.ga_data, reply.ga_len); | 1303 reply.ga_data, reply.ga_len); |
1304 ga_clear(&reply); | |
1265 } | 1305 } |
1266 vim_free(res); | 1306 vim_free(res); |
1267 } | 1307 } |
1268 else if (*p == 'r' && p[1] == 0) | 1308 else if (*p == 'r' && p[1] == 0) |
1269 { | 1309 { |
1270 int serial, gotSerial; | 1310 int serial, gotSerial; |
1271 char_u *res; | 1311 char_u *res; |
1272 PendingCommand *pcPtr; | 1312 PendingCommand *pcPtr; |
1313 char_u *enc; | |
1273 | 1314 |
1274 /* | 1315 /* |
1275 * This is a reply to some command that we sent out. Iterate | 1316 * This is a reply to some command that we sent out. Iterate |
1276 * over all of its options. Stop when we reach the end of the | 1317 * over all of its options. Stop when we reach the end of the |
1277 * property or something that doesn't look like an option. | 1318 * property or something that doesn't look like an option. |
1278 */ | 1319 */ |
1279 p += 2; | 1320 p += 2; |
1280 gotSerial = 0; | 1321 gotSerial = 0; |
1281 res = (char_u *)""; | 1322 res = (char_u *)""; |
1282 code = 0; | 1323 code = 0; |
1324 enc = NULL; | |
1283 while ((p-propInfo) < numItems && *p == '-') | 1325 while ((p-propInfo) < numItems && *p == '-') |
1284 { | 1326 { |
1285 switch (p[1]) | 1327 switch (p[1]) |
1286 { | 1328 { |
1287 case 'r': | 1329 case 'r': |
1288 if (p[2] == ' ') | 1330 if (p[2] == ' ') |
1289 res = p + 3; | 1331 res = p + 3; |
1332 break; | |
1333 case 'E': | |
1334 if (p[2] == ' ') | |
1335 enc = p + 3; | |
1290 break; | 1336 break; |
1291 case 's': | 1337 case 's': |
1292 if (sscanf((char *)p + 2, " %d", &serial) == 1) | 1338 if (sscanf((char *)p + 2, " %d", &serial) == 1) |
1293 gotSerial = 1; | 1339 gotSerial = 1; |
1294 break; | 1340 break; |
1314 if (serial != pcPtr->serial || pcPtr->result != NULL) | 1360 if (serial != pcPtr->serial || pcPtr->result != NULL) |
1315 continue; | 1361 continue; |
1316 | 1362 |
1317 pcPtr->code = code; | 1363 pcPtr->code = code; |
1318 if (res != NULL) | 1364 if (res != NULL) |
1319 pcPtr->result = vim_strsave(res); | 1365 { |
1366 res = serverConvert(enc, res, &tofree); | |
1367 if (tofree == NULL) | |
1368 res = vim_strsave(res); | |
1369 pcPtr->result = res; | |
1370 } | |
1320 else | 1371 else |
1321 pcPtr->result = vim_strsave((char_u *)""); | 1372 pcPtr->result = vim_strsave((char_u *)""); |
1322 break; | 1373 break; |
1323 } | 1374 } |
1324 } | 1375 } |
1328 unsigned int u; | 1379 unsigned int u; |
1329 int gotWindow; | 1380 int gotWindow; |
1330 char_u *str; | 1381 char_u *str; |
1331 char_u winstr[30]; | 1382 char_u winstr[30]; |
1332 struct ServerReply *r; | 1383 struct ServerReply *r; |
1384 char_u *enc; | |
1333 | 1385 |
1334 /* | 1386 /* |
1335 * This is a (n)otification. Sent with serverreply_send in VimL. | 1387 * This is a (n)otification. Sent with serverreply_send in VimL. |
1336 * Execute any autocommand and save it for later retrieval | 1388 * Execute any autocommand and save it for later retrieval |
1337 */ | 1389 */ |
1338 p += 2; | 1390 p += 2; |
1339 gotWindow = 0; | 1391 gotWindow = 0; |
1340 str = (char_u *)""; | 1392 str = (char_u *)""; |
1393 enc = NULL; | |
1341 while ((p-propInfo) < numItems && *p == '-') | 1394 while ((p-propInfo) < numItems && *p == '-') |
1342 { | 1395 { |
1343 switch (p[1]) | 1396 switch (p[1]) |
1344 { | 1397 { |
1345 case 'n': | 1398 case 'n': |
1346 if (p[2] == ' ') | 1399 if (p[2] == ' ') |
1347 str = p + 3; | 1400 str = p + 3; |
1401 break; | |
1402 case 'E': | |
1403 if (p[2] == ' ') | |
1404 enc = p + 3; | |
1348 break; | 1405 break; |
1349 case 'w': | 1406 case 'w': |
1350 if (sscanf((char *)p + 2, " %x", &u) == 1) | 1407 if (sscanf((char *)p + 2, " %x", &u) == 1) |
1351 { | 1408 { |
1352 win = u; | 1409 win = u; |
1359 p++; | 1416 p++; |
1360 } | 1417 } |
1361 | 1418 |
1362 if (!gotWindow) | 1419 if (!gotWindow) |
1363 continue; | 1420 continue; |
1421 str = serverConvert(enc, str, &tofree); | |
1364 if ((r = ServerReplyFind(win, SROP_Add)) != NULL) | 1422 if ((r = ServerReplyFind(win, SROP_Add)) != NULL) |
1365 { | 1423 { |
1366 ga_concat(&(r->strings), str); | 1424 ga_concat(&(r->strings), str); |
1367 ga_append(&(r->strings), NUL); | 1425 ga_append(&(r->strings), NUL); |
1368 } | 1426 } |
1369 #ifdef FEAT_AUTOCMD | 1427 #ifdef FEAT_AUTOCMD |
1370 sprintf((char *)winstr, "0x%x", (unsigned int)win); | 1428 sprintf((char *)winstr, "0x%x", (unsigned int)win); |
1371 apply_autocmds(EVENT_REMOTEREPLY, winstr, str, TRUE, curbuf); | 1429 apply_autocmds(EVENT_REMOTEREPLY, winstr, str, TRUE, curbuf); |
1372 #endif | 1430 #endif |
1373 | 1431 vim_free(tofree); |
1374 } | 1432 } |
1375 else | 1433 else |
1376 { | 1434 { |
1377 /* | 1435 /* |
1378 * Didn't recognize this thing. Just skip through the next | 1436 * Didn't recognize this thing. Just skip through the next |