annotate src/job.c @ 30079:105f946422d1 v9.0.0377

patch 9.0.0377: argument assignment does not work Commit: https://github.com/vim/vim/commit/eb5adf19d15de4dd1d148954ac5345154f0fea60 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 4 13:41:37 2022 +0100 patch 9.0.0377: argument assignment does not work Problem: Argument assignment does not work. Solution: Skip over "=".
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Sep 2022 14:45:02 +0200
parents da56650de132
children b6bef244837e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 * Implements starting jobs and controlling them.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 #include "vim.h"
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #define FOR_ALL_JOBS(job) \
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 for ((job) = first_job; (job) != NULL; (job) = (job)->jv_next)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 handle_mode(typval_T *item, jobopt_T *opt, ch_mode_T *modep, int jo)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 char_u *val = tv_get_string(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 opt->jo_set |= jo;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 if (STRCMP(val, "nl") == 0)
28769
78fc778de076 patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents: 28244
diff changeset
27 *modep = CH_MODE_NL;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 else if (STRCMP(val, "raw") == 0)
28769
78fc778de076 patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents: 28244
diff changeset
29 *modep = CH_MODE_RAW;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 else if (STRCMP(val, "js") == 0)
28769
78fc778de076 patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents: 28244
diff changeset
31 *modep = CH_MODE_JS;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 else if (STRCMP(val, "json") == 0)
28769
78fc778de076 patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents: 28244
diff changeset
33 *modep = CH_MODE_JSON;
28244
85b07a942518 patch 8.2.4648: handling LSP messages is a bit slow
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
34 else if (STRCMP(val, "lsp") == 0)
28769
78fc778de076 patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents: 28244
diff changeset
35 *modep = CH_MODE_LSP;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
38 semsg(_(e_invalid_argument_str), val);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 handle_io(typval_T *item, ch_part_T part, jobopt_T *opt)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 char_u *val = tv_get_string(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 opt->jo_set |= JO_OUT_IO << (part - PART_OUT);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 if (STRCMP(val, "null") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 opt->jo_io[part] = JIO_NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 else if (STRCMP(val, "pipe") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 opt->jo_io[part] = JIO_PIPE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 else if (STRCMP(val, "file") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 opt->jo_io[part] = JIO_FILE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 else if (STRCMP(val, "buffer") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 opt->jo_io[part] = JIO_BUFFER;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 else if (STRCMP(val, "out") == 0 && part == PART_ERR)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 opt->jo_io[part] = JIO_OUT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
62 semsg(_(e_invalid_argument_str), val);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 * Clear a jobopt_T before using it.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 clear_job_options(jobopt_T *opt)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 CLEAR_POINTER(opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 * Free any members of a jobopt_T.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 free_job_options(jobopt_T *opt)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 if (opt->jo_callback.cb_partial != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 partial_unref(opt->jo_callback.cb_partial);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 else if (opt->jo_callback.cb_name != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 func_unref(opt->jo_callback.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 if (opt->jo_out_cb.cb_partial != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 partial_unref(opt->jo_out_cb.cb_partial);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 else if (opt->jo_out_cb.cb_name != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 func_unref(opt->jo_out_cb.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 if (opt->jo_err_cb.cb_partial != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 partial_unref(opt->jo_err_cb.cb_partial);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 else if (opt->jo_err_cb.cb_name != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 func_unref(opt->jo_err_cb.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 if (opt->jo_close_cb.cb_partial != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 partial_unref(opt->jo_close_cb.cb_partial);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 else if (opt->jo_close_cb.cb_name != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 func_unref(opt->jo_close_cb.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 if (opt->jo_exit_cb.cb_partial != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 partial_unref(opt->jo_exit_cb.cb_partial);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 else if (opt->jo_exit_cb.cb_name != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 func_unref(opt->jo_exit_cb.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 if (opt->jo_env != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 dict_unref(opt->jo_env);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 * Get the PART_ number from the first character of an option name.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 part_from_char(int c)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 return c == 'i' ? PART_IN : c == 'o' ? PART_OUT: PART_ERR;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 * Get the option entries from the dict in "tv", parse them and put the result
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 * in "opt".
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 * Only accept JO_ options in "supported" and JO2_ options in "supported2".
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 * If an option value is invalid return FAIL.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 typval_T *item;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 char_u *val;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 dict_T *dict;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 int todo;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 hashitem_T *hi;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 ch_part_T part;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 if (tv->v_type == VAR_UNKNOWN)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 if (tv->v_type != VAR_DICT)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
136 emsg(_(e_dictionary_required));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 dict = tv->vval.v_dict;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 if (dict == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 todo = (int)dict->dv_hashtab.ht_used;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 if (!HASHITEM_EMPTY(hi))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 item = &dict_lookup(hi)->di_tv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 if (STRCMP(hi->hi_key, "mode") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 if (!(supported & JO_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 if (handle_mode(item, opt, &opt->jo_mode, JO_MODE) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 else if (STRCMP(hi->hi_key, "in_mode") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 if (!(supported & JO_IN_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 if (handle_mode(item, opt, &opt->jo_in_mode, JO_IN_MODE)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 else if (STRCMP(hi->hi_key, "out_mode") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 if (!(supported & JO_OUT_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 if (handle_mode(item, opt, &opt->jo_out_mode, JO_OUT_MODE)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 else if (STRCMP(hi->hi_key, "err_mode") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 if (!(supported & JO_ERR_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 if (handle_mode(item, opt, &opt->jo_err_mode, JO_ERR_MODE)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 else if (STRCMP(hi->hi_key, "noblock") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 if (!(supported & JO_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 opt->jo_noblock = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 else if (STRCMP(hi->hi_key, "in_io") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 || STRCMP(hi->hi_key, "out_io") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 || STRCMP(hi->hi_key, "err_io") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 if (handle_io(item, part_from_char(*hi->hi_key), opt) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 else if (STRCMP(hi->hi_key, "in_name") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 || STRCMP(hi->hi_key, "out_name") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 || STRCMP(hi->hi_key, "err_name") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 part = part_from_char(*hi->hi_key);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 opt->jo_set |= JO_OUT_NAME << (part - PART_OUT);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 opt->jo_io_name[part] = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 opt->jo_io_name_buf[part]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 else if (STRCMP(hi->hi_key, "pty") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (!(supported & JO_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 opt->jo_pty = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 else if (STRCMP(hi->hi_key, "in_buf") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 || STRCMP(hi->hi_key, "out_buf") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 || STRCMP(hi->hi_key, "err_buf") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 part = part_from_char(*hi->hi_key);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 opt->jo_set |= JO_OUT_BUF << (part - PART_OUT);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 opt->jo_io_buf[part] = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 if (opt->jo_io_buf[part] <= 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 {
29239
da56650de132 patch 8.2.5138: various small issues
Bram Moolenaar <Bram@vim.org>
parents: 29175
diff changeset
225 semsg(_(e_invalid_value_for_argument_str_str),
da56650de132 patch 8.2.5138: various small issues
Bram Moolenaar <Bram@vim.org>
parents: 29175
diff changeset
226 hi->hi_key, tv_get_string(item));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 if (buflist_findnr(opt->jo_io_buf[part]) == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 {
26439
b18f3b0f317c patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26113
diff changeset
231 semsg(_(e_buffer_nr_does_not_exist),
b18f3b0f317c patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26113
diff changeset
232 (long)opt->jo_io_buf[part]);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 else if (STRCMP(hi->hi_key, "out_modifiable") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 || STRCMP(hi->hi_key, "err_modifiable") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 part = part_from_char(*hi->hi_key);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 opt->jo_set |= JO_OUT_MODIFIABLE << (part - PART_OUT);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 opt->jo_modifiable[part] = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 else if (STRCMP(hi->hi_key, "out_msg") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 || STRCMP(hi->hi_key, "err_msg") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 part = part_from_char(*hi->hi_key);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 opt->jo_set2 |= JO2_OUT_MSG << (part - PART_OUT);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 opt->jo_message[part] = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 else if (STRCMP(hi->hi_key, "in_top") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 || STRCMP(hi->hi_key, "in_bot") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 linenr_T *lp;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 if (hi->hi_key[3] == 't')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 lp = &opt->jo_in_top;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 opt->jo_set |= JO_IN_TOP;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 lp = &opt->jo_in_bot;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 opt->jo_set |= JO_IN_BOT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 *lp = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 if (*lp < 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
276 semsg(_(e_invalid_value_for_argument_str_str), hi->hi_key, tv_get_string(item));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 else if (STRCMP(hi->hi_key, "channel") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 if (!(supported & JO_OUT_IO))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 opt->jo_set |= JO_CHANNEL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 if (item->v_type != VAR_CHANNEL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
287 semsg(_(e_invalid_value_for_argument_str), "channel");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 opt->jo_channel = item->vval.v_channel;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 else if (STRCMP(hi->hi_key, "callback") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 if (!(supported & JO_CALLBACK))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 opt->jo_set |= JO_CALLBACK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 opt->jo_callback = get_callback(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 if (opt->jo_callback.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
300 semsg(_(e_invalid_value_for_argument_str), "callback");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 else if (STRCMP(hi->hi_key, "out_cb") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 if (!(supported & JO_OUT_CALLBACK))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 opt->jo_set |= JO_OUT_CALLBACK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 opt->jo_out_cb = get_callback(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 if (opt->jo_out_cb.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
312 semsg(_(e_invalid_value_for_argument_str), "out_cb");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 else if (STRCMP(hi->hi_key, "err_cb") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 if (!(supported & JO_ERR_CALLBACK))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 opt->jo_set |= JO_ERR_CALLBACK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 opt->jo_err_cb = get_callback(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 if (opt->jo_err_cb.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
324 semsg(_(e_invalid_value_for_argument_str), "err_cb");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 else if (STRCMP(hi->hi_key, "close_cb") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 if (!(supported & JO_CLOSE_CALLBACK))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 opt->jo_set |= JO_CLOSE_CALLBACK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 opt->jo_close_cb = get_callback(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 if (opt->jo_close_cb.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
336 semsg(_(e_invalid_value_for_argument_str), "close_cb");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 else if (STRCMP(hi->hi_key, "drop") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 int never = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 val = tv_get_string(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 if (STRCMP(val, "never") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 never = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 else if (STRCMP(val, "auto") != 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
349 semsg(_(e_invalid_value_for_argument_str_str), "drop", val);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 opt->jo_drop_never = never;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 else if (STRCMP(hi->hi_key, "exit_cb") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 if (!(supported & JO_EXIT_CB))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 opt->jo_set |= JO_EXIT_CB;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 opt->jo_exit_cb = get_callback(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 if (opt->jo_exit_cb.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
362 semsg(_(e_invalid_value_for_argument_str), "exit_cb");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 #ifdef FEAT_TERMINAL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 else if (STRCMP(hi->hi_key, "term_name") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 if (!(supported2 & JO2_TERM_NAME))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 opt->jo_set2 |= JO2_TERM_NAME;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 opt->jo_term_name = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 opt->jo_term_name_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 if (opt->jo_term_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
376 semsg(_(e_invalid_value_for_argument_str), "term_name");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 else if (STRCMP(hi->hi_key, "term_finish") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 if (!(supported2 & JO2_TERM_FINISH))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 val = tv_get_string(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 if (STRCMP(val, "open") != 0 && STRCMP(val, "close") != 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
387 semsg(_(e_invalid_value_for_argument_str_str), "term_finish", val);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 opt->jo_set2 |= JO2_TERM_FINISH;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 opt->jo_term_finish = *val;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 else if (STRCMP(hi->hi_key, "term_opencmd") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 char_u *p;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 if (!(supported2 & JO2_TERM_OPENCMD))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 opt->jo_set2 |= JO2_TERM_OPENCMD;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 p = opt->jo_term_opencmd = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 opt->jo_term_opencmd_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 if (p != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 // Must have %d and no other %.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 p = vim_strchr(p, '%');
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 if (p != NULL && (p[1] != 'd'
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 || vim_strchr(p + 2, '%') != NULL))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 p = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 if (p == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
412 semsg(_(e_invalid_value_for_argument_str), "term_opencmd");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 else if (STRCMP(hi->hi_key, "eof_chars") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 if (!(supported2 & JO2_EOF_CHARS))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 opt->jo_set2 |= JO2_EOF_CHARS;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 opt->jo_eof_chars = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 opt->jo_eof_chars_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 if (opt->jo_eof_chars == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
425 semsg(_(e_invalid_value_for_argument_str), "eof_chars");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 else if (STRCMP(hi->hi_key, "term_rows") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 {
26105
fd1cbe72815a patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents: 26057
diff changeset
431 int error = FALSE;
fd1cbe72815a patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents: 26057
diff changeset
432
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 if (!(supported2 & JO2_TERM_ROWS))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 opt->jo_set2 |= JO2_TERM_ROWS;
26105
fd1cbe72815a patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents: 26057
diff changeset
436 opt->jo_term_rows = tv_get_number_chk(item, &error);
fd1cbe72815a patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents: 26057
diff changeset
437 if (error)
fd1cbe72815a patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents: 26057
diff changeset
438 return FAIL;
26113
c421c9599d83 patch 8.2.3589: failure when "term_rows" of term_start() is an unusual value
Bram Moolenaar <Bram@vim.org>
parents: 26105
diff changeset
439 if (opt->jo_term_rows < 0 || opt->jo_term_rows > 1000)
c421c9599d83 patch 8.2.3589: failure when "term_rows" of term_start() is an unusual value
Bram Moolenaar <Bram@vim.org>
parents: 26105
diff changeset
440 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
441 semsg(_(e_invalid_value_for_argument_str), "term_rows");
26113
c421c9599d83 patch 8.2.3589: failure when "term_rows" of term_start() is an unusual value
Bram Moolenaar <Bram@vim.org>
parents: 26105
diff changeset
442 return FAIL;
c421c9599d83 patch 8.2.3589: failure when "term_rows" of term_start() is an unusual value
Bram Moolenaar <Bram@vim.org>
parents: 26105
diff changeset
443 }
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 else if (STRCMP(hi->hi_key, "term_cols") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 if (!(supported2 & JO2_TERM_COLS))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 opt->jo_set2 |= JO2_TERM_COLS;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 opt->jo_term_cols = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 else if (STRCMP(hi->hi_key, "vertical") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 if (!(supported2 & JO2_VERTICAL))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 opt->jo_set2 |= JO2_VERTICAL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 opt->jo_vertical = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 else if (STRCMP(hi->hi_key, "curwin") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 if (!(supported2 & JO2_CURWIN))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 opt->jo_set2 |= JO2_CURWIN;
22155
de47cb7b41e6 patch 8.2.1627: Vim9: cannot pass "true" to submatch/term_gettty/term_start
Bram Moolenaar <Bram@vim.org>
parents: 22095
diff changeset
464 opt->jo_curwin = tv_get_bool(item);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 else if (STRCMP(hi->hi_key, "bufnr") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 int nr;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 if (!(supported2 & JO2_CURWIN))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 opt->jo_set2 |= JO2_BUFNR;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 nr = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 if (nr <= 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
476 semsg(_(e_invalid_value_for_argument_str_str), hi->hi_key, tv_get_string(item));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 opt->jo_bufnr_buf = buflist_findnr(nr);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 if (opt->jo_bufnr_buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
26439
b18f3b0f317c patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26113
diff changeset
482 semsg(_(e_buffer_nr_does_not_exist), (long)nr);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 if (opt->jo_bufnr_buf->b_nwindows == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 || opt->jo_bufnr_buf->b_term == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
488 semsg(_(e_invalid_argument_str), "bufnr");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 else if (STRCMP(hi->hi_key, "hidden") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 if (!(supported2 & JO2_HIDDEN))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 opt->jo_set2 |= JO2_HIDDEN;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 opt->jo_hidden = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 else if (STRCMP(hi->hi_key, "norestore") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 if (!(supported2 & JO2_NORESTORE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 opt->jo_set2 |= JO2_NORESTORE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 opt->jo_term_norestore = tv_get_bool(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 else if (STRCMP(hi->hi_key, "term_kill") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 if (!(supported2 & JO2_TERM_KILL))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 opt->jo_set2 |= JO2_TERM_KILL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 opt->jo_term_kill = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 opt->jo_term_kill_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (opt->jo_term_kill == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
515 semsg(_(e_invalid_value_for_argument_str), "term_kill");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 else if (STRCMP(hi->hi_key, "tty_type") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 char_u *p;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 if (!(supported2 & JO2_TTY_TYPE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 opt->jo_set2 |= JO2_TTY_TYPE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 p = tv_get_string_chk(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 if (p == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
529 semsg(_(e_invalid_value_for_argument_str), "tty_type");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 // Allow empty string, "winpty", "conpty".
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 if (!(*p == NUL || STRCMP(p, "winpty") == 0
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28769
diff changeset
534 || STRCMP(p, "conpty") == 0))
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
536 semsg(_(e_invalid_value_for_argument_str), "tty_type");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 opt->jo_tty_type = p[0];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 else if (STRCMP(hi->hi_key, "ansi_colors") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 int n = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 listitem_T *li;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 long_u rgb[16];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 if (!(supported2 & JO2_ANSI_COLORS))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 if (item == NULL || item->v_type != VAR_LIST
28919
99c1356f4210 patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
552 || item->vval.v_list == NULL
99c1356f4210 patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
553 || item->vval.v_list->lv_first == &range_list_item)
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
555 semsg(_(e_invalid_value_for_argument_str), "ansi_colors");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 li = item->vval.v_list->lv_first;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 for (; li != NULL && n < 16; li = li->li_next, n++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 char_u *color_name;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 guicolor_T guicolor;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 int called_emsg_before = called_emsg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 color_name = tv_get_string_chk(&li->li_tv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 if (color_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 guicolor = GUI_GET_COLOR(color_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if (guicolor == INVALCOLOR)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (called_emsg_before == called_emsg)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 // may not get the error if the GUI didn't start
26057
92c424550367 patch 8.2.3562: cannot add color names
Bram Moolenaar <Bram@vim.org>
parents: 25686
diff changeset
575 semsg(_(e_cannot_allocate_color_str), color_name);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 rgb[n] = GUI_MCH_GET_RGB(guicolor);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 if (n != 16 || li != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
584 semsg(_(e_invalid_value_for_argument_str), "ansi_colors");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 opt->jo_set2 |= JO2_ANSI_COLORS;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 memcpy(opt->jo_ansi_colors, rgb, sizeof(rgb));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 # endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 else if (STRCMP(hi->hi_key, "term_highlight") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 char_u *p;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 if (!(supported2 & JO2_TERM_HIGHLIGHT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 opt->jo_set2 |= JO2_TERM_HIGHLIGHT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 p = tv_get_string_buf_chk(item, opt->jo_term_highlight_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 if (p == NULL || *p == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
602 semsg(_(e_invalid_value_for_argument_str), "term_highlight");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 opt->jo_term_highlight = p;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 else if (STRCMP(hi->hi_key, "term_api") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 if (!(supported2 & JO2_TERM_API))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 opt->jo_set2 |= JO2_TERM_API;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 opt->jo_term_api = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 opt->jo_term_api_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (opt->jo_term_api == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
616 semsg(_(e_invalid_value_for_argument_str), "term_api");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 else if (STRCMP(hi->hi_key, "env") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 if (!(supported2 & JO2_ENV))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 if (item->v_type != VAR_DICT)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
627 semsg(_(e_invalid_value_for_argument_str), "env");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 opt->jo_set2 |= JO2_ENV;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 opt->jo_env = item->vval.v_dict;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 if (opt->jo_env != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 ++opt->jo_env->dv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 else if (STRCMP(hi->hi_key, "cwd") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 if (!(supported2 & JO2_CWD))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 opt->jo_cwd = tv_get_string_buf_chk(item, opt->jo_cwd_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 #ifndef MSWIN // Win32 directories don't have the concept of "executable"
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 || mch_access((char *)opt->jo_cwd, X_OK) != 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 )
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
646 semsg(_(e_invalid_value_for_argument_str), "cwd");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 opt->jo_set2 |= JO2_CWD;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 else if (STRCMP(hi->hi_key, "waittime") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 if (!(supported & JO_WAITTIME))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 opt->jo_set |= JO_WAITTIME;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 opt->jo_waittime = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 else if (STRCMP(hi->hi_key, "timeout") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 if (!(supported & JO_TIMEOUT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 opt->jo_set |= JO_TIMEOUT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 opt->jo_timeout = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 else if (STRCMP(hi->hi_key, "out_timeout") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 if (!(supported & JO_OUT_TIMEOUT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 opt->jo_set |= JO_OUT_TIMEOUT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 opt->jo_out_timeout = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 else if (STRCMP(hi->hi_key, "err_timeout") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 if (!(supported & JO_ERR_TIMEOUT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 opt->jo_set |= JO_ERR_TIMEOUT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 opt->jo_err_timeout = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 else if (STRCMP(hi->hi_key, "part") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 if (!(supported & JO_PART))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 opt->jo_set |= JO_PART;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 val = tv_get_string(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 if (STRCMP(val, "err") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 opt->jo_part = PART_ERR;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 else if (STRCMP(val, "out") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 opt->jo_part = PART_OUT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
691 semsg(_(e_invalid_value_for_argument_str_str), "part", val);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 else if (STRCMP(hi->hi_key, "id") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 if (!(supported & JO_ID))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 opt->jo_set |= JO_ID;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 opt->jo_id = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 else if (STRCMP(hi->hi_key, "stoponexit") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 if (!(supported & JO_STOPONEXIT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 opt->jo_set |= JO_STOPONEXIT;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 opt->jo_stoponexit = tv_get_string_buf_chk(item,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 opt->jo_stoponexit_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 if (opt->jo_stoponexit == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
711 semsg(_(e_invalid_value_for_argument_str), "stoponexit");
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 else if (STRCMP(hi->hi_key, "block_write") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 if (!(supported & JO_BLOCK_WRITE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 opt->jo_set |= JO_BLOCK_WRITE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 opt->jo_block_write = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 --todo;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 if (todo > 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
728 semsg(_(e_invalid_argument_str), hi->hi_key);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 static job_T *first_job = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 job_free_contents(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 ch_log(job->jv_channel, "Freeing job");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 if (job->jv_channel != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 // The link from the channel to the job doesn't count as a reference,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 // thus don't decrement the refcount of the job. The reference from
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 // the job to the channel does count the reference, decrement it and
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 // NULL the reference. We don't set ch_job_killed, unreferencing the
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 // job doesn't mean it stops running.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 job->jv_channel->ch_job = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 channel_unref(job->jv_channel);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 mch_clear_job(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 vim_free(job->jv_tty_in);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 vim_free(job->jv_tty_out);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 vim_free(job->jv_stoponexit);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 vim_free(job->jv_termsig);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 #ifdef MSWIN
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 vim_free(job->jv_tty_type);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 free_callback(&job->jv_exit_cb);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 if (job->jv_argv != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 for (i = 0; job->jv_argv[i] != NULL; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 vim_free(job->jv_argv[i]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 vim_free(job->jv_argv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 * Remove "job" from the list of jobs.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 job_unlink(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 if (job->jv_next != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 job->jv_next->jv_prev = job->jv_prev;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 if (job->jv_prev == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 first_job = job->jv_next;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 job->jv_prev->jv_next = job->jv_next;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 job_free_job(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 job_unlink(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 vim_free(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 job_free(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 if (!in_free_unref_items)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 job_free_job(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 static job_T *jobs_to_free = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 * Put "job" in a list to be freed later, when it's no longer referenced.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 job_free_later(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 job_unlink(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 job->jv_next = jobs_to_free;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 jobs_to_free = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 free_jobs_to_free_later(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 while (jobs_to_free != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 job = jobs_to_free;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 jobs_to_free = job->jv_next;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 vim_free(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 #if defined(EXITFREE) || defined(PROTO)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 job_free_all(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 while (first_job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 job_free(first_job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 free_jobs_to_free_later();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 # ifdef FEAT_TERMINAL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 free_unused_terminals();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 # endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 * Return TRUE if we need to check if the process of "job" has ended.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 job_need_end_check(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 return job->jv_status == JOB_STARTED
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 && (job->jv_stoponexit != NULL || job->jv_exit_cb.cb_name != NULL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 * Return TRUE if the channel of "job" is still useful.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 job_channel_still_useful(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 return job->jv_channel != NULL && channel_still_useful(job->jv_channel);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 * Return TRUE if the channel of "job" is closeable.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 job_channel_can_close(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 return job->jv_channel != NULL && channel_can_close(job->jv_channel);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 * Return TRUE if the job should not be freed yet. Do not free the job when
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 * it has not ended yet and there is a "stoponexit" flag, an exit callback
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 * or when the associated channel will do something with the job output.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 job_still_useful(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 return job_need_end_check(job) || job_channel_still_useful(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 #if defined(GUI_MAY_FORK) || defined(GUI_MAY_SPAWN) || defined(PROTO)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 * Return TRUE when there is any running job that we care about.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 job_any_running()
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 if (job_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 ch_log(NULL, "GUI not forking because a job is running");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 return TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 return FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902
23144
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
903 // Unix uses argv[] for the command, other systems use a string.
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
904 #if defined(UNIX)
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
905 # define USE_ARGV
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
906 #endif
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
907
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 #if !defined(USE_ARGV) || defined(PROTO)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 * Escape one argument for an external command.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 * Returns the escaped string in allocated memory. NULL when out of memory.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 static char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 win32_escape_arg(char_u *arg)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 int slen, dlen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 int escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 char_u *s, *d;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 char_u *escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 int has_spaces = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 // First count the number of extra bytes required.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 slen = (int)STRLEN(arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 dlen = slen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 for (s = arg; *s != NUL; MB_PTR_ADV(s))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 if (*s == '"' || *s == '\\')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 ++dlen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 if (*s == ' ' || *s == '\t')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 has_spaces = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 dlen += 2;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 if (dlen == slen)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 return vim_strsave(arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 // Allocate memory for the result and fill it.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 escaped_arg = alloc(dlen + 1);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 if (escaped_arg == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 memset(escaped_arg, 0, dlen+1);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 d = escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 *d++ = '"';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 for (s = arg; *s != NUL;)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 switch (*s)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 case '"':
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 for (i = 0; i < escaping; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 *d++ = *s++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 case '\\':
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 escaping++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 *d++ = *s++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 default:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 MB_COPY_CHAR(s, d);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 // add terminating quote and finish with a NUL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 for (i = 0; i < escaping; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 *d++ = '"';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 *d = NUL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 return escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 * Build a command line from a list, taking care of escaping.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 * The result is put in gap->ga_data.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 * Returns FAIL when out of memory.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 win32_build_cmd(list_T *l, garray_T *gap)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 listitem_T *li;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 char_u *s;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 CHECK_LIST_MATERIALIZE(l);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 FOR_ALL_LIST_ITEMS(l, li)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 s = tv_get_string_chk(&li->li_tv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 if (s == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 s = win32_escape_arg(s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if (s == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 ga_concat(gap, s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 vim_free(s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 if (li->li_next != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 ga_append(gap, ' ');
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 * NOTE: Must call job_cleanup() only once right after the status of "job"
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 * changed to JOB_ENDED (i.e. after job_status() returned "dead" first or
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 * mch_detect_ended_job() returned non-NULL).
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 * If the job is no longer used it will be removed from the list of jobs, and
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 * deleted a bit later.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 job_cleanup(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 if (job->jv_status != JOB_ENDED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 // Ready to cleanup the job.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 job->jv_status = JOB_FINISHED;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 // When only channel-in is kept open, close explicitly.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 if (job->jv_channel != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 ch_close_part(job->jv_channel, PART_IN);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 if (job->jv_exit_cb.cb_name != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 typval_T argv[3];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 // Invoke the exit callback. Make sure the refcount is > 0.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 ch_log(job->jv_channel, "Invoking exit callback %s",
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 job->jv_exit_cb.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 ++job->jv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 argv[0].v_type = VAR_JOB;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 argv[0].vval.v_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 argv[1].v_type = VAR_NUMBER;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 argv[1].vval.v_number = job->jv_exitval;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 call_callback(&job->jv_exit_cb, -1, &rettv, 2, argv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 --job->jv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 channel_need_redraw = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 job->jv_channel->ch_killing = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 // Do not free the job in case the close callback of the associated channel
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 // isn't invoked yet and may get information by job_info().
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 if (job->jv_refcount == 0 && !job_channel_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 // The job was already unreferenced and the associated channel was
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 // detached, now that it ended it can be freed. However, a caller might
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 // still use it, thus free it a bit later.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 job_free_later(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 * Mark references in jobs that are still useful.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 set_ref_in_job(int copyID)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 int abort = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 typval_T tv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 for (job = first_job; !abort && job != NULL; job = job->jv_next)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 if (job_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 tv.v_type = VAR_JOB;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 tv.vval.v_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 return abort;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 * Dereference "job". Note that after this "job" may have been freed.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 job_unref(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 if (job != NULL && --job->jv_refcount <= 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 // Do not free the job if there is a channel where the close callback
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 // may get the job info.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 if (!job_channel_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 // Do not free the job when it has not ended yet and there is a
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 // "stoponexit" flag or an exit callback.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 if (!job_need_end_check(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 job_free(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 else if (job->jv_channel != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 // Do remove the link to the channel, otherwise it hangs
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 // around until Vim exits. See job_free() for refcount.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 ch_log(job->jv_channel, "detaching channel from job");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 job->jv_channel->ch_job = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 channel_unref(job->jv_channel);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 job->jv_channel = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 free_unused_jobs_contents(int copyID, int mask)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 int did_free = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 if ((job->jv_copyID & mask) != (copyID & mask)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 && !job_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 // Free the channel and ordinary items it contains, but don't
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 // recurse into Lists, Dictionaries etc.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 did_free = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 return did_free;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 free_unused_jobs(int copyID, int mask)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 job_T *job_next;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 for (job = first_job; job != NULL; job = job_next)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 job_next = job->jv_next;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 if ((job->jv_copyID & mask) != (copyID & mask)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 && !job_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 // Free the job struct itself.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 job_free_job(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 * Allocate a job. Sets the refcount to one and sets options default.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 job_alloc(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 job = ALLOC_CLEAR_ONE(job_T);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 job->jv_refcount = 1;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 job->jv_stoponexit = vim_strsave((char_u *)"term");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 if (first_job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 first_job->jv_prev = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 job->jv_next = first_job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 first_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 job_set_options(job_T *job, jobopt_T *opt)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 if (opt->jo_set & JO_STOPONEXIT)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 vim_free(job->jv_stoponexit);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 if (opt->jo_stoponexit == NULL || *opt->jo_stoponexit == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 job->jv_stoponexit = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 job->jv_stoponexit = vim_strsave(opt->jo_stoponexit);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 if (opt->jo_set & JO_EXIT_CB)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 free_callback(&job->jv_exit_cb);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 if (opt->jo_exit_cb.cb_name == NULL || *opt->jo_exit_cb.cb_name == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 job->jv_exit_cb.cb_name = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 job->jv_exit_cb.cb_partial = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 copy_callback(&job->jv_exit_cb, &opt->jo_exit_cb);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 * Called when Vim is exiting: kill all jobs that have the "stoponexit" flag.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 job_stop_on_exit(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 if (job->jv_status == JOB_STARTED && job->jv_stoponexit != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 mch_signal_job(job, job->jv_stoponexit);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 * Return TRUE when there is any job that has an exit callback and might exit,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 * which means job_check_ended() should be called more often.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 has_pending_job(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 // Only should check if the channel has been closed, if the channel is
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 // open the job won't exit.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 if ((job->jv_status == JOB_STARTED && !job_channel_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 || (job->jv_status == JOB_FINISHED
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 && job_channel_can_close(job)))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 return TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 return FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 #define MAX_CHECK_ENDED 8
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 * Called once in a while: check if any jobs that seem useful have ended.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 * Returns TRUE if a job did end.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 job_check_ended(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 int did_end = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 // be quick if there are no jobs to check
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 if (first_job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 return did_end;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 for (i = 0; i < MAX_CHECK_ENDED; ++i)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 // NOTE: mch_detect_ended_job() must only return a job of which the
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 // status was just set to JOB_ENDED.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 job_T *job = mch_detect_ended_job(first_job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 did_end = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 job_cleanup(job); // may add "job" to jobs_to_free
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 // Actually free jobs that were cleaned up.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 free_jobs_to_free_later();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 if (channel_need_redraw)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 channel_need_redraw = FALSE;
26466
d413104a94c8 patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1266 redraw_after_callback(TRUE, FALSE);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 return did_end;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 * Create a job and return it. Implements job_start().
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 * "argv_arg" is only for Unix.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 * When "argv_arg" is NULL then "argvars" is used.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 * The returned job has a refcount of one.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 * Returns NULL when out of memory.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 job_start(
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 typval_T *argvars,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 char **argv_arg UNUSED,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 jobopt_T *opt_arg,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 job_T **term_job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 char_u *cmd = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 char **argv = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 int argc = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 int i;
23144
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
1290 #ifndef USE_ARGV
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 garray_T ga;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 jobopt_T opt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 ch_part_T part;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 job = job_alloc();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 job->jv_status = JOB_FAILED;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 #ifndef USE_ARGV
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
1302 ga_init2(&ga, sizeof(char*), 20);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 if (opt_arg != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 opt = *opt_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 // Default mode is NL.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 clear_job_options(&opt);
28769
78fc778de076 patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents: 28244
diff changeset
1311 opt.jo_mode = CH_MODE_NL;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 if (get_job_options(&argvars[1], &opt,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 + JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 JO2_ENV + JO2_CWD) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 // Check that when io is "file" that there is a file name.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 for (part = PART_OUT; part < PART_COUNT; ++part)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 if ((opt.jo_set & (JO_OUT_IO << (part - PART_OUT)))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 && opt.jo_io[part] == JIO_FILE
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 && (!(opt.jo_set & (JO_OUT_NAME << (part - PART_OUT)))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 || *opt.jo_io_name[part] == NUL))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1326 emsg(_(e_io_file_requires_name_to_be_set));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 if ((opt.jo_set & JO_IN_IO) && opt.jo_io[PART_IN] == JIO_BUFFER)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 buf_T *buf = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 // check that we can find the buffer before starting the job
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 if (opt.jo_set & JO_IN_BUF)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 buf = buflist_findnr(opt.jo_io_buf[PART_IN]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 if (buf == NULL)
26439
b18f3b0f317c patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26113
diff changeset
1339 semsg(_(e_buffer_nr_does_not_exist),
b18f3b0f317c patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26113
diff changeset
1340 (long)opt.jo_io_buf[PART_IN]);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 else if (!(opt.jo_set & JO_IN_NAME))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1344 emsg(_(e_in_io_buffer_requires_in_buf_or_in_name_to_be_set));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 buf = buflist_find_by_name(opt.jo_io_name[PART_IN], FALSE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 if (buf->b_ml.ml_mfp == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 char_u numbuf[NUMBUFLEN];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 char_u *s;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 if (opt.jo_set & JO_IN_BUF)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 sprintf((char *)numbuf, "%d", opt.jo_io_buf[PART_IN]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 s = numbuf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 s = opt.jo_io_name[PART_IN];
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1362 semsg(_(e_buffer_must_be_loaded_str), s);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 job->jv_in_buf = buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 job_set_options(job, &opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 #ifdef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 if (argv_arg != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 // Make a copy of argv_arg for job->jv_argv.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 for (i = 0; argv_arg[i] != NULL; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 argc++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 argv = ALLOC_MULT(char *, argc + 1);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 if (argv == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 for (i = 0; i < argc; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 argv[i] = (char *)vim_strsave((char_u *)argv_arg[i]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 argv[argc] = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 if (argvars[0].v_type == VAR_STRING)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 // Command is a string.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 cmd = argvars[0].vval.v_string;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 if (cmd == NULL || *skipwhite(cmd) == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
1391 emsg(_(e_invalid_argument));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 if (build_argv_from_string(cmd, &argv, &argc) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 else if (argvars[0].v_type != VAR_LIST
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 || argvars[0].vval.v_list == NULL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 || argvars[0].vval.v_list->lv_len < 1)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
1402 emsg(_(e_invalid_argument));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 list_T *l = argvars[0].vval.v_list;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 if (build_argv_from_list(l, &argv, &argc) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 // Empty command is invalid.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 if (argc == 0 || *skipwhite((char_u *)argv[0]) == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
1415 emsg(_(e_invalid_argument));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 if (win32_build_cmd(l, &ga) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 cmd = ga.ga_data;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 if (cmd == NULL || *skipwhite(cmd) == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
1424 emsg(_(e_invalid_argument));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 // Save the command used to start the job.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 job->jv_argv = argv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 if (term_job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 *term_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 #ifdef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 if (ch_log_active())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 garray_T ga;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
1441 ga_init2(&ga, sizeof(char), 200);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 for (i = 0; i < argc; ++i)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 if (i > 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 ga_concat(&ga, (char_u *)" ");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 ga_concat(&ga, (char_u *)argv[i]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 ga_append(&ga, NUL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 ch_log(NULL, "Starting job: %s", (char *)ga.ga_data);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 ga_clear(&ga);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 mch_job_start(argv, job, &opt, term_job != NULL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 ch_log(NULL, "Starting job: %s", (char *)cmd);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 mch_job_start((char *)cmd, job, &opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 // If the channel is reading from a buffer, write lines now.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 if (job->jv_channel != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 channel_write_in(job->jv_channel);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 theend:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 vim_free(ga.ga_data);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 if (argv != NULL && argv != job->jv_argv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 for (i = 0; argv[i] != NULL; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 vim_free(argv[i]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 vim_free(argv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 free_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 * Get the status of "job" and invoke the exit callback when needed.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 * The returned string is not allocated.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 char *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 job_status(job_T *job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 char *result;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 if (job->jv_status >= JOB_ENDED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 // No need to check, dead is dead.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 result = "dead";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 else if (job->jv_status == JOB_FAILED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 result = "fail";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 result = mch_job_status(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 if (job->jv_status == JOB_ENDED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 job_cleanup(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 return result;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 * Send a signal to "job". Implements job_stop().
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 * When "type" is not NULL use this for the type.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 * Otherwise use argvars[1] for the type.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 job_stop(job_T *job, typval_T *argvars, char *type)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 char_u *arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 if (type != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 arg = (char_u *)type;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 else if (argvars[1].v_type == VAR_UNKNOWN)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 arg = (char_u *)"";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 arg = tv_get_string_chk(&argvars[1]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 if (arg == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
1518 emsg(_(e_invalid_argument));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 if (job->jv_status == JOB_FAILED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 ch_log(job->jv_channel, "Job failed to start, job_stop() skipped");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 if (job->jv_status == JOB_ENDED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 ch_log(job->jv_channel, "Job has already ended, job_stop() skipped");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 ch_log(job->jv_channel, "Stopping job with '%s'", (char *)arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 if (mch_signal_job(job, arg) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 // Assume that only "kill" will kill the job.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 if (job->jv_channel != NULL && STRCMP(arg, "kill") == 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 job->jv_channel->ch_job_killed = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 // We don't try freeing the job, obviously the caller still has a
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 // reference to it.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 return 1;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 invoke_prompt_callback(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 typval_T argv[2];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 char_u *prompt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 linenr_T lnum = curbuf->b_ml.ml_line_count;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 // Add a new line for the prompt before invoking the callback, so that
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 // text can always be inserted above the last line.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 ml_append(lnum, (char_u *)"", 0, FALSE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 curwin->w_cursor.lnum = lnum + 1;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 curwin->w_cursor.col = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 if (curbuf->b_prompt_callback.cb_name == NULL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 || *curbuf->b_prompt_callback.cb_name == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 text = ml_get(lnum);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 prompt = prompt_text();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 if (STRLEN(text) >= STRLEN(prompt))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 text += STRLEN(prompt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 argv[0].v_type = VAR_STRING;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 argv[0].vval.v_string = vim_strsave(text);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 argv[1].v_type = VAR_UNKNOWN;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 call_callback(&curbuf->b_prompt_callback, -1, &rettv, 1, argv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 clear_tv(&argv[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 * Return TRUE when the interrupt callback was invoked.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 invoke_prompt_interrupt(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 typval_T argv[1];
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26439
diff changeset
1584 int ret;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 if (curbuf->b_prompt_interrupt.cb_name == NULL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 || *curbuf->b_prompt_interrupt.cb_name == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 return FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 argv[0].v_type = VAR_UNKNOWN;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 got_int = FALSE; // don't skip executing commands
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26439
diff changeset
1592 ret = call_callback(&curbuf->b_prompt_interrupt, -1, &rettv, 0, argv);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 clear_tv(&rettv);
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26439
diff changeset
1594 return ret == FAIL ? FALSE : TRUE;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 * Return the effective prompt for the specified buffer.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 */
25567
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1600 static char_u *
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 buf_prompt_text(buf_T* buf)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 if (buf->b_prompt_text == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 return (char_u *)"% ";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 return buf->b_prompt_text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 * Return the effective prompt for the current buffer.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 prompt_text(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 return buf_prompt_text(curbuf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 * Prepare for prompt mode: Make sure the last line has the prompt text.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 * Move the cursor to this line.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 init_prompt(int cmdchar_todo)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 char_u *prompt = prompt_text();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 text = ml_get_curline();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 if (STRNCMP(text, prompt, STRLEN(prompt)) != 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 // prompt is missing, insert it or append a line with it
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 if (*text == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 ml_replace(curbuf->b_ml.ml_line_count, prompt, TRUE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 ml_append(curbuf->b_ml.ml_line_count, prompt, 0, FALSE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 coladvance((colnr_T)MAXCOL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 changed_bytes(curbuf->b_ml.ml_line_count, 0);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 // Insert always starts after the prompt, allow editing text after it.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 if (Insstart_orig.lnum != curwin->w_cursor.lnum
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 || Insstart_orig.col != (int)STRLEN(prompt))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 set_insstart(curwin->w_cursor.lnum, (int)STRLEN(prompt));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 if (cmdchar_todo == 'A')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 coladvance((colnr_T)MAXCOL);
22934
3f04c2cf0ced patch 8.2.2014: using CTRL-O in a prompt buffer moves cursor to start
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
1649 if (curwin->w_cursor.col < (int)STRLEN(prompt))
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 curwin->w_cursor.col = (int)STRLEN(prompt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 // Make sure the cursor is in a valid position.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 check_cursor();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 * Return TRUE if the cursor is in the editable position of the prompt line.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 prompt_curpos_editable()
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 return curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 && curwin->w_cursor.col >= (int)STRLEN(prompt_text());
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 * "prompt_setcallback({buffer}, {callback})" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 f_prompt_setcallback(typval_T *argvars, typval_T *rettv UNUSED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 callback_T callback;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 return;
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1676
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1677 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1678 return;
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1679
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 buf = tv_get_buf(&argvars[0], FALSE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 callback = get_callback(&argvars[1]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 if (callback.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 free_callback(&buf->b_prompt_callback);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 set_callback(&buf->b_prompt_callback, &callback);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 * "prompt_setinterrupt({buffer}, {callback})" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 f_prompt_setinterrupt(typval_T *argvars, typval_T *rettv UNUSED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 callback_T callback;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 return;
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1703
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1704 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1705 return;
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1706
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 buf = tv_get_buf(&argvars[0], FALSE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 callback = get_callback(&argvars[1]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 if (callback.cb_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 free_callback(&buf->b_prompt_interrupt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 set_callback(&buf->b_prompt_interrupt, &callback);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 * "prompt_getprompt({buffer})" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 f_prompt_getprompt(typval_T *argvars, typval_T *rettv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 // return an empty string by default, e.g. it's not a prompt buffer
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 rettv->v_type = VAR_STRING;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 rettv->vval.v_string = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1732 if (in_vim9script() && check_for_buffer_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: 25348
diff changeset
1733 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1734
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 buf = tv_get_buf_from_arg(&argvars[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 if (!bt_prompt(buf))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 rettv->vval.v_string = vim_strsave(buf_prompt_text(buf));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 * "prompt_setprompt({buffer}, {text})" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 f_prompt_setprompt(typval_T *argvars, typval_T *rettv UNUSED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1754 if (in_vim9script()
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1755 && (check_for_buffer_arg(argvars, 0) == FAIL
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1756 || check_for_string_arg(argvars, 1) == FAIL))
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1757 return;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1758
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 buf = tv_get_buf(&argvars[0], FALSE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 text = tv_get_string(&argvars[1]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 vim_free(buf->b_prompt_text);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 buf->b_prompt_text = vim_strsave(text);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 * Get the job from the argument.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 * Returns NULL if the job is invalid.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 static job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 get_job_arg(typval_T *tv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 if (tv->v_type != VAR_JOB)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
1781 semsg(_(e_invalid_argument_str), tv_get_string(tv));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 job = tv->vval.v_job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 if (job == NULL)
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1787 emsg(_(e_not_valid_job));
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 * "job_getchannel()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 f_job_getchannel(typval_T *argvars, typval_T *rettv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1797 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1799 if (in_vim9script() && check_for_job_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: 25348
diff changeset
1800 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1801
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1802 job = get_job_arg(&argvars[0]);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 rettv->v_type = VAR_CHANNEL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 rettv->vval.v_channel = job->jv_channel;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 if (job->jv_channel != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 ++job->jv_channel->ch_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 * Implementation of job_info().
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 job_info(job_T *job, dict_T *dict)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 dictitem_T *item;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 varnumber_T nr;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 list_T *l;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 dict_add_string(dict, "status", (char_u *)job_status(job));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 item = dictitem_alloc((char_u *)"channel");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 if (item == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 item->di_tv.v_type = VAR_CHANNEL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 item->di_tv.vval.v_channel = job->jv_channel;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 if (job->jv_channel != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 ++job->jv_channel->ch_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 if (dict_add(dict, item) == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 dictitem_free(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 nr = job->jv_pid;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 nr = job->jv_proc_info.dwProcessId;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 dict_add_number(dict, "process", nr);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 dict_add_string(dict, "tty_in", job->jv_tty_in);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 dict_add_string(dict, "tty_out", job->jv_tty_out);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 dict_add_number(dict, "exitval", job->jv_exitval);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 dict_add_string(dict, "exit_cb", job->jv_exit_cb.cb_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 dict_add_string(dict, "stoponexit", job->jv_stoponexit);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 dict_add_string(dict, "termsig", job->jv_termsig);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 #ifdef MSWIN
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 dict_add_string(dict, "tty_type", job->jv_tty_type);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 l = list_alloc();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 if (l != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 dict_add_list(dict, "cmd", l);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 if (job->jv_argv != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 for (i = 0; job->jv_argv[i] != NULL; i++)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 list_append_string(l, (char_u *)job->jv_argv[i], -1);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 * Implementation of job_info() to return info for all jobs.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 job_info_all(list_T *l)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 typval_T tv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 tv.v_type = VAR_JOB;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 tv.vval.v_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 if (list_append_tv(l, &tv) != OK)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 * "job_info()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 f_job_info(typval_T *argvars, typval_T *rettv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1889 if (in_vim9script() && check_for_opt_job_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: 25348
diff changeset
1890 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1891
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 if (argvars[0].v_type != VAR_UNKNOWN)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1894 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1896 job = get_job_arg(&argvars[0]);
29175
755ab148288b patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents: 28919
diff changeset
1897 if (job != NULL && rettv_dict_alloc(rettv) == OK)
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 job_info(job, rettv->vval.v_dict);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 else if (rettv_list_alloc(rettv) == OK)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 job_info_all(rettv->vval.v_list);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 * "job_setoptions()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 {
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1910 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 jobopt_T opt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1913 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1914 && (check_for_job_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1915 || check_for_dict_arg(argvars, 1) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1916 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1917
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1918 job = get_job_arg(&argvars[0]);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 clear_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 if (get_job_options(&argvars[1], &opt, JO_STOPONEXIT + JO_EXIT_CB, 0) == OK)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 job_set_options(job, &opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 free_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 * "job_start()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 f_job_start(typval_T *argvars, typval_T *rettv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 rettv->v_type = VAR_JOB;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 if (check_restricted() || check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 return;
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1936
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1937 if (in_vim9script()
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1938 && (check_for_string_or_list_arg(argvars, 0) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1939 || check_for_opt_dict_arg(argvars, 1) == FAIL))
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1940 return;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1941
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 rettv->vval.v_job = job_start(argvars, NULL, NULL, NULL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 * "job_status()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 f_job_status(typval_T *argvars, typval_T *rettv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1951 if (in_vim9script() && check_for_job_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: 25348
diff changeset
1952 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1953
22618
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1954 if (argvars[0].v_type == VAR_JOB && argvars[0].vval.v_job == NULL)
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1955 {
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1956 // A job that never started returns "fail".
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1957 rettv->v_type = VAR_STRING;
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1958 rettv->vval.v_string = vim_strsave((char_u *)"fail");
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1959 }
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1960 else
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1961 {
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1962 job_T *job = get_job_arg(&argvars[0]);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963
22618
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1964 if (job != NULL)
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1965 {
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1966 rettv->v_type = VAR_STRING;
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1967 rettv->vval.v_string = vim_strsave((char_u *)job_status(job));
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22155
diff changeset
1968 }
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 * "job_stop()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 f_job_stop(typval_T *argvars, typval_T *rettv)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 {
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1978 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1980 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1981 && (check_for_job_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1982 || check_for_opt_string_or_number_arg(argvars, 1) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1983 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1984
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1985 job = get_job_arg(&argvars[0]);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 rettv->vval.v_number = job_stop(job, argvars, NULL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1990 /*
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1991 * Get a string with information about the job in "varp" in "buf".
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1992 * "buf" must be at least NUMBUFLEN long.
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1993 */
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1994 char_u *
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1995 job_to_string_buf(typval_T *varp, char_u *buf)
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1996 {
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1997 job_T *job = varp->vval.v_job;
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1998 char *status;
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1999
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2000 if (job == NULL)
25686
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
2001 {
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
2002 vim_snprintf((char *)buf, NUMBUFLEN, "no process");
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
2003 return buf;
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
2004 }
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2005 status = job->jv_status == JOB_FAILED ? "fail"
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2006 : job->jv_status >= JOB_ENDED ? "dead"
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2007 : "run";
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2008 # ifdef UNIX
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2009 vim_snprintf((char *)buf, NUMBUFLEN,
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2010 "process %ld %s", (long)job->jv_pid, status);
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2011 # elif defined(MSWIN)
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2012 vim_snprintf((char *)buf, NUMBUFLEN,
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2013 "process %ld %s",
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2014 (long)job->jv_proc_info.dwProcessId,
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2015 status);
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2016 # else
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2017 // fall-back
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2018 vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status);
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2019 # endif
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2020 return buf;
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2021 }
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2022
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 #endif // FEAT_JOB_CHANNEL