annotate src/job.c @ 26057:92c424550367 v8.2.3562

patch 8.2.3562: cannot add color names Commit: https://github.com/vim/vim/commit/e30d10253fa634c4f60daa798d029245f4eed393 Author: Drew Vogel <dvogel@github> Date: Sun Oct 24 20:35:07 2021 +0100 patch 8.2.3562: cannot add color names Problem: Cannot add color names. Solution: Add the v:colornames dictionary. (Drew Vogel, closes https://github.com/vim/vim/issues/8761)
author Bram Moolenaar <Bram@vim.org>
date Sun, 24 Oct 2021 21:45:04 +0200
parents 838a0108a92d
children fd1cbe72815a
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
26057
92c424550367 patch 8.2.3562: cannot add color names
Bram Moolenaar <Bram@vim.org>
parents: 25686
diff changeset
562 semsg(_(e_cannot_allocate_color_str), color_name);
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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
23144
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
890 // Unix uses argv[] for the command, other systems use a string.
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
891 #if defined(UNIX)
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
892 # define USE_ARGV
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
893 #endif
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
894
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 #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
896 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 * 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
898 * 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
899 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 static char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 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
902 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 int slen, dlen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 int escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 char_u *s, *d;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 char_u *escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 int has_spaces = FALSE;
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 // 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
911 slen = (int)STRLEN(arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 dlen = slen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 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
914 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 if (*s == '"' || *s == '\\')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 ++dlen;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 if (*s == ' ' || *s == '\t')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 has_spaces = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 dlen += 2;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 if (dlen == slen)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 return vim_strsave(arg);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 // 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
928 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
929 if (escaped_arg == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 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
932
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 d = escaped_arg;
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 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 *d++ = '"';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 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
939 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 switch (*s)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 case '"':
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 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
944 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 *d++ = *s++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 case '\\':
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 escaping++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 *d++ = *s++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 default:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 escaping = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 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
956 break;
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 // 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
961 if (has_spaces)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 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
964 *d++ = '\\';
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 *d++ = '"';
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 *d = NUL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 return escaped_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 * 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
974 * 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
975 * 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
976 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 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
979 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 listitem_T *li;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 char_u *s;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 CHECK_LIST_MATERIALIZE(l);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 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
985 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 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
987 if (s == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 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
990 if (s == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 return FAIL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 ga_concat(gap, s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 vim_free(s);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 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
995 ga_append(gap, ' ');
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 return OK;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 * 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
1003 * 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
1004 * 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
1005 * 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
1006 * deleted a bit later.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 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
1010 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 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
1012 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 // 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
1015 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
1016
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 // 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
1018 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
1019 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
1020
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 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
1022 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 typval_T argv[3];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 // 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
1027 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
1028 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
1029 ++job->jv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 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
1031 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
1032 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
1033 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
1034 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
1035 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 --job->jv_refcount;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 channel_need_redraw = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 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
1041 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
1042
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 // 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
1044 // 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
1045 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
1046 // 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
1047 // 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
1048 // 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
1049 job_free_later(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 * 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
1054 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 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
1057 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 int abort = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 typval_T tv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 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
1063 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
1064 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 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
1066 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
1067 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
1068 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 return abort;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071
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 * 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
1074 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 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
1077 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 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
1079 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 // 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
1081 // 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
1082 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
1083 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 // 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
1085 // "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
1086 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
1087 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 job_free(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 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
1091 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 // 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
1093 // 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
1094 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
1095 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
1096 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
1097 job->jv_channel = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 }
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 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
1105 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 int did_free = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111 && !job_still_useful(job))
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 // 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
1114 // 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
1115 job_free_contents(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 did_free = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 return did_free;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 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
1123 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 job_T *job_next;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 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
1128 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 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
1130 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
1131 && !job_still_useful(job))
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 // 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
1134 job_free_job(job);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 }
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138
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 * 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
1141 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 job_alloc(void)
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_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 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
1148 if (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 job->jv_refcount = 1;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 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
1152
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 if (first_job != NULL)
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 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
1156 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
1157 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 first_job = job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 }
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 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
1165 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 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
1167 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 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
1169 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
1170 job->jv_stoponexit = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 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
1173 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 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
1175 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 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
1178 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 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
1180 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
1181 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 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
1184 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 * 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
1189 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 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
1192 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 job_T *job;
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 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 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
1197 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
1198 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 * 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
1202 * 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
1203 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 has_pending_job(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 // 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
1211 // 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
1212 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
1213 || (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
1214 && 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
1215 return TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 return FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 #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
1220
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 * 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
1223 * 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
1224 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 job_check_ended(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 int did_end = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 // 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
1232 if (first_job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 return did_end;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 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
1236 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 // 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
1238 // 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
1239 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
1240
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 break;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 did_end = TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 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
1245 }
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 // 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
1248 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
1249
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 if (channel_need_redraw)
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 channel_need_redraw = FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 redraw_after_callback(TRUE);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 return did_end;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 * 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
1260 * "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
1261 * 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
1262 * 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
1263 * 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
1264 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 job_start(
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 typval_T *argvars,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 char **argv_arg UNUSED,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 jobopt_T *opt_arg,
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 job_T **term_job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 char_u *cmd = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 char **argv = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 int argc = 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 int i;
23144
de5c000f14c4 patch 8.2.2118: dead code in the job support
Bram Moolenaar <Bram@vim.org>
parents: 22934
diff changeset
1277 #ifndef USE_ARGV
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 garray_T ga;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 jobopt_T opt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 ch_part_T part;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 job = job_alloc();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 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
1288 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 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
1290 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 if (opt_arg != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 opt = *opt_arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 // Default mode is NL.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 clear_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 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
1299 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
1300 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
1301 + 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
1302 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
1303 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 // 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
1307 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
1308 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
1309 && 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
1310 && (!(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
1311 || *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
1312 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 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
1314 goto theend;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 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
1318 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 buf_T *buf = NULL;
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 // 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
1322 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
1323 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 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
1325 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 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
1327 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 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
1329 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 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
1331 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 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
1334 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 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
1337 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 char_u numbuf[NUMBUFLEN];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 char_u *s;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 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
1342 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 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
1344 s = numbuf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 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
1348 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
1349 goto theend;
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->jv_in_buf = buf;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 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
1355
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 #ifdef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 if (argv_arg != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 // 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
1360 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
1361 argc++;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 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
1363 if (argv == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 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
1366 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
1367 argv[argc] = NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 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
1372 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 // Command is a string.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 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
1375 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
1376 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 }
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 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
1382 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 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
1385 || 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
1386 || 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
1387 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 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
1394
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 if (build_argv_from_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
1396 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 // Empty command is invalid.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 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
1400 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 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
1406 goto theend;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 cmd = ga.ga_data;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 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
1409 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 goto theend;
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 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 }
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 // 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
1417 job->jv_argv = argv;
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 if (term_job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 *term_job = job;
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 #ifdef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 if (ch_log_active())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 garray_T ga;
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 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
1428 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
1429 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 if (i > 0)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 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
1432 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
1433 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 ga_append(&ga, NUL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 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
1436 ga_clear(&ga);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 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
1439 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 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
1441 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
1442 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 // If 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
1445 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
1446 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
1447
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 theend:
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 #ifndef USE_ARGV
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 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
1451 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 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
1453 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 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
1455 vim_free(argv[i]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 vim_free(argv);
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 free_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 return job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 * 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
1464 * 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
1465 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 char *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 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
1468 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 char *result;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 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
1472 // 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
1473 result = "dead";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 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
1475 result = "fail";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 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
1479 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
1480 job_cleanup(job);
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 return result;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 * 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
1487 * 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
1488 * 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
1489 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 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
1492 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 char_u *arg;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 if (type != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 arg = (char_u *)type;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 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
1498 arg = (char_u *)"";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 else
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 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
1502 if (arg == NULL)
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 emsg(_(e_invarg));
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 return 0;
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 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
1509 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 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
1511 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 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
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, "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
1516 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 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
1519 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
1520 return 0;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 // 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
1523 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
1524 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
1525
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 // 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
1527 // reference to it.
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 return 1;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 }
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 invoke_prompt_callback(void)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 typval_T argv[2];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 char_u *prompt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 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
1539
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 // 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
1541 // 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
1542 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
1543 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
1544 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
1545
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 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
1547 || *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
1548 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 text = ml_get(lnum);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 prompt = prompt_text();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 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
1552 text += STRLEN(prompt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 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
1554 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
1555 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
1556
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 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
1558 clear_tv(&argv[0]);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 * 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
1564 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 invoke_prompt_interrupt(void)
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 typval_T rettv;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 typval_T argv[1];
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 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
1572 || *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
1573 return FALSE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 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
1575
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 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
1577 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
1578 clear_tv(&rettv);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 return TRUE;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 * 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
1584 */
25567
0082503ff2ff patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1585 static char_u *
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 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
1587 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 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
1589 return (char_u *)"% ";
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 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
1591 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 * 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
1595 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 char_u *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 prompt_text(void)
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 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
1600 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 * 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
1605 * 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
1606 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 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
1609 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 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
1611 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 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
1614 text = ml_get_curline();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 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
1616 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 // 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
1618 if (*text == NUL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 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
1620 else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 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
1622 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
1623 coladvance((colnr_T)MAXCOL);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 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
1625 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 // 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
1628 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
1629 || 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
1630 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
1631
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 if (cmdchar_todo == 'A')
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 coladvance((colnr_T)MAXCOL);
22934
3f04c2cf0ced patch 8.2.2014: using CTRL-O in a prompt buffer moves cursor to start
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
1634 if (curwin->w_cursor.col < (int)STRLEN(prompt))
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 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
1636 // 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
1637 check_cursor();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 * 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
1642 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 int
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 prompt_curpos_editable()
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 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
1647 && 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
1648 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 * "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
1652 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 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
1655 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 callback_T callback;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 return;
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1661
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1662 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1663 return;
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1664
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 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
1666 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 return;
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 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
1670 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
1671 return;
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 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
1674 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
1675 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 * "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
1679 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 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
1682 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 callback_T callback;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 return;
25348
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1688
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1689 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1690 return;
75031a22be39 patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1691
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 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
1693 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 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
1697 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
1698 return;
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 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
1701 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
1702 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704
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 * "prompt_getprompt({buffer})" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 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
1710 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 buf_T *buf;
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 // 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
1714 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
1715 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
1716
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1717 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1718 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1719
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 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
1721 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 if (!bt_prompt(buf))
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 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
1728 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729
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 * "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
1732 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 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
1735 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 buf_T *buf;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 char_u *text;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1739 if (in_vim9script()
25314
7e620652bd13 patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
1740 && (check_for_buffer_arg(argvars, 0) == FAIL
25272
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1741 || check_for_string_arg(argvars, 1) == FAIL))
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1742 return;
712e867f9721 patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24812
diff changeset
1743
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 if (check_secure())
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 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
1747 if (buf == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 return;
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 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
1751 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
1752 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
1753 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754
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 * 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
1757 * 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
1758 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 static job_T *
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 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
1761 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 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
1765 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 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
1767 return NULL;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 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
1770
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 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
1773 return job;
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 * "job_getchannel()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 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
1781 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1782 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1784 if (in_vim9script() && check_for_job_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1785 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1786
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1787 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
1788 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 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
1791 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
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 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 }
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 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 * Implementation of job_info().
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 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
1802 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 dictitem_T *item;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 varnumber_T nr;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 list_T *l;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 int i;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807
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, "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
1809
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 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
1811 if (item == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 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
1814 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
1815 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
1816 ++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
1817 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
1818 dictitem_free(item);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 nr = job->jv_pid;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 #else
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 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
1824 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 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
1826 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
1827 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
1828
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 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
1830 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
1831 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
1832 #ifdef UNIX
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 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
1834 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 #ifdef MSWIN
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 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
1837 #endif
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 l = list_alloc();
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 if (l != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 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
1843 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
1844 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
1845 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
1846 }
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
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 * 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
1851 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 static void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 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
1854 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 job_T *job;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 typval_T tv;
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 FOR_ALL_JOBS(job)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 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
1861 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
1862
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 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
1864 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 * "job_info()" function
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 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
1873 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1874 if (in_vim9script() && check_for_opt_job_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1875 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1876
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 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
1878 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1879 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1881 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
1882 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
1883 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
1884 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 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
1886 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
1887 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888
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 * "job_setoptions()" function
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 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
1894 {
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1895 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 jobopt_T opt;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1898 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1899 && (check_for_job_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1900 || check_for_dict_arg(argvars, 1) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1901 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1902
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1903 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
1904 if (job == NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 return;
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 clear_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 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
1908 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
1909 free_job_options(&opt);
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911
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 * "job_start()" function
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 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 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
1917 {
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 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
1919 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
1920 return;
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1921
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1922 if (in_vim9script()
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1923 && (check_for_string_or_list_arg(argvars, 0) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1924 || check_for_opt_dict_arg(argvars, 1) == FAIL))
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1925 return;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25314
diff changeset
1926
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 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
1928 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 * "job_status()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 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
1935 {
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1936 if (in_vim9script() && check_for_job_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1937 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25348
diff changeset
1938
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
1939 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
1940 {
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
1941 // 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
1942 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
1943 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
1944 }
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
1945 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
1946 {
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
1947 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
1948
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
1949 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
1950 {
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
1951 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
1952 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
1953 }
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 /*
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 * "job_stop()" function
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 */
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 void
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 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
1962 {
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1963 job_T *job;
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1965 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1966 && (check_for_job_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1967 || check_for_opt_string_or_number_arg(argvars, 1) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1968 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1969
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25272
diff changeset
1970 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
1971 if (job != NULL)
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 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
1973 }
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1975 /*
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1976 * Get a string with information about the job in "varp" in "buf".
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1977 * "buf" must be at least NUMBUFLEN long.
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1978 */
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1979 char_u *
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1980 job_to_string_buf(typval_T *varp, char_u *buf)
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1981 {
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1982 job_T *job = varp->vval.v_job;
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1983 char *status;
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1984
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1985 if (job == NULL)
25686
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
1986 {
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
1987 vim_snprintf((char *)buf, NUMBUFLEN, "no process");
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
1988 return buf;
838a0108a92d patch 8.2.3379: crash when using NULL job
Bram Moolenaar <Bram@vim.org>
parents: 25567
diff changeset
1989 }
24812
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1990 status = job->jv_status == JOB_FAILED ? "fail"
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1991 : job->jv_status >= JOB_ENDED ? "dead"
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1992 : "run";
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1993 # ifdef UNIX
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1994 vim_snprintf((char *)buf, NUMBUFLEN,
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1995 "process %ld %s", (long)job->jv_pid, status);
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1996 # elif defined(MSWIN)
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1997 vim_snprintf((char *)buf, NUMBUFLEN,
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1998 "process %ld %s",
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
1999 (long)job->jv_proc_info.dwProcessId,
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2000 status);
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2001 # else
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2002 // fall-back
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2003 vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status);
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2004 # endif
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2005 return buf;
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2006 }
8fdf839af1f4 patch 8.2.2944: Vim9: no error when using job or channel as a string
Bram Moolenaar <Bram@vim.org>
parents: 23144
diff changeset
2007
22095
2cc0de1e05a6 patch 8.2.1597: the channel source file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 #endif // FEAT_JOB_CHANNEL