annotate src/clientserver.c @ 30459:300e973cb91d v9.0.0565

patch 9.0.0565: cscope test causes problems with test timeout timer Commit: https://github.com/vim/vim/commit/dfa8be4944b49c228d401e788aaade47b4abb658 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 23 23:19:18 2022 +0100 patch 9.0.0565: cscope test causes problems with test timeout timer Problem: Cscope test causes problems when code for test timeout timer is included (even when commented out). Solution: Disable part of the cscope test for now.
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Sep 2022 00:30:07 +0200
parents 9137d2bc93bf
children 37aa9fd2ed72
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * clientserver.c: functions for Client Server functionality
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_CLIENTSERVER) || defined(PROTO)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 static void cmdsrv_main(int *argc, char **argv, char_u *serverName_arg, char_u **serverStr);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 static char_u *serverMakeName(char_u *arg, char *cmd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * Replace termcodes such as <CR> and insert as key presses if there is room.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 server_to_input_buf(char_u *str)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 char_u *ptr = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 char_u *cpo_save = p_cpo;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 // Set 'cpoptions' the way we want it.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 // B set - backslashes are *not* treated specially
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 // k set - keycodes are *not* reverse-engineered
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 // < unset - <Key> sequences *are* interpreted
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 // The last but one parameter of replace_termcodes() is TRUE so that the
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 // <lt> sequence is recognised - needed for a real backslash.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 p_cpo = (char_u *)"Bk";
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
37 str = replace_termcodes(str, &ptr, REPTERM_DO_LT, NULL);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 p_cpo = cpo_save;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 if (*ptr != NUL) // trailing CTRL-V results in nothing
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 * Add the string to the input stream.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 * Can't use add_to_input_buf() here, we now have K_SPECIAL bytes.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 * First clear typed characters from the typeahead buffer, there could
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 * be half a mapping there. Then append to the existing string, so
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 * that multiple commands from a client are concatenated.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 if (typebuf.tb_maplen < typebuf.tb_len)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 (void)ins_typebuf(str, REMAP_NONE, typebuf.tb_len, TRUE, FALSE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 // Let input_available() know we inserted text in the typeahead
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 // buffer.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 typebuf_was_filled = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 }
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
58 vim_free(ptr);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 * Evaluate an expression that the client sent to a string.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 char_u *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 eval_client_expr_to_string(char_u *expr)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 char_u *res;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 int save_dbl = debug_break_level;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 int save_ro = redir_off;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 funccal_entry_T funccal_entry;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 int did_save_funccal = FALSE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 // Evaluate the expression at the toplevel, don't use variables local to
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 // the calling function. Except when in debug mode.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 if (!debug_mode)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 save_funccal(&funccal_entry);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 did_save_funccal = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 // Disable debugging, otherwise Vim hangs, waiting for "cont" to be
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 // typed.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 debug_break_level = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 redir_off = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 // Do not display error message, otherwise Vim hangs, waiting for "cont"
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 // to be typed. Do generate errors so that try/catch works.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 ++emsg_silent;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
20996
3af71cbcfdbe patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents: 20174
diff changeset
89 res = eval_to_string(expr, TRUE);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 debug_break_level = save_dbl;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 redir_off = save_ro;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 --emsg_silent;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 if (emsg_silent < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 emsg_silent = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 if (did_save_funccal)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 restore_funccal();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 // A client can tell us to redraw, but not to display the cursor, so do
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 // that here.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 setcursor();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 out_flush_cursor(FALSE, FALSE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 return res;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 * Evaluate a command or expression sent to ourselves.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 int
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 sendToLocalVim(char_u *cmd, int asExpr, char_u **result)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if (asExpr)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 char_u *ret;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 ret = eval_client_expr_to_string(cmd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (result != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 if (ret == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 {
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
122 char *err = _(e_invalid_expression_received);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 size_t len = STRLEN(cmd) + STRLEN(err) + 5;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 char_u *msg;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 msg = alloc(len);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 if (msg != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 vim_snprintf((char *)msg, len, "%s: \"%s\"", err, cmd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 *result = msg;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 *result = ret;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 vim_free(ret);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 return ret == NULL ? -1 : 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 server_to_input_buf(cmd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 return 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 * If conversion is needed, convert "data" from "client_enc" to 'encoding' and
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 * return an allocated string. Otherwise return "data".
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 * "*tofree" is set to the result when it needs to be freed later.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 char_u *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 serverConvert(
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 char_u *client_enc UNUSED,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 char_u *data,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 char_u **tofree)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 char_u *res = data;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 *tofree = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 if (client_enc != NULL && p_enc != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 vimconv_T vimconv;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 vimconv.vc_type = CONV_NONE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 if (convert_setup(&vimconv, client_enc, p_enc) != FAIL
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 && vimconv.vc_type != CONV_NONE)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 res = string_convert(&vimconv, data, NULL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 if (res == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 res = data;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 *tofree = res;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 convert_setup(&vimconv, NULL, NULL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 return res;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 * Common code for the X command server and the Win32 command server.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 static char_u *build_drop_cmd(int filec, char **filev, int tabs, int sendReply);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 * Do the client-server stuff, unless "--servername ''" was used.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 exec_on_server(mparm_T *parmp)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 // Initialise the client/server messaging infrastructure.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 serverInitMessaging();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 * When a command server argument was found, execute it. This may
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 * exit Vim when it was successful. Otherwise it's executed further
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 * on. Remember the encoding used here in "serverStrEnc".
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 if (parmp->serverArg)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 cmdsrv_main(&parmp->argc, parmp->argv,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 parmp->serverName_arg, &parmp->serverStr);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 parmp->serverStrEnc = vim_strsave(p_enc);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 // If we're still running, get the name to register ourselves.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 // On Win32 can register right now, for X11 need to setup the
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 // clipboard first, it's further down.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 parmp->servername = serverMakeName(parmp->serverName_arg,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 parmp->argv[0]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 if (parmp->servername != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 serverSetName(parmp->servername);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 vim_free(parmp->servername);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 * Prepare for running as a Vim server.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 prepare_server(mparm_T *parmp)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 # if defined(FEAT_X11)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 * Register for remote command execution with :serversend and --remote
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 * unless there was a -X or a --servername '' on the command line.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 * Only register nongui-vim's with an explicit --servername argument,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 * or when compiling with autoservername.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 * When running as root --servername is also required.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if (X_DISPLAY != NULL && parmp->servername != NULL && (
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 # if defined(FEAT_AUTOSERVERNAME) || defined(FEAT_GUI)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 (
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 # if defined(FEAT_AUTOSERVERNAME)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 1
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 gui.in_use
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 # ifdef UNIX
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 && getuid() != ROOT_UID
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 ) ||
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 parmp->serverName_arg != NULL))
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 (void)serverRegisterName(X_DISPLAY, parmp->servername);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 vim_free(parmp->servername);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 TIME_MSG("register server name");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 serverDelayedStartName = parmp->servername;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 * Execute command ourselves if we're here because the send failed (or
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 * else we would have exited above).
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 if (parmp->serverStr != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 char_u *p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 server_to_input_buf(serverConvert(parmp->serverStrEnc,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 parmp->serverStr, &p));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 vim_free(p);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 static void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 cmdsrv_main(
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 int *argc,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 char **argv,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 char_u *serverName_arg,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 char_u **serverStr)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 char_u *res;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 int i;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 char_u *sname;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 int ret;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 int didone = FALSE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 int exiterr = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 char **newArgV = argv + 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 int newArgC = 1,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 Argc = *argc;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 int argtype;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 #define ARGTYPE_OTHER 0
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 #define ARGTYPE_EDIT 1
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 #define ARGTYPE_EDIT_WAIT 2
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 #define ARGTYPE_SEND 3
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 int silent = FALSE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 int tabs = FALSE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 # ifndef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 HWND srv;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 Window srv;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 setup_term_clip();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 sname = serverMakeName(serverName_arg, argv[0]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 if (sname == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 * Execute the command server related arguments and remove them
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 * from the argc/argv array; We may have to return into main()
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 for (i = 1; i < Argc; i++)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 res = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 if (STRCMP(argv[i], "--") == 0) // end of option arguments
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 for (; i < *argc; i++)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 *newArgV++ = argv[i];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 newArgC++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 break;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 if (STRICMP(argv[i], "--remote-send") == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 argtype = ARGTYPE_SEND;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 else if (STRNICMP(argv[i], "--remote", 8) == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 char *p = argv[i] + 8;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 argtype = ARGTYPE_EDIT;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 while (*p != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 if (STRNICMP(p, "-wait", 5) == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 argtype = ARGTYPE_EDIT_WAIT;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 p += 5;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 else if (STRNICMP(p, "-silent", 7) == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 silent = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 p += 7;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 else if (STRNICMP(p, "-tab", 4) == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 tabs = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 p += 4;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 argtype = ARGTYPE_OTHER;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 break;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 argtype = ARGTYPE_OTHER;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 if (argtype != ARGTYPE_OTHER)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 if (i == *argc - 1)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 mainerr_arg_missing((char_u *)argv[i]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 if (argtype == ARGTYPE_SEND)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 *serverStr = (char_u *)argv[i + 1];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 i++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 *serverStr = build_drop_cmd(*argc - i - 1, argv + i + 1,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 tabs, argtype == ARGTYPE_EDIT_WAIT);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 if (*serverStr == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 // Probably out of memory, exit.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 didone = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 exiterr = 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 break;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 Argc = i;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 if (xterm_dpy == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 mch_errmsg(_("No display"));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 ret = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 ret = serverSendToVim(xterm_dpy, sname, *serverStr,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 NULL, &srv, 0, 0, 0, silent);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 // Win32 always works?
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, 0, silent);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 if (ret < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 if (argtype == ARGTYPE_SEND)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 // Failed to send, abort.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 mch_errmsg(_(": Send failed.\n"));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 didone = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 exiterr = 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 else if (!silent)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 // Let vim start normally.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 mch_errmsg(_(": Send failed. Trying to execute locally\n"));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 break;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 // Guess that when the server name starts with "g" it's a GUI
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 // server, which we can bring to the foreground here.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 // Foreground() in the server doesn't work very well.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G')
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 SetForegroundWindow(srv);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 * For --remote-wait: Wait until the server did edit each
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 * file. Also detect that the server no longer runs.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 */
28169
bef82285dda0 patch 8.2.4610: some conditions are always true
Bram Moolenaar <Bram@vim.org>
parents: 28162
diff changeset
423 if (argtype == ARGTYPE_EDIT_WAIT)
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 int numFiles = *argc - i - 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 char_u *done = alloc(numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 NOTIFYICONDATA ni;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 int count = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 extern HWND message_window;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 if (numFiles > 0 && argv[i + 1][0] == '+')
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 // Skip "+cmd" argument, don't wait for it to be edited.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 --numFiles;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 ni.cbSize = sizeof(ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 ni.hWnd = message_window;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 ni.uID = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 ni.uFlags = NIF_ICON|NIF_TIP;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 ni.hIcon = LoadIcon((HINSTANCE)GetModuleHandle(0), "IDR_VIM");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 sprintf(ni.szTip, _("%d of %d edited"), count, numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 Shell_NotifyIcon(NIM_ADD, &ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 // Wait for all files to unload in remote
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 vim_memset(done, 0, numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 while (memchr(done, 0, numFiles) != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 {
30154
9137d2bc93bf patch 9.0.0413: ASAN reports a memory leak
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
451 char_u *p;
9137d2bc93bf patch 9.0.0413: ASAN reports a memory leak
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
452 int j;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 p = serverGetReply(srv, NULL, TRUE, TRUE, 0);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 if (p == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 break;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 if (serverReadReply(xterm_dpy, srv, &p, TRUE, -1) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 break;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 j = atoi((char *)p);
30154
9137d2bc93bf patch 9.0.0413: ASAN reports a memory leak
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
462 vim_free(p);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 if (j >= 0 && j < numFiles)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 ++count;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 sprintf(ni.szTip, _("%d of %d edited"),
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 count, numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 Shell_NotifyIcon(NIM_MODIFY, &ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 done[j] = 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 Shell_NotifyIcon(NIM_DELETE, &ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 # endif
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 19920
diff changeset
477 vim_free(done);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 else if (STRICMP(argv[i], "--remote-expr") == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 if (i == *argc - 1)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 mainerr_arg_missing((char_u *)argv[i]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 // Win32 always works?
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 if (serverSendToVim(sname, (char_u *)argv[i + 1],
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 &res, NULL, 1, 0, FALSE) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 if (xterm_dpy == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 mch_errmsg(_("No display: Send expression failed.\n"));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 else if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1],
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 &res, NULL, 1, 0, 1, FALSE) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 if (res != NULL && *res != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 // Output error from remote
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 mch_errmsg((char *)res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 VIM_CLEAR(res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 mch_errmsg(_(": Send expression failed.\n"));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 else if (STRICMP(argv[i], "--serverlist") == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 // Win32 always works?
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 res = serverGetVimNames();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 if (xterm_dpy != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 res = serverGetVimNames(xterm_dpy);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (did_emsg)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 mch_errmsg("\n");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 else if (STRICMP(argv[i], "--servername") == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 // Already processed. Take it out of the command line
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 i++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 continue;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 *newArgV++ = argv[i];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 newArgC++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 continue;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 didone = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 if (res != NULL && *res != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 mch_msg((char *)res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 if (res[STRLEN(res) - 1] != '\n')
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 mch_msg("\n");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 vim_free(res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (didone)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 display_errors(); // display any collected messages
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 exit(exiterr); // Mission accomplished - get out
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 // Return back into main()
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 *argc = newArgC;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 vim_free(sname);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 * Build a ":drop" command to send to a Vim server.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 static char_u *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 build_drop_cmd(
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 int filec,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 char **filev,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 int tabs, // Use ":tab drop" instead of ":drop".
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 int sendReply)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 garray_T ga;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 int i;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 char_u *inicmd = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 char_u *p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 char_u *cdp;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 char_u *cwd;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 if (filec > 0 && filev[0][0] == '+')
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 inicmd = (char_u *)filev[0] + 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 filev++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 filec--;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 // Check if we have at least one argument.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (filec <= 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 mainerr_arg_missing((char_u *)filev[-1]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 // Temporarily cd to the current directory to handle relative file names.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 cwd = alloc(MAXPATHL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 if (cwd == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 if (mch_dirname(cwd, MAXPATHL) != OK)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 vim_free(cwd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 cdp = vim_strsave_escaped_ext(cwd,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 #ifdef BACKSLASH_IN_FILENAME
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 (char_u *)"", // rem_backslash() will tell what chars to escape
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 PATH_ESC_CHARS,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 '\\', TRUE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 vim_free(cwd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 if (cdp == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 ga_init2(&ga, 1, 100);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 ga_concat(&ga, (char_u *)"<C-\\><C-N>:cd ");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 ga_concat(&ga, cdp);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 // Call inputsave() so that a prompt for an encryption key works.
21723
5b0796787cb2 patch 8.2.1411: when splitting a window localdir is copied but prevdir is not
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
600 ga_concat(&ga, (char_u *)
5b0796787cb2 patch 8.2.1411: when splitting a window localdir is copied but prevdir is not
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
601 "<CR>:if exists('*inputsave')|call inputsave()|endif|");
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 if (tabs)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 ga_concat(&ga, (char_u *)"tab ");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 ga_concat(&ga, (char_u *)"drop");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 for (i = 0; i < filec; i++)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 // On Unix the shell has already expanded the wildcards, don't want to
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 // do it again in the Vim server. On MS-Windows only escape
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 // non-wildcard characters.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 p = vim_strsave_escaped((char_u *)filev[i],
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 #ifdef UNIX
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 PATH_ESC_CHARS
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 (char_u *)" \t%#"
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 );
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 if (p == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 vim_free(ga.ga_data);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 ga_concat(&ga, (char_u *)" ");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 ga_concat(&ga, p);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 vim_free(p);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 }
21723
5b0796787cb2 patch 8.2.1411: when splitting a window localdir is copied but prevdir is not
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
626 ga_concat(&ga, (char_u *)
5b0796787cb2 patch 8.2.1411: when splitting a window localdir is copied but prevdir is not
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
627 "|if exists('*inputrestore')|call inputrestore()|endif<CR>");
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 // The :drop commands goes to Insert mode when 'insertmode' is set, use
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 // CTRL-\ CTRL-N again.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 ga_concat(&ga, (char_u *)"<C-\\><C-N>");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 // Switch back to the correct current directory (prior to temporary path
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 // switch) unless 'autochdir' is set, in which case it will already be
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 // correct after the :drop command. With line breaks and spaces:
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 // if !exists('+acd') || !&acd
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 // if haslocaldir()
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 // cd -
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 // lcd -
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 // elseif getcwd() ==# 'current path'
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 // cd -
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 // endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 // endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 ga_concat(&ga, (char_u *)":if !exists('+acd')||!&acd|if haslocaldir()|");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 ga_concat(&ga, (char_u *)"cd -|lcd -|elseif getcwd() ==# '");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 ga_concat(&ga, cdp);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 ga_concat(&ga, (char_u *)"'|cd -|endif|endif<CR>");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 vim_free(cdp);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 if (sendReply)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 ga_concat(&ga, (char_u *)":call SetupRemoteReplies()<CR>");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 ga_concat(&ga, (char_u *)":");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 if (inicmd != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 {
27583
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
655 // Can't use <CR> after "inicmd", because a "startinsert" would cause
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 // the following commands to be inserted as text. Use a "|",
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 // hopefully "inicmd" does allow this...
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 ga_concat(&ga, inicmd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 ga_concat(&ga, (char_u *)"|");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 // Bring the window to the foreground, goto Insert mode when 'im' set and
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 // clear command line.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 ga_concat(&ga, (char_u *)"cal foreground()|if &im|star|en|redr|f<CR>");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 ga_append(&ga, NUL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 return ga.ga_data;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 * Make our basic server name: use the specified "arg" if given, otherwise use
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 * the tail of the command "cmd" we were started with.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 * Return the name in allocated memory. This doesn't include a serial number.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 static char_u *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 serverMakeName(char_u *arg, char *cmd)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 char_u *p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 if (arg != NULL && *arg != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 p = vim_strsave_up(arg);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 p = vim_strsave_up(gettail((char_u *)cmd));
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 // Remove .exe or .bat from the name.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 if (p != NULL && vim_strchr(p, '.') != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 *vim_strchr(p, '.') = NUL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 return p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 #endif // FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 #if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 static void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 make_connection(void)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 if (X_DISPLAY == NULL
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 # ifdef FEAT_GUI
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 && !gui.in_use
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 )
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 x_force_connect = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 setup_term_clip();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 x_force_connect = FALSE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 static int
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 check_connection(void)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 make_connection();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 if (X_DISPLAY == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 {
26893
79c76ca2c53c patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
713 emsg(_(e_no_connection_to_x_server));
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 return FAIL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 return OK;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 static void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 remote_common(typval_T *argvars, typval_T *rettv, int expr)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 char_u *server_name;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 char_u *keys;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 char_u *r = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 char_u buf[NUMBUFLEN];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 int timeout = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 HWND w;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 Window w;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 if (check_restricted() || check_secure())
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 if (check_connection() == FAIL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 if (argvars[2].v_type != VAR_UNKNOWN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 && argvars[3].v_type != VAR_UNKNOWN)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 timeout = tv_get_number(&argvars[3]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 server_name = tv_get_string_chk(&argvars[0]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 if (server_name == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 return; // type error; errmsg already given
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 keys = tv_get_string_buf(&argvars[1], buf);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 if (serverSendToVim(server_name, keys, &r, &w, expr, timeout, TRUE) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 if (serverSendToVim(X_DISPLAY, server_name, keys, &r, &w, expr, timeout,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 0, TRUE) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 if (r != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 emsg((char *)r); // sending worked but evaluation failed
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 vim_free(r);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 else
26893
79c76ca2c53c patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
763 semsg(_(e_unable_to_send_to_str), server_name);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 rettv->vval.v_string = r;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 if (argvars[2].v_type != VAR_UNKNOWN)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 dictitem_T v;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 char_u str[30];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 char_u *idvar;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 idvar = tv_get_string_chk(&argvars[2]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 if (idvar != NULL && *idvar != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 sprintf((char *)str, PRINTF_HEX_LONG_U, (long_u)w);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 v.di_tv.v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 v.di_tv.vval.v_string = vim_strsave(str);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 set_var(idvar, &v.di_tv, FALSE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 vim_free(v.di_tv.vval.v_string);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 #if defined(FEAT_EVAL) || defined(PROTO)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 * "remote_expr()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 f_remote_expr(typval_T *argvars UNUSED, typval_T *rettv)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 rettv->vval.v_string = NULL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
797
28162
6e431b1c51d5 patch 8.2.4606: test fails because of changed error message
Bram Moolenaar <Bram@vim.org>
parents: 27583
diff changeset
798 #ifdef FEAT_CLIENTSERVER
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
799 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
800 && (check_for_string_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
801 || check_for_string_arg(argvars, 1) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
802 || check_for_opt_string_arg(argvars, 2) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
803 || (argvars[2].v_type != VAR_UNKNOWN
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
804 && check_for_opt_number_arg(argvars, 3) == FAIL)))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
805 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
806
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 remote_common(argvars, rettv, TRUE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 * "remote_foreground()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 f_remote_foreground(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 #ifdef FEAT_CLIENTSERVER
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
818 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
819 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
820
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 // On Win32 it's done in this application.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 char_u *server_name = tv_get_string_chk(&argvars[0]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 if (server_name != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 serverForeground(server_name);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 // Send a foreground() expression to the server.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 argvars[1].v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 argvars[1].vval.v_string = vim_strsave((char_u *)"foreground()");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 argvars[2].v_type = VAR_UNKNOWN;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 rettv->vval.v_string = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 remote_common(argvars, rettv, TRUE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 vim_free(argvars[1].vval.v_string);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 f_remote_peek(typval_T *argvars UNUSED, typval_T *rettv)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 dictitem_T v;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 char_u *s = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 long_u n = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 char_u *serverid;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
853 rettv->vval.v_number = -1;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 if (check_restricted() || check_secure())
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 return;
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
856
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
857 if (in_vim9script()
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
858 && (check_for_string_arg(argvars, 0) == FAIL
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
859 || check_for_opt_string_arg(argvars, 1) == FAIL))
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
860 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
861
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 serverid = tv_get_string_chk(&argvars[0]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 if (serverid == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 return; // type error; errmsg already given
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 sscanf((const char *)serverid, SCANF_HEX_LONG_U, &n);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 if (n == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 rettv->vval.v_number = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 s = serverGetReply((HWND)n, FALSE, FALSE, FALSE, 0);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 rettv->vval.v_number = (s != NULL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 if (check_connection() == FAIL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 rettv->vval.v_number = serverPeekReply(X_DISPLAY,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 serverStrToWin(serverid), &s);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 if (argvars[1].v_type != VAR_UNKNOWN && rettv->vval.v_number > 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 char_u *retvar;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 v.di_tv.v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 v.di_tv.vval.v_string = vim_strsave(s);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 retvar = tv_get_string_chk(&argvars[1]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 if (retvar != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 set_var(retvar, &v.di_tv, FALSE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 vim_free(v.di_tv.vval.v_string);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 rettv->vval.v_number = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 f_remote_read(typval_T *argvars UNUSED, typval_T *rettv)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 char_u *r = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 #ifdef FEAT_CLIENTSERVER
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
904 char_u *serverid;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
906 if (in_vim9script()
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
907 && (check_for_string_arg(argvars, 0) == FAIL
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
908 || check_for_opt_number_arg(argvars, 1) == FAIL))
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
909 return;
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
910
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
911 serverid = tv_get_string_chk(&argvars[0]);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 if (serverid != NULL && !check_restricted() && !check_secure())
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 int timeout = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 // The server's HWND is encoded in the 'id' parameter
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 long_u n = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 if (argvars[1].v_type != VAR_UNKNOWN)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 timeout = tv_get_number(&argvars[1]);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 sscanf((char *)serverid, SCANF_HEX_LONG_U, &n);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 if (n != 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 r = serverGetReply((HWND)n, FALSE, TRUE, TRUE, timeout);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 if (r == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 if (check_connection() == FAIL
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 || serverReadReply(X_DISPLAY, serverStrToWin(serverid),
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 &r, FALSE, timeout) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 # endif
26897
d02d40f0261c patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26893
diff changeset
933 emsg(_(e_unable_to_read_server_reply));
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 rettv->vval.v_string = r;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 * "remote_send()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 f_remote_send(typval_T *argvars UNUSED, typval_T *rettv)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 rettv->vval.v_string = NULL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
948
28162
6e431b1c51d5 patch 8.2.4606: test fails because of changed error message
Bram Moolenaar <Bram@vim.org>
parents: 27583
diff changeset
949 #ifdef FEAT_CLIENTSERVER
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
950 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
951 && (check_for_string_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
952 || check_for_string_arg(argvars, 1) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
953 || check_for_opt_string_arg(argvars, 2) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
954 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
955
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 remote_common(argvars, rettv, FALSE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 * "remote_startserver()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 f_remote_startserver(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 #ifdef FEAT_CLIENTSERVER
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
967 char_u *server;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
969 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
970 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
971
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
972 server = tv_get_string_chk(&argvars[0]);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 if (server == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 return; // type error; errmsg already given
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 if (serverName != NULL)
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
976 emsg(_(e_already_started_server));
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 if (check_connection() == OK)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 serverRegisterName(X_DISPLAY, server);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 serverSetName(server);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 #else
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
987 emsg(_(e_clientserver_feature_not_available));
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 f_server2client(typval_T *argvars UNUSED, typval_T *rettv)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 char_u buf[NUMBUFLEN];
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
996 char_u *server;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
997 char_u *reply;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 rettv->vval.v_number = -1;
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1000 if (check_restricted() || check_secure())
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1001 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1002
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1003 if (in_vim9script()
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1004 && (check_for_string_arg(argvars, 0) == FAIL
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1005 || check_for_string_arg(argvars, 1) == FAIL))
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1006 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1007
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1008 server = tv_get_string_chk(&argvars[0]);
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1009 reply = tv_get_string_buf_chk(&argvars[1], buf);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 if (server == NULL || reply == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 return;
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1012
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 if (check_connection() == FAIL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 if (serverSendReply(server, reply) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 {
26893
79c76ca2c53c patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
1020 emsg(_(e_unable_to_send_to_client));
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 rettv->vval.v_number = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 rettv->vval.v_number = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 f_serverlist(typval_T *argvars UNUSED, typval_T *rettv)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 char_u *r = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 r = serverGetVimNames();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 make_connection();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 if (X_DISPLAY != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 r = serverGetVimNames(X_DISPLAY);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 rettv->vval.v_string = r;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 #endif