Mercurial > vim
comparison src/if_xcmdsrv.c @ 7823:bcef391c101c v7.4.1208
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 30 17:24:07 2016 +0100
patch 7.4.1208
Problem: Using old style function declarations.
Solution: Change to new style function declarations. (script by Hirohito
Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Jan 2016 17:30:04 +0100 |
parents | 37c929c4a073 |
children | 29765df3a866 |
comparison
equal
deleted
inserted
replaced
7822:c357d21dc1b5 | 7823:bcef391c101c |
---|---|
212 /* | 212 /* |
213 * Associate an ASCII name with Vim. Try real hard to get a unique one. | 213 * Associate an ASCII name with Vim. Try real hard to get a unique one. |
214 * Returns FAIL or OK. | 214 * Returns FAIL or OK. |
215 */ | 215 */ |
216 int | 216 int |
217 serverRegisterName(dpy, name) | 217 serverRegisterName( |
218 Display *dpy; /* display to register with */ | 218 Display *dpy, /* display to register with */ |
219 char_u *name; /* the name that will be used as a base */ | 219 char_u *name) /* the name that will be used as a base */ |
220 { | 220 { |
221 int i; | 221 int i; |
222 int res; | 222 int res; |
223 char_u *p = NULL; | 223 char_u *p = NULL; |
224 | 224 |
250 } | 250 } |
251 return OK; | 251 return OK; |
252 } | 252 } |
253 | 253 |
254 static int | 254 static int |
255 DoRegisterName(dpy, name) | 255 DoRegisterName(Display *dpy, char_u *name) |
256 Display *dpy; | |
257 char_u *name; | |
258 { | 256 { |
259 Window w; | 257 Window w; |
260 XErrorHandler old_handler; | 258 XErrorHandler old_handler; |
261 #define MAX_NAME_LENGTH 100 | 259 #define MAX_NAME_LENGTH 100 |
262 char_u propInfo[MAX_NAME_LENGTH + 20]; | 260 char_u propInfo[MAX_NAME_LENGTH + 20]; |
330 /* | 328 /* |
331 * Clean out new ID from registry and set it as comm win. | 329 * Clean out new ID from registry and set it as comm win. |
332 * Change any registered window ID. | 330 * Change any registered window ID. |
333 */ | 331 */ |
334 void | 332 void |
335 serverChangeRegisteredWindow(dpy, newwin) | 333 serverChangeRegisteredWindow( |
336 Display *dpy; /* Display to register with */ | 334 Display *dpy, /* Display to register with */ |
337 Window newwin; /* Re-register to this ID */ | 335 Window newwin) /* Re-register to this ID */ |
338 { | 336 { |
339 char_u propInfo[MAX_NAME_LENGTH + 20]; | 337 char_u propInfo[MAX_NAME_LENGTH + 20]; |
340 | 338 |
341 commWindow = newwin; | 339 commWindow = newwin; |
342 | 340 |
366 /* | 364 /* |
367 * Send to an instance of Vim via the X display. | 365 * Send to an instance of Vim via the X display. |
368 * Returns 0 for OK, negative for an error. | 366 * Returns 0 for OK, negative for an error. |
369 */ | 367 */ |
370 int | 368 int |
371 serverSendToVim(dpy, name, cmd, result, server, asExpr, localLoop, silent) | 369 serverSendToVim( |
372 Display *dpy; /* Where to send. */ | 370 Display *dpy, /* Where to send. */ |
373 char_u *name; /* Where to send. */ | 371 char_u *name, /* Where to send. */ |
374 char_u *cmd; /* What to send. */ | 372 char_u *cmd, /* What to send. */ |
375 char_u **result; /* Result of eval'ed expression */ | 373 char_u **result, /* Result of eval'ed expression */ |
376 Window *server; /* Actual ID of receiving app */ | 374 Window *server, /* Actual ID of receiving app */ |
377 Bool asExpr; /* Interpret as keystrokes or expr ? */ | 375 Bool asExpr, /* Interpret as keystrokes or expr ? */ |
378 Bool localLoop; /* Throw away everything but result */ | 376 Bool localLoop, /* Throw away everything but result */ |
379 int silent; /* don't complain about no server */ | 377 int silent) /* don't complain about no server */ |
380 { | 378 { |
381 Window w; | 379 Window w; |
382 char_u *property; | 380 char_u *property; |
383 int length; | 381 int length; |
384 int res; | 382 int res; |
533 | 531 |
534 return pending.code == 0 ? 0 : -1; | 532 return pending.code == 0 ? 0 : -1; |
535 } | 533 } |
536 | 534 |
537 static int | 535 static int |
538 WaitForPend(p) | 536 WaitForPend(void *p) |
539 void *p; | |
540 { | 537 { |
541 PendingCommand *pending = (PendingCommand *) p; | 538 PendingCommand *pending = (PendingCommand *) p; |
542 return pending->result != NULL; | 539 return pending->result != NULL; |
543 } | 540 } |
544 | 541 |
545 /* | 542 /* |
546 * Return TRUE if window "w" exists and has a "Vim" property on it. | 543 * Return TRUE if window "w" exists and has a "Vim" property on it. |
547 */ | 544 */ |
548 static int | 545 static int |
549 WindowValid(dpy, w) | 546 WindowValid(Display *dpy, Window w) |
550 Display *dpy; | |
551 Window w; | |
552 { | 547 { |
553 XErrorHandler old_handler; | 548 XErrorHandler old_handler; |
554 Atom *plist; | 549 Atom *plist; |
555 int numProp; | 550 int numProp; |
556 int i; | 551 int i; |
575 | 570 |
576 /* | 571 /* |
577 * Enter a loop processing X events & polling chars until we see a result | 572 * Enter a loop processing X events & polling chars until we see a result |
578 */ | 573 */ |
579 static void | 574 static void |
580 ServerWait(dpy, w, endCond, endData, localLoop, seconds) | 575 ServerWait( |
581 Display *dpy; | 576 Display *dpy, |
582 Window w; | 577 Window w, |
583 EndCond endCond; | 578 EndCond endCond, |
584 void *endData; | 579 void *endData, |
585 int localLoop; | 580 int localLoop, |
586 int seconds; | 581 int seconds) |
587 { | 582 { |
588 time_t start; | 583 time_t start; |
589 time_t now; | 584 time_t now; |
590 XEvent event; | 585 XEvent event; |
591 | 586 |
647 * display. | 642 * display. |
648 * | 643 * |
649 * Returns a newline separated list in allocated memory or NULL. | 644 * Returns a newline separated list in allocated memory or NULL. |
650 */ | 645 */ |
651 char_u * | 646 char_u * |
652 serverGetVimNames(dpy) | 647 serverGetVimNames(Display *dpy) |
653 Display *dpy; | |
654 { | 648 { |
655 char_u *regProp; | 649 char_u *regProp; |
656 char_u *entry; | 650 char_u *entry; |
657 char_u *p; | 651 char_u *p; |
658 long_u numItems; | 652 long_u numItems; |
702 /* ---------------------------------------------------------- | 696 /* ---------------------------------------------------------- |
703 * Reply stuff | 697 * Reply stuff |
704 */ | 698 */ |
705 | 699 |
706 static struct ServerReply * | 700 static struct ServerReply * |
707 ServerReplyFind(w, op) | 701 ServerReplyFind(Window w, enum ServerReplyOp op) |
708 Window w; | |
709 enum ServerReplyOp op; | |
710 { | 702 { |
711 struct ServerReply *p; | 703 struct ServerReply *p; |
712 struct ServerReply e; | 704 struct ServerReply e; |
713 int i; | 705 int i; |
714 | 706 |
746 /* | 738 /* |
747 * Convert string to windowid. | 739 * Convert string to windowid. |
748 * Issue an error if the id is invalid. | 740 * Issue an error if the id is invalid. |
749 */ | 741 */ |
750 Window | 742 Window |
751 serverStrToWin(str) | 743 serverStrToWin(char_u *str) |
752 char_u *str; | |
753 { | 744 { |
754 unsigned id = None; | 745 unsigned id = None; |
755 | 746 |
756 sscanf((char *)str, "0x%x", &id); | 747 sscanf((char *)str, "0x%x", &id); |
757 if (id == None) | 748 if (id == None) |
763 /* | 754 /* |
764 * Send a reply string (notification) to client with id "name". | 755 * Send a reply string (notification) to client with id "name". |
765 * Return -1 if the window is invalid. | 756 * Return -1 if the window is invalid. |
766 */ | 757 */ |
767 int | 758 int |
768 serverSendReply(name, str) | 759 serverSendReply(char_u *name, char_u *str) |
769 char_u *name; | |
770 char_u *str; | |
771 { | 760 { |
772 char_u *property; | 761 char_u *property; |
773 int length; | 762 int length; |
774 int res; | 763 int res; |
775 Display *dpy = X_DISPLAY; | 764 Display *dpy = X_DISPLAY; |
805 } | 794 } |
806 return -1; | 795 return -1; |
807 } | 796 } |
808 | 797 |
809 static int | 798 static int |
810 WaitForReply(p) | 799 WaitForReply(void *p) |
811 void *p; | |
812 { | 800 { |
813 Window *w = (Window *) p; | 801 Window *w = (Window *) p; |
814 return ServerReplyFind(*w, SROP_Find) != NULL; | 802 return ServerReplyFind(*w, SROP_Find) != NULL; |
815 } | 803 } |
816 | 804 |
818 * Wait for replies from id (win) | 806 * Wait for replies from id (win) |
819 * Return 0 and the malloc'ed string when a reply is available. | 807 * Return 0 and the malloc'ed string when a reply is available. |
820 * Return -1 if the window becomes invalid while waiting. | 808 * Return -1 if the window becomes invalid while waiting. |
821 */ | 809 */ |
822 int | 810 int |
823 serverReadReply(dpy, win, str, localLoop) | 811 serverReadReply( |
824 Display *dpy; | 812 Display *dpy, |
825 Window win; | 813 Window win, |
826 char_u **str; | 814 char_u **str, |
827 int localLoop; | 815 int localLoop) |
828 { | 816 { |
829 int len; | 817 int len; |
830 char_u *s; | 818 char_u *s; |
831 struct ServerReply *p; | 819 struct ServerReply *p; |
832 | 820 |
856 /* | 844 /* |
857 * Check for replies from id (win). | 845 * Check for replies from id (win). |
858 * Return TRUE and a non-malloc'ed string if there is. Else return FALSE. | 846 * Return TRUE and a non-malloc'ed string if there is. Else return FALSE. |
859 */ | 847 */ |
860 int | 848 int |
861 serverPeekReply(dpy, win, str) | 849 serverPeekReply(Display *dpy, Window win, char_u **str) |
862 Display *dpy; | |
863 Window win; | |
864 char_u **str; | |
865 { | 850 { |
866 struct ServerReply *p; | 851 struct ServerReply *p; |
867 | 852 |
868 if ((p = ServerReplyFind(win, SROP_Find)) != NULL && p->strings.ga_len > 0) | 853 if ((p = ServerReplyFind(win, SROP_Find)) != NULL && p->strings.ga_len > 0) |
869 { | 854 { |
880 /* | 865 /* |
881 * Initialize the communication channels for sending commands and receiving | 866 * Initialize the communication channels for sending commands and receiving |
882 * results. | 867 * results. |
883 */ | 868 */ |
884 static int | 869 static int |
885 SendInit(dpy) | 870 SendInit(Display *dpy) |
886 Display *dpy; | |
887 { | 871 { |
888 XErrorHandler old_handler; | 872 XErrorHandler old_handler; |
889 | 873 |
890 /* | 874 /* |
891 * Create the window used for communication, and set up an | 875 * Create the window used for communication, and set up an |
937 * If the registry property is improperly formed, then it is deleted. | 921 * If the registry property is improperly formed, then it is deleted. |
938 * If "delete" is non-zero, then if the named server is found it is | 922 * If "delete" is non-zero, then if the named server is found it is |
939 * removed from the registry property. | 923 * removed from the registry property. |
940 */ | 924 */ |
941 static Window | 925 static Window |
942 LookupName(dpy, name, delete, loose) | 926 LookupName( |
943 Display *dpy; /* Display whose registry to check. */ | 927 Display *dpy, /* Display whose registry to check. */ |
944 char_u *name; /* Name of a server. */ | 928 char_u *name, /* Name of a server. */ |
945 int delete; /* If non-zero, delete info about name. */ | 929 int delete, /* If non-zero, delete info about name. */ |
946 char_u **loose; /* Do another search matching -999 if not found | 930 char_u **loose) /* Do another search matching -999 if not found |
947 Return result here if a match is found */ | 931 Return result here if a match is found */ |
948 { | 932 { |
949 char_u *regProp, *entry; | 933 char_u *regProp, *entry; |
950 char_u *p; | 934 char_u *p; |
951 long_u numItems; | 935 long_u numItems; |
1031 * 1. There is an old windowid for an exit'ed vim in the registry | 1015 * 1. There is an old windowid for an exit'ed vim in the registry |
1032 * 2. We get that id for our commWindow but only want to send, not register. | 1016 * 2. We get that id for our commWindow but only want to send, not register. |
1033 * 3. The window will mistakenly be regarded valid because of own commWindow | 1017 * 3. The window will mistakenly be regarded valid because of own commWindow |
1034 */ | 1018 */ |
1035 static void | 1019 static void |
1036 DeleteAnyLingerer(dpy, win) | 1020 DeleteAnyLingerer( |
1037 Display *dpy; /* Display whose registry to check. */ | 1021 Display *dpy, /* Display whose registry to check. */ |
1038 Window win; /* Window to remove */ | 1022 Window win) /* Window to remove */ |
1039 { | 1023 { |
1040 char_u *regProp, *entry = NULL; | 1024 char_u *regProp, *entry = NULL; |
1041 char_u *p; | 1025 char_u *p; |
1042 long_u numItems; | 1026 long_u numItems; |
1043 int_u wwin; | 1027 int_u wwin; |
1093 * Return the property in "regPropp". "empty_prop" is used when it doesn't | 1077 * Return the property in "regPropp". "empty_prop" is used when it doesn't |
1094 * exist yet. | 1078 * exist yet. |
1095 * Return OK when successful. | 1079 * Return OK when successful. |
1096 */ | 1080 */ |
1097 static int | 1081 static int |
1098 GetRegProp(dpy, regPropp, numItemsp, domsg) | 1082 GetRegProp( |
1099 Display *dpy; | 1083 Display *dpy, |
1100 char_u **regPropp; | 1084 char_u **regPropp, |
1101 long_u *numItemsp; | 1085 long_u *numItemsp, |
1102 int domsg; /* When TRUE give error message. */ | 1086 int domsg) /* When TRUE give error message. */ |
1103 { | 1087 { |
1104 int result, actualFormat; | 1088 int result, actualFormat; |
1105 long_u bytesAfter; | 1089 long_u bytesAfter; |
1106 Atom actualType; | 1090 Atom actualType; |
1107 XErrorHandler old_handler; | 1091 XErrorHandler old_handler; |
1150 * it runs the event immediatly instead of enqueuing it. Immediate can cause | 1134 * it runs the event immediatly instead of enqueuing it. Immediate can cause |
1151 * unintended behavior and should only be used for code that blocks for a | 1135 * unintended behavior and should only be used for code that blocks for a |
1152 * response. | 1136 * response. |
1153 */ | 1137 */ |
1154 void | 1138 void |
1155 serverEventProc(dpy, eventPtr, immediate) | 1139 serverEventProc( |
1156 Display *dpy; | 1140 Display *dpy, |
1157 XEvent *eventPtr; /* Information about event. */ | 1141 XEvent *eventPtr, /* Information about event. */ |
1158 int immediate; /* Run event immediately. Should mostly be 0. */ | 1142 int immediate) /* Run event immediately. Should mostly be 0. */ |
1159 { | 1143 { |
1160 char_u *propInfo; | 1144 char_u *propInfo; |
1161 int result, actualFormat; | 1145 int result, actualFormat; |
1162 long_u numItems, bytesAfter; | 1146 long_u numItems, bytesAfter; |
1163 Atom actualType; | 1147 Atom actualType; |
1195 /* | 1179 /* |
1196 * Saves x clientserver commands in a queue so that they can be called when | 1180 * Saves x clientserver commands in a queue so that they can be called when |
1197 * vim is idle. | 1181 * vim is idle. |
1198 */ | 1182 */ |
1199 static void | 1183 static void |
1200 save_in_queue(propInfo, len) | 1184 save_in_queue(char_u *propInfo, long_u len) |
1201 char_u *propInfo; | |
1202 long_u len; | |
1203 { | 1185 { |
1204 x_queue_T *node; | 1186 x_queue_T *node; |
1205 | 1187 |
1206 node = (x_queue_T *)alloc(sizeof(x_queue_T)); | 1188 node = (x_queue_T *)alloc(sizeof(x_queue_T)); |
1207 if (node == NULL) | 1189 if (node == NULL) |
1224 | 1206 |
1225 /* | 1207 /* |
1226 * Parses queued clientserver messages. | 1208 * Parses queued clientserver messages. |
1227 */ | 1209 */ |
1228 void | 1210 void |
1229 server_parse_messages() | 1211 server_parse_messages(void) |
1230 { | 1212 { |
1231 x_queue_T *node; | 1213 x_queue_T *node; |
1232 | 1214 |
1233 if (!X_DISPLAY) | 1215 if (!X_DISPLAY) |
1234 return; /* cannot happen? */ | 1216 return; /* cannot happen? */ |
1245 /* | 1227 /* |
1246 * Returns a non-zero value if there are clientserver messages waiting | 1228 * Returns a non-zero value if there are clientserver messages waiting |
1247 * int the queue. | 1229 * int the queue. |
1248 */ | 1230 */ |
1249 int | 1231 int |
1250 server_waiting() | 1232 server_waiting(void) |
1251 { | 1233 { |
1252 return head.next != NULL && head.next != &head; | 1234 return head.next != NULL && head.next != &head; |
1253 } | 1235 } |
1254 | 1236 |
1255 /* | 1237 /* |
1256 * Prases a single clientserver message. A single message may contain multiple | 1238 * Prases a single clientserver message. A single message may contain multiple |
1257 * commands. | 1239 * commands. |
1258 * "propInfo" will be freed. | 1240 * "propInfo" will be freed. |
1259 */ | 1241 */ |
1260 static void | 1242 static void |
1261 server_parse_message(dpy, propInfo, numItems) | 1243 server_parse_message( |
1262 Display *dpy; | 1244 Display *dpy, |
1263 char_u *propInfo; /* A string containing 0 or more X commands */ | 1245 char_u *propInfo, /* A string containing 0 or more X commands */ |
1264 long_u numItems; /* The size of propInfo in bytes. */ | 1246 long_u numItems) /* The size of propInfo in bytes. */ |
1265 { | 1247 { |
1266 char_u *p; | 1248 char_u *p; |
1267 int code; | 1249 int code; |
1268 char_u *tofree; | 1250 char_u *tofree; |
1269 | 1251 |
1537 * that if the append fails this procedure can return an error code rather | 1519 * that if the append fails this procedure can return an error code rather |
1538 * than having Xlib panic. | 1520 * than having Xlib panic. |
1539 * Return: 0 for OK, -1 for error | 1521 * Return: 0 for OK, -1 for error |
1540 */ | 1522 */ |
1541 static int | 1523 static int |
1542 AppendPropCarefully(dpy, window, property, value, length) | 1524 AppendPropCarefully( |
1543 Display *dpy; /* Display on which to operate. */ | 1525 Display *dpy, /* Display on which to operate. */ |
1544 Window window; /* Window whose property is to be modified. */ | 1526 Window window, /* Window whose property is to be modified. */ |
1545 Atom property; /* Name of property. */ | 1527 Atom property, /* Name of property. */ |
1546 char_u *value; /* Characters to append to property. */ | 1528 char_u *value, /* Characters to append to property. */ |
1547 int length; /* How much to append */ | 1529 int length) /* How much to append */ |
1548 { | 1530 { |
1549 XErrorHandler old_handler; | 1531 XErrorHandler old_handler; |
1550 | 1532 |
1551 old_handler = XSetErrorHandler(x_error_check); | 1533 old_handler = XSetErrorHandler(x_error_check); |
1552 got_x_error = FALSE; | 1534 got_x_error = FALSE; |
1560 | 1542 |
1561 /* | 1543 /* |
1562 * Another X Error handler, just used to check for errors. | 1544 * Another X Error handler, just used to check for errors. |
1563 */ | 1545 */ |
1564 static int | 1546 static int |
1565 x_error_check(dpy, error_event) | 1547 x_error_check(Display *dpy UNUSED, XErrorEvent *error_event UNUSED) |
1566 Display *dpy UNUSED; | |
1567 XErrorEvent *error_event UNUSED; | |
1568 { | 1548 { |
1569 got_x_error = TRUE; | 1549 got_x_error = TRUE; |
1570 return 0; | 1550 return 0; |
1571 } | 1551 } |
1572 | 1552 |
1573 /* | 1553 /* |
1574 * Check if "str" looks like it had a serial number appended. | 1554 * Check if "str" looks like it had a serial number appended. |
1575 * Actually just checks if the name ends in a digit. | 1555 * Actually just checks if the name ends in a digit. |
1576 */ | 1556 */ |
1577 static int | 1557 static int |
1578 IsSerialName(str) | 1558 IsSerialName(char_u *str) |
1579 char_u *str; | |
1580 { | 1559 { |
1581 int len = STRLEN(str); | 1560 int len = STRLEN(str); |
1582 | 1561 |
1583 return (len > 1 && vim_isdigit(str[len - 1])); | 1562 return (len > 1 && vim_isdigit(str[len - 1])); |
1584 } | 1563 } |