annotate src/clientserver.c @ 27492:4789f29c9595

Update runtime files Commit: https://github.com/vim/vim/commit/c4573eb12dba6a062af28ee0b8938d1521934ce4 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 31 15:40:56 2022 +0000 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Mon, 31 Jan 2022 16:45:03 +0100
parents 41e0dcf38521
children d4921b91542c
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 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 if (ret >= 0 && argtype == ARGTYPE_EDIT_WAIT)
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 int j;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 char_u *done = alloc(numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 char_u *p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 NOTIFYICONDATA ni;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 int count = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 extern HWND message_window;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 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
436 // 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
437 --numFiles;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 ni.cbSize = sizeof(ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 ni.hWnd = message_window;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 ni.uID = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 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
444 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
445 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
446 Shell_NotifyIcon(NIM_ADD, &ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 // 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
450 vim_memset(done, 0, numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 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
452 {
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);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 if (j >= 0 && j < numFiles)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 ++count;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 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
467 count, numFiles);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 Shell_NotifyIcon(NIM_MODIFY, &ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 done[j] = 1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 }
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 # ifdef FEAT_GUI_MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 Shell_NotifyIcon(NIM_DELETE, &ni);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 # endif
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 19920
diff changeset
476 vim_free(done);
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 }
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 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
480 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 if (i == *argc - 1)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 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
483 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 // Win32 always works?
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 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
486 &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
487 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 if (xterm_dpy == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 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
490 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
491 &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
492 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 if (res != NULL && *res != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 // Output error from remote
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 mch_errmsg((char *)res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 VIM_CLEAR(res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 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
501 }
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 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
504 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 // Win32 always works?
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 res = serverGetVimNames();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 if (xterm_dpy != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 res = serverGetVimNames(xterm_dpy);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 if (did_emsg)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 mch_errmsg("\n");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 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
516 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 // 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
518 i++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 continue;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 *newArgV++ = argv[i];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 newArgC++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 continue;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 didone = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 if (res != NULL && *res != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 mch_msg((char *)res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 mch_msg("\n");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 vim_free(res);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 }
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 if (didone)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 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
540 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
541 }
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 // Return back into main()
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 *argc = newArgC;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 vim_free(sname);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 }
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 * 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
550 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 static char_u *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 build_drop_cmd(
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 int filec,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 char **filev,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 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
556 int sendReply)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 garray_T ga;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 int i;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 char_u *inicmd = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 char_u *p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 char_u *cdp;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 char_u *cwd;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 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
568 filev++;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 filec--;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 // 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
572 if (filec <= 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 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
574
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 // 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
576 cwd = alloc(MAXPATHL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 if (cwd == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 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
580 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 vim_free(cwd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 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
585 #ifdef BACKSLASH_IN_FILENAME
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 (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
587 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 PATH_ESC_CHARS,
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 '\\', TRUE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 vim_free(cwd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 if (cdp == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 ga_init2(&ga, 1, 100);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 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
596 ga_concat(&ga, cdp);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 // 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
599 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
600 "<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
601 if (tabs)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 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
603 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
604 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
605 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 // 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
607 // 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
608 // non-wildcard characters.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 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
610 #ifdef UNIX
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 PATH_ESC_CHARS
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 (char_u *)" \t%#"
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 );
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 if (p == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 vim_free(ga.ga_data);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 return NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 ga_concat(&ga, (char_u *)" ");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 ga_concat(&ga, p);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 vim_free(p);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 }
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
625 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
626 "|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
627
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 // 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
629 // CTRL-\ CTRL-N again.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 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
631
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 // 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
633 // 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
634 // 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
635 // if !exists('+acd') || !&acd
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 // if haslocaldir()
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 // cd -
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 // lcd -
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 // elseif getcwd() ==# 'current path'
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 // cd -
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 // endif
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 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
644 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
645 ga_concat(&ga, cdp);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 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
647 vim_free(cdp);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 if (sendReply)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 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
651 ga_concat(&ga, (char_u *)":");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 if (inicmd != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 // Can't use <CR> after "inicmd", because an "startinsert" would cause
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 // 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
656 // hopefully "inicmd" does allow this...
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 ga_concat(&ga, inicmd);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 ga_concat(&ga, (char_u *)"|");
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 // 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
661 // clear command line.
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 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
663 ga_append(&ga, NUL);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 return ga.ga_data;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 }
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 * 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
669 * 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
670 * 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
671 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 static char_u *
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 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
674 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 char_u *p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 if (arg != NULL && *arg != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 p = vim_strsave_up(arg);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 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
682 // 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
683 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
684 *vim_strchr(p, '.') = NUL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 return p;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 #endif // FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 #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
691 static void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 make_connection(void)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 if (X_DISPLAY == NULL
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 # ifdef FEAT_GUI
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 && !gui.in_use
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 )
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 x_force_connect = TRUE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 setup_term_clip();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 x_force_connect = FALSE;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 }
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 static int
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 check_connection(void)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 make_connection();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 if (X_DISPLAY == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 {
26893
79c76ca2c53c patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
712 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
713 return FAIL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 return OK;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 static void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 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
722 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 char_u *server_name;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 char_u *keys;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 char_u *r = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 char_u buf[NUMBUFLEN];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 int timeout = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 HWND w;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 Window w;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 if (check_restricted() || check_secure())
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 if (check_connection() == FAIL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 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
742 && 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
743 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
744
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 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
746 if (server_name == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 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
748 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
749 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 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
751 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 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
753 0, TRUE) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 if (r != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 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
759 vim_free(r);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 else
26893
79c76ca2c53c patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
762 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
763 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 }
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 rettv->vval.v_string = r;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 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
769 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 dictitem_T v;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 char_u str[30];
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 char_u *idvar;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 if (idvar != NULL && *idvar != NUL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 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
778 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
779 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
780 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
781 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
782 }
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 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 #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
788 /*
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 * "remote_expr()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 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
793 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 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
796
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
797 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
798 && (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
799 || 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
800 || 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
801 || (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
802 && 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
803 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
804
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 remote_common(argvars, rettv, TRUE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 }
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 * "remote_foreground()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 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
815 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 #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
817 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
818 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
819
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 // 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
822 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 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
824
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 if (server_name != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 serverForeground(server_name);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 // 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
830 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
831 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
832 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
833 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 rettv->vval.v_string = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 remote_common(argvars, rettv, TRUE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 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
837 # endif
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 }
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 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 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
843 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 dictitem_T v;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 char_u *s = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 long_u n = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 char_u *serverid;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851
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
852 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
853 if (check_restricted() || check_secure())
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 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
855
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 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
857 && (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
858 || 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
859 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
860
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 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
862 if (serverid == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 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
864 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 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
866 if (n == 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 rettv->vval.v_number = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 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
871 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
872 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 if (check_connection() == FAIL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 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
878 serverStrToWin(serverid), &s);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 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
882 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 char_u *retvar;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 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
886 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
887 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
888 if (retvar != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 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
890 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
891 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 rettv->vval.v_number = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 }
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 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 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
899 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 char_u *r = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 #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
903 char_u *serverid;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904
25252
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
905 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
906 && (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
907 || 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
908 return;
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
909
acda780ffc3e patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21723
diff changeset
910 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
911 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
912 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 int timeout = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 // 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
916 long_u n = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 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
920 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
921
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 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
924 if (n != 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 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
926 if (r == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 if (check_connection() == FAIL
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 || serverReadReply(X_DISPLAY, serverStrToWin(serverid),
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 &r, FALSE, timeout) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 # endif
26897
d02d40f0261c patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26893
diff changeset
932 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
933 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 rettv->vval.v_string = r;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 }
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 * "remote_send()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 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
944 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 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
947
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
948 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
949 && (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
950 || 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
951 || 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
952 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25252
diff changeset
953
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 remote_common(argvars, rettv, FALSE);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 }
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 * "remote_startserver()" function
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 */
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 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
964 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 #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
966 char_u *server;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967
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
968 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
969 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
970
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 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
972 if (server == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 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
974 if (serverName != NULL)
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
975 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
976 else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 if (check_connection() == OK)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 serverRegisterName(X_DISPLAY, server);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 serverSetName(server);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 #else
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
986 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
987 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 }
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 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 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
992 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 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
995 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
996 char_u *reply;
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 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
999 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
1000 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
1001
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 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
1003 && (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
1004 || 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
1005 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
1006
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 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
1008 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
1009 if (server == NULL || reply == NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 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
1011
19920
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 # ifdef FEAT_X11
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 if (check_connection() == FAIL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 # endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 if (serverSendReply(server, reply) < 0)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 {
26893
79c76ca2c53c patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
1019 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
1020 return;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 rettv->vval.v_number = 0;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 #else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 rettv->vval.v_number = -1;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 #endif
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 }
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 void
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 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
1030 {
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 char_u *r = NULL;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 #ifdef FEAT_CLIENTSERVER
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 # ifdef MSWIN
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 r = serverGetVimNames();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 # else
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 make_connection();
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 if (X_DISPLAY != NULL)
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 r = serverGetVimNames(X_DISPLAY);
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 # endif
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 rettv->v_type = VAR_STRING;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 rettv->vval.v_string = r;
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 }
5e41b2e63c73 patch 8.2.0516: client-server code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 #endif