annotate src/job.c @ 22745:34e09ca2ddb7

Added tag v8.2.1920 for changeset f63d14eca5c4d3cf075230af2ba7bcfa11d2a695
author Bram Moolenaar <Bram@vim.org>
date Wed, 28 Oct 2020 23:00:05 +0100
parents c2d8b596dd0f
children 3f04c2cf0ced
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)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 *modep = MODE_NL;
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)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 *modep = MODE_RAW;
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)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 *modep = MODE_JS;
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)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 *modep = MODE_JSON;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 semsg(_(e_invarg2), val);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 return OK;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 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
44 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 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
46
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 semsg(_(e_invarg2), val);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 return OK;
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
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 * 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
68 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 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
71 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 CLEAR_POINTER(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
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 * 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
77 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 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
80 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104
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 * 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
107 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 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
110 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 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
112 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113
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 * 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
116 * in "opt".
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 * 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
118 * 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
119 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 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
122 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 typval_T *item;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 char_u *val;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 dict_T *dict;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 int todo;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 hashitem_T *hi;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 ch_part_T part;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 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
131 return OK;
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_DICT)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 emsg(_(e_dictreq));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 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
138 if (dict == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 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
142 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
143 if (!HASHITEM_EMPTY(hi))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 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
146
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 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
148 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 if (!(supported & JO_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 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
152 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 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
155 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 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
157 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 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
159 == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 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
163 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 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
165 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 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
167 == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 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
171 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 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
173 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 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
175 == FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 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
179 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 if (!(supported & JO_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 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
183 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 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
185 || 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
186 || 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
187 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 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
189 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 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
191 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 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
194 || 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
195 || 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
196 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 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
198
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 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
200 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 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
202 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
203 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
204 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 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
206 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 if (!(supported & JO_MODE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 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
210 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 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
212 || 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
213 || 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
214 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 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
216
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 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
218 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 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
220 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
221 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
222 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 semsg(_(e_invargNval), hi->hi_key, tv_get_string(item));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 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
227 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 semsg(_(e_nobufnr), (long)opt->jo_io_buf[part]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 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
233 || 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
234 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 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
236
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 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
238 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 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
240 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
241 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 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
243 || 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
244 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 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
246
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 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
248 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 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
250 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
251 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 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
253 || 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
254 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 linenr_T *lp;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 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
258 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 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
260 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 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
262 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
263 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 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
267 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
268 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 *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
270 if (*lp < 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 semsg(_(e_invargNval), hi->hi_key, tv_get_string(item));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 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
277 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 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
279 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 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
281 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
282 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 semsg(_(e_invargval), "channel");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 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
287 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 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
289 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 if (!(supported & JO_CALLBACK))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 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
293 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
294 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
295 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 semsg(_(e_invargval), "callback");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 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
301 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 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
303 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 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
305 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
306 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
307 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 semsg(_(e_invargval), "out_cb");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 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
313 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 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
315 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 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
317 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
318 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
319 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 semsg(_(e_invargval), "err_cb");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 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
325 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 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
327 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 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
329 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
330 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
331 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 semsg(_(e_invargval), "close_cb");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 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
337 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 int never = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 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
340
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 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
342 never = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 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
344 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 semsg(_(e_invargNval), "drop", val);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 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
349 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 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
351 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 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
353 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 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
355 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
356 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
357 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 semsg(_(e_invargval), "exit_cb");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 #ifdef FEAT_TERMINAL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 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
364 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 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
366 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 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
368 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
369 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
370 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
371 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 semsg(_(e_invargval), "term_name");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 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
377 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 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
379 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 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
381 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
382 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 semsg(_(e_invargNval), "term_finish", val);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 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
387 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
388 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 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
390 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 char_u *p;
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 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
394 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 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
396 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
397 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
398 if (p != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 // 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
401 p = vim_strchr(p, '%');
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 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
403 || 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
404 p = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 if (p == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 semsg(_(e_invargval), "term_opencmd");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 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
413 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 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
415 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 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
417 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
418 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
419 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
420 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 semsg(_(e_invargval), "eof_chars");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 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
426 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 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
428 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 opt->jo_set2 |= JO2_TERM_ROWS;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 opt->jo_term_rows = tv_get_number(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 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
433 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 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
435 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 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
437 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
438 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 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
440 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 if (!(supported2 & JO2_VERTICAL))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 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
444 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
445 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 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
447 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 if (!(supported2 & JO2_CURWIN))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 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
451 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
452 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 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
454 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 int nr;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 if (!(supported2 & JO2_CURWIN))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 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
460 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
461 if (nr <= 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 semsg(_(e_invargNval), hi->hi_key, tv_get_string(item));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 return FAIL;
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 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
467 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
468 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 semsg(_(e_nobufnr), (long)nr);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 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
473 || 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
474 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 semsg(_(e_invarg2), "bufnr");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 }
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 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
480 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 if (!(supported2 & JO2_HIDDEN))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 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
484 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
485 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 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
487 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 if (!(supported2 & JO2_NORESTORE))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 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
491 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
492 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 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
494 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 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
496 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 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
498 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
499 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
500 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
501 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 semsg(_(e_invargval), "term_kill");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 }
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, "tty_type") == 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 char_u *p;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 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
511 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 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
513 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
514 if (p == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 semsg(_(e_invargval), "tty_type");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 return FAIL;
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 // 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
520 if (!(*p == NUL || STRCMP(p, "winpty") == 0
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 || STRCMP(p, "conpty") == 0))
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 semsg(_(e_invargval), "tty_type");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 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
527 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 # 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
529 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
530 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 int n = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 listitem_T *li;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 long_u rgb[16];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 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
536 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (item == NULL || item->v_type != VAR_LIST
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 || item->vval.v_list == NULL)
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 semsg(_(e_invargval), "ansi_colors");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 return FAIL;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 CHECK_LIST_MATERIALIZE(item->vval.v_list);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 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
547 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
548 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 char_u *color_name;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 guicolor_T guicolor;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 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
552
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 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
554 if (color_name == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 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
558 if (guicolor == INVALCOLOR)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 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
561 // may not get the error if the GUI didn't start
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 semsg(_(e_alloc_color), color_name);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 }
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 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
567 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 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
570 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 semsg(_(e_invargval), "ansi_colors");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 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
576 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
577 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 # endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 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
580 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 char_u *p;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 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
584 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 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
586 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
587 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
588 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 semsg(_(e_invargval), "term_highlight");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 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
593 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 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
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_API))
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_API;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 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
600 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
601 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
602 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 semsg(_(e_invargval), "term_api");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
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 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 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
609 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 if (!(supported2 & JO2_ENV))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 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
613 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 semsg(_(e_invargval), "env");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 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
618 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
619 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
620 ++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
621 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 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
623 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 if (!(supported2 & JO2_CWD))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 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
627 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
628 #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
629 || 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
630 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 )
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 semsg(_(e_invargval), "cwd");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 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
637 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 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
639 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 if (!(supported & JO_WAITTIME))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 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
643 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
644 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 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
646 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 if (!(supported & JO_TIMEOUT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 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
650 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
651 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 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
653 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 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
655 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 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
657 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
658 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 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
660 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 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
662 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 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
664 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
665 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 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
667 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 if (!(supported & JO_PART))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 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
671 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
672 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
673 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
674 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
675 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
676 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 semsg(_(e_invargNval), "part", val);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 return FAIL;
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 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
683 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 if (!(supported & JO_ID))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 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
687 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
688 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 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
690 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 if (!(supported & JO_STOPONEXIT))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 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
694 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
695 opt->jo_stoponexit_buf);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 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
697 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 semsg(_(e_invargval), "stoponexit");
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
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, "block_write") == 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_BLOCK_WRITE))
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_BLOCK_WRITE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 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
708 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 --todo;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 if (todo > 0)
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 semsg(_(e_invarg2), hi->hi_key);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 }
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 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
723
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 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
726 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 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
730 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
731 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 // 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
733 // 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
734 // 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
735 // 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
736 // 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
737 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
738 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
739 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 mch_clear_job(job);
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 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
743 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
744 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
745 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 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
747 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 #ifdef MSWIN
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 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
750 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 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
752 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
753 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 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
755 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
756 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
757 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 * 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
762 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 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
765 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 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
767 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
768 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
769 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
770 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 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
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 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 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
776 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 job_unlink(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 vim_free(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 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
783 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 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
785 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 job_free_job(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 }
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 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
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 * 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
795 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 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
798 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 job_unlink(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 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
801 jobs_to_free = job;
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 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
806 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 job_T *job;
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 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
810 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 job = jobs_to_free;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 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
813 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 vim_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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 #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
819 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 job_free_all(void)
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 (first_job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 job_free(first_job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 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
825
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 # ifdef FEAT_TERMINAL
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 free_unused_terminals();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 # endif
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 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 * 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
834 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 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
837 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 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
839 && (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
840 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841
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 * 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
844 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 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
847 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 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
849 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 * 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
853 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 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
856 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 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
858 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859
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 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
862 * 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
863 * 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
864 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 static int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 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
867 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 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
869 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 #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
872 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 * 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
874 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 job_any_running()
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 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 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
882 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 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
884 return TRUE;
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 FALSE;
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 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 #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
891 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 * 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
893 * 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
894 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 static char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 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
897 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 int slen, dlen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 int escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 char_u *s, *d;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 char_u *escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 int has_spaces = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 // 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
906 slen = (int)STRLEN(arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 dlen = slen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 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
909 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 if (*s == '"' || *s == '\\')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 ++dlen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 if (*s == ' ' || *s == '\t')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 has_spaces = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 }
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 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 dlen += 2;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 if (dlen == slen)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 return vim_strsave(arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 // 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
923 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
924 if (escaped_arg == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 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
927
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 d = escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 *d++ = '"';
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 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
934 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 switch (*s)
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 case '"':
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 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
939 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 *d++ = *s++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 case '\\':
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 escaping++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 *d++ = *s++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 default:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 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
951 break;
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 }
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 // 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
956 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 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
959 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 *d++ = '"';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 *d = NUL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 return escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 * 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
969 * 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
970 * 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
971 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 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
974 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 listitem_T *li;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 char_u *s;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 CHECK_LIST_MATERIALIZE(l);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 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
980 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 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
982 if (s == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 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
985 if (s == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 ga_concat(gap, s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 vim_free(s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 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
990 ga_append(gap, ' ');
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 #endif
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 * 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
998 * 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
999 * 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
1000 * 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
1001 * deleted a bit later.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 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
1005 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 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
1007 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 // 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
1010 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
1011
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 // 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
1013 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
1014 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
1015
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 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
1017 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 typval_T argv[3];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 typval_T rettv;
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 // 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
1022 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
1023 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
1024 ++job->jv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 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
1026 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
1027 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
1028 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
1029 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
1030 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 --job->jv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 channel_need_redraw = TRUE;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 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
1036 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
1037
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 // 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
1039 // 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
1040 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
1041 // 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
1042 // 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
1043 // 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
1044 job_free_later(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 * 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
1049 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 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
1052 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 int abort = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 typval_T tv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 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
1058 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
1059 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 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
1061 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
1062 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
1063 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 return abort;
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
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 * 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
1069 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 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
1072 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 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
1074 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 // 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
1076 // 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
1077 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
1078 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 // 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
1080 // "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
1081 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
1082 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 job_free(job);
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 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
1086 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 // 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
1088 // 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
1089 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
1090 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
1091 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
1092 job->jv_channel = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 }
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 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
1100 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 int did_free = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 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
1106 && !job_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 // 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
1109 // 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
1110 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 did_free = TRUE;
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 return did_free;
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 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
1118 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 job_T *job_next;
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 (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
1123 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125 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
1126 && !job_still_useful(job))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 // 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
1129 job_free_job(job);
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 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 * 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
1136 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 job_alloc(void)
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 job_T *job;
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 = 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
1143 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 job->jv_refcount = 1;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 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
1147
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 if (first_job != NULL)
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 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
1151 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
1152 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 first_job = job;
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 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 }
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 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
1160 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 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
1162 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 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
1164 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
1165 job->jv_stoponexit = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 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
1168 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 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
1170 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 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
1172 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
1173 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 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
1175 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
1176 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 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
1179 }
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 * 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
1184 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 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
1187 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 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
1192 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
1193 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 * 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
1197 * 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
1198 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 has_pending_job(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 // 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
1206 // 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
1207 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
1208 || (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
1209 && 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
1210 return TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 return FALSE;
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 #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
1215
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 * 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
1218 * 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
1219 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 job_check_ended(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 int did_end = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 // 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
1227 if (first_job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 return did_end;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 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
1231 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 // 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
1233 // 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
1234 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
1235
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 did_end = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 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
1240 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 // 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
1243 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
1244
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 if (channel_need_redraw)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 channel_need_redraw = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 redraw_after_callback(TRUE);
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 return did_end;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252
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 * 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
1255 * "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
1256 * 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
1257 * 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
1258 * 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
1259 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 job_start(
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 typval_T *argvars,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 char **argv_arg UNUSED,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 jobopt_T *opt_arg,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 job_T **term_job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 char_u *cmd = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 char **argv = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 int argc = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 #if defined(UNIX)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 # define USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 garray_T ga;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 jobopt_T opt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 ch_part_T part;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 job = job_alloc();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 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
1285 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 ga_init2(&ga, (int)sizeof(char*), 20);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 if (opt_arg != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 opt = *opt_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 // Default mode is NL.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 clear_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 opt.jo_mode = MODE_NL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 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
1297 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
1298 + 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
1299 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
1300 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 // 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
1304 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
1305 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
1306 && 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
1307 && (!(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
1308 || *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
1309 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 emsg(_("E920: _io file requires _name to be set"));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 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
1315 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 buf_T *buf = NULL;
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 // 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
1319 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
1320 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 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
1322 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 semsg(_(e_nobufnr), (long)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
1324 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 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
1326 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 emsg(_("E915: in_io buffer requires in_buf or in_name to be set"));
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 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 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
1331 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 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
1334 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 char_u numbuf[NUMBUFLEN];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 char_u *s;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 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
1339 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 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
1341 s = numbuf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 s = opt.jo_io_name[PART_IN];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 semsg(_("E918: buffer must be loaded: %s"), s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 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
1349 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 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
1352
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 #ifdef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 if (argv_arg != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 // 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
1357 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
1358 argc++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 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
1360 if (argv == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 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
1363 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
1364 argv[argc] = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 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
1369 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 // Command is a string.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 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
1372 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
1373 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 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
1379 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 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
1382 || 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
1383 || 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
1384 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 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
1391
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 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
1393 goto theend;
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 // Empty command is invalid.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 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
1397 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 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
1403 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 cmd = ga.ga_data;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 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
1406 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 #endif
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 // 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
1414 job->jv_argv = argv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 if (term_job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 *term_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 #ifdef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 if (ch_log_active())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 garray_T ga;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 ga_init2(&ga, (int)sizeof(char), 200);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 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
1426 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 if (i > 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 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
1429 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
1430 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 ga_append(&ga, NUL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 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
1433 ga_clear(&ga);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 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
1436 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 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
1438 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
1439 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 // 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
1442 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
1443 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
1444
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 theend:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 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
1448 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 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
1450 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 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
1452 vim_free(argv[i]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 vim_free(argv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 free_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 return job;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 * 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
1461 * 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
1462 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 char *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 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
1465 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 char *result;
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 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
1469 // 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
1470 result = "dead";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 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
1472 result = "fail";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 else
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 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
1476 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
1477 job_cleanup(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 return result;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481
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 * 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
1484 * 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
1485 * 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
1486 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 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
1489 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 char_u *arg;
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 if (type != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 arg = (char_u *)type;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 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
1495 arg = (char_u *)"";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 else
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 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
1499 if (arg == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 return 0;
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 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
1506 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 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
1508 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 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
1511 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 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
1513 return 0;
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 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
1516 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
1517 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 // 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
1520 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
1521 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
1522
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 // 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
1524 // reference to it.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 return 1;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 invoke_prompt_callback(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 typval_T argv[2];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 char_u *prompt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 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
1536
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 // 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
1538 // 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
1539 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
1540 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
1541 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
1542
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 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
1544 || *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
1545 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 text = ml_get(lnum);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 prompt = prompt_text();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 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
1549 text += STRLEN(prompt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 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
1551 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
1552 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
1553
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 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
1555 clear_tv(&argv[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558
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 * 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
1561 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 invoke_prompt_interrupt(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 typval_T argv[1];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 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
1569 || *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
1570 return FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 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
1572
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 got_int = FALSE; // don't skip executing commands
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 call_callback(&curbuf->b_prompt_interrupt, -1, &rettv, 0, argv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 return TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 * 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
1581 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 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
1584 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 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
1586 return (char_u *)"% ";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 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
1588 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589
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 * 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
1592 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 prompt_text(void)
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 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
1597 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 * 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
1602 * 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
1603 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 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
1606 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 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
1608 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 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
1611 text = ml_get_curline();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 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
1613 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 // 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
1615 if (*text == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 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
1617 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 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
1619 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
1620 coladvance((colnr_T)MAXCOL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 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
1622 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 // 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
1625 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
1626 || 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
1627 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
1628
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 if (cmdchar_todo == 'A')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 coladvance((colnr_T)MAXCOL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 if (cmdchar_todo == 'I' || 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
1632 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
1633 // 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
1634 check_cursor();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 * 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
1639 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 prompt_curpos_editable()
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 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
1644 && 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
1645 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 * "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
1649 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 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
1652 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 callback_T callback;
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 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 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
1659 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 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
1663 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
1664 return;
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 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
1667 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
1668 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669
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 * "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
1672 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 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
1675 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 callback_T callback;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 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
1682 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 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
1686 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
1687 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 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
1690 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
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
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 * "prompt_getprompt({buffer})" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 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
1699 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 // 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
1703 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
1704 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
1705
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 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
1707 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 if (!bt_prompt(buf))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 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
1714 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 * "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
1718 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 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
1721 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 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
1728 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 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
1732 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
1733 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
1734 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 * 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
1738 * 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
1739 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 static job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 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
1742 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 job_T *job;
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 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
1746 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 semsg(_(e_invarg2), tv_get_string(tv));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 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
1751
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 emsg(_("E916: not a valid job"));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 * "job_getchannel()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 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
1762 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 job_T *job = get_job_arg(&argvars[0]);
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 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 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
1768 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
1769 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
1770 ++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
1771 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 * Implementation of job_info().
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 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 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
1779 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 dictitem_T *item;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 varnumber_T nr;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 list_T *l;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 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
1786
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 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
1788 if (item == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 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
1791 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
1792 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
1793 ++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
1794 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
1795 dictitem_free(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 nr = job->jv_pid;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 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
1801 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 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
1803 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
1804 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
1805
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 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
1807 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
1808 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
1809 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 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
1811 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 #ifdef MSWIN
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 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
1814 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 l = list_alloc();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 if (l != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 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
1820 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
1821 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
1822 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
1823 }
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 * 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
1828 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 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
1831 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 typval_T tv;
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 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 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
1838 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
1839
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 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
1841 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 }
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 * "job_info()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 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
1850 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 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
1852 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 job_T *job = get_job_arg(&argvars[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 if (job != NULL && rettv_dict_alloc(rettv) != FAIL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 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
1857 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 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
1859 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
1860 }
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 * "job_setoptions()" function
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 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
1867 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 job_T *job = get_job_arg(&argvars[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 jobopt_T opt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 clear_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 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
1875 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
1876 free_job_options(&opt);
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 * "job_start()" function
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 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
1884 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 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
1886 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
1887 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 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
1889 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 * "job_status()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 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
1896 {
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
1897 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
1898 {
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
1899 // 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
1900 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
1901 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
1902 }
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
1903 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
1904 {
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
1905 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
1906
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
1907 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
1908 {
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
1909 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
1910 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
1911 }
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 * "job_stop()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 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
1920 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 job_T *job = get_job_arg(&argvars[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 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
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 #endif // FEAT_JOB_CHANNEL