diff options
-rw-r--r-- | Filelist | 2 | ||||
-rw-r--r-- | src/Make_cyg_ming.mak | 2 | ||||
-rw-r--r-- | src/Make_mvc.mak | 12 | ||||
-rw-r--r-- | src/Makefile | 10 | ||||
-rwxr-xr-x | src/auto/configure | 4 | ||||
-rw-r--r-- | src/channel.c | 1845 | ||||
-rw-r--r-- | src/configure.ac | 4 | ||||
-rw-r--r-- | src/edit.c | 84 | ||||
-rw-r--r-- | src/globals.h | 3 | ||||
-rw-r--r-- | src/job.c | 1918 | ||||
-rw-r--r-- | src/proto.h | 1 | ||||
-rw-r--r-- | src/proto/channel.pro | 34 | ||||
-rw-r--r-- | src/proto/edit.pro | 4 | ||||
-rw-r--r-- | src/proto/job.pro | 37 | ||||
-rw-r--r-- | src/version.c | 2 |
15 files changed, 2002 insertions, 1960 deletions
@@ -75,6 +75,7 @@ SRC_ALL = \ src/highlight.c \ src/indent.c \ src/insexpand.c \ + src/job.c \ src/json.c \ src/json_test.c \ src/kword_test.c \ @@ -250,6 +251,7 @@ SRC_ALL = \ src/proto/highlight.pro \ src/proto/indent.pro \ src/proto/insexpand.pro \ + src/proto/job.pro \ src/proto/json.pro \ src/proto/list.pro \ src/proto/locale.pro \ diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index 5fc08331da..75021cc374 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -870,7 +870,7 @@ OBJ += $(OUTDIR)/netbeans.o endif ifeq ($(CHANNEL),yes) -OBJ += $(OUTDIR)/channel.o +OBJ += $(OUTDIR)/job.o $(OUTDIR)/channel.o LIB += -lwsock32 -lws2_32 endif diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index 8e539562d8..705aaf6cef 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -471,8 +471,8 @@ SOUND_LIB = winmm.lib !endif !if "$(CHANNEL)" == "yes" -CHANNEL_PRO = proto/channel.pro -CHANNEL_OBJ = $(OBJDIR)/channel.obj +CHANNEL_PRO = proto/job.pro proto/channel.pro +CHANNEL_OBJ = $(OBJDIR)/job.obj $(OBJDIR)/channel.obj CHANNEL_DEFS = -DFEAT_JOB_CHANNEL -DFEAT_IPV6 ! if $(WINVER) >= 0x600 CHANNEL_DEFS = $(CHANNEL_DEFS) -DHAVE_INET_NTOP @@ -1673,6 +1673,8 @@ $(OUTDIR)/if_tcl.obj: $(OUTDIR) if_tcl.c $(INCL) $(OUTDIR)/iscygpty.obj: $(OUTDIR) iscygpty.c $(CUI_INCL) $(CC) $(CFLAGS_OUTDIR) iscygpty.c -D_WIN32_WINNT=0x0600 -DUSE_DYNFILEID -DENABLE_STUB_IMPL +$(OUTDIR)/job.obj: $(OUTDIR) job.c $(INCL) + $(OUTDIR)/json.obj: $(OUTDIR) json.c $(INCL) $(OUTDIR)/list.obj: $(OUTDIR) list.c $(INCL) @@ -1703,11 +1705,11 @@ $(OUTDIR)/mouse.obj: $(OUTDIR) mouse.c $(INCL) $(OUTDIR)/move.obj: $(OUTDIR) move.c $(INCL) -$(OUTDIR)/mbyte.obj: $(OUTDIR) mbyte.c $(INCL) +$(OUTDIR)/mbyte.obj: $(OUTDIR) mbyte.c $(INCL) -$(OUTDIR)/netbeans.obj: $(OUTDIR) netbeans.c $(NBDEBUG_SRC) $(INCL) version.h +$(OUTDIR)/netbeans.obj: $(OUTDIR) netbeans.c $(NBDEBUG_SRC) $(INCL) version.h -$(OUTDIR)/channel.obj: $(OUTDIR) channel.c $(INCL) +$(OUTDIR)/channel.obj: $(OUTDIR) channel.c $(INCL) $(OUTDIR)/normal.obj: $(OUTDIR) normal.c $(INCL) diff --git a/src/Makefile b/src/Makefile index 4d1439a5f2..05c32a2a52 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1708,7 +1708,7 @@ SRC = $(BASIC_SRC) \ EXTRA_SRC = if_lua.c if_mzsch.c auto/if_perl.c if_perlsfio.c \ if_python.c if_python3.c if_tcl.c if_ruby.c \ - gui_beval.c netbeans.c channel.c \ + gui_beval.c netbeans.c job.c channel.c \ $(GRESOURCE_SRC) # Unittest files @@ -1962,6 +1962,7 @@ PRO_AUTO = \ if_xcmdsrv.pro \ indent.pro \ insexpand.pro \ + job.pro \ json.pro \ list.pro \ locale.pro \ @@ -3352,6 +3353,9 @@ objects/indent.o: indent.c objects/insexpand.o: insexpand.c $(CCC) -o $@ insexpand.c +objects/job.o: job.c + $(CCC) -o $@ job.c + objects/json.o: json.c $(CCC) -o $@ json.c @@ -4200,6 +4204,10 @@ objects/gui_at_fs.o: gui_at_fs.c vim.h protodef.h auto/config.h feature.h \ os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h errors.h globals.h gui_at_sb.h +objects/job.o: job.c vim.h protodef.h auto/config.h feature.h os_unix.h \ + auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h errors.h globals.h objects/json_test.o: json_test.c main.c vim.h protodef.h auto/config.h feature.h \ os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ diff --git a/src/auto/configure b/src/auto/configure index e66162fd63..37a60fad2b 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -8006,9 +8006,9 @@ fi if test "$enable_channel" = "yes"; then $as_echo "#define FEAT_JOB_CHANNEL 1" >>confdefs.h - CHANNEL_SRC="channel.c" + CHANNEL_SRC="job.c channel.c" - CHANNEL_OBJ="objects/channel.o" + CHANNEL_OBJ="objects/job.o objects/channel.o" fi diff --git a/src/channel.c b/src/channel.c index 5bf561e220..2959139f56 100644 --- a/src/channel.c +++ b/src/channel.c @@ -66,17 +66,10 @@ static ch_mode_T channel_get_mode(channel_T *channel, ch_part_T part); static int channel_get_timeout(channel_T *channel, ch_part_T part); static ch_part_T channel_part_send(channel_T *channel); static ch_part_T channel_part_read(channel_T *channel); -static void free_job_options(jobopt_T *opt); #define FOR_ALL_CHANNELS(ch) \ for ((ch) = first_channel; (ch) != NULL; (ch) = (ch)->ch_next) -#define FOR_ALL_JOBS(job) \ - for ((job) = first_job; (job) != NULL; (job) = (job)->jv_next) - -// Whether a redraw is needed for appending a line to a buffer. -static int channel_need_redraw = FALSE; - // Whether we are inside channel_parse_messages() or another situation where it // is safe to invoke callbacks. static int safe_to_invoke_callback = 0; @@ -361,7 +354,7 @@ has_any_channel(void) * Return TRUE if "channel" has a callback and the associated job wasn't * killed. */ - static int + int channel_still_useful(channel_T *channel) { int has_sock_msg; @@ -404,7 +397,7 @@ channel_still_useful(channel_T *channel) /* * Return TRUE if "channel" is closeable (i.e. all readable fds are closed). */ - static int + int channel_can_close(channel_T *channel) { return channel->ch_to_be_closed == 0; @@ -1386,7 +1379,7 @@ theend: return channel; } - static void + void ch_close_part(channel_T *channel, ch_part_T part) { sock_T *fd = &channel->ch_part[part].ch_fd; @@ -1625,7 +1618,7 @@ can_write_buf_line(channel_T *channel) /* * Write any buffer lines to the input channel. */ - static void + void channel_write_in(channel_T *channel) { chanpart_T *in_part = &channel->ch_part[PART_IN]; @@ -4763,1654 +4756,6 @@ channel_get_timeout(channel_T *channel, ch_part_T part) return channel->ch_part[part].ch_timeout; } - static int -handle_mode(typval_T *item, jobopt_T *opt, ch_mode_T *modep, int jo) -{ - char_u *val = tv_get_string(item); - - opt->jo_set |= jo; - if (STRCMP(val, "nl") == 0) - *modep = MODE_NL; - else if (STRCMP(val, "raw") == 0) - *modep = MODE_RAW; - else if (STRCMP(val, "js") == 0) - *modep = MODE_JS; - else if (STRCMP(val, "json") == 0) - *modep = MODE_JSON; - else - { - semsg(_(e_invarg2), val); - return FAIL; - } - return OK; -} - - static int -handle_io(typval_T *item, ch_part_T part, jobopt_T *opt) -{ - char_u *val = tv_get_string(item); - - opt->jo_set |= JO_OUT_IO << (part - PART_OUT); - if (STRCMP(val, "null") == 0) - opt->jo_io[part] = JIO_NULL; - else if (STRCMP(val, "pipe") == 0) - opt->jo_io[part] = JIO_PIPE; - else if (STRCMP(val, "file") == 0) - opt->jo_io[part] = JIO_FILE; - else if (STRCMP(val, "buffer") == 0) - opt->jo_io[part] = JIO_BUFFER; - else if (STRCMP(val, "out") == 0 && part == PART_ERR) - opt->jo_io[part] = JIO_OUT; - else - { - semsg(_(e_invarg2), val); - return FAIL; - } - return OK; -} - -/* - * Clear a jobopt_T before using it. - */ - void -clear_job_options(jobopt_T *opt) -{ - CLEAR_POINTER(opt); -} - -/* - * Free any members of a jobopt_T. - */ - static void -free_job_options(jobopt_T *opt) -{ - if (opt->jo_callback.cb_partial != NULL) - partial_unref(opt->jo_callback.cb_partial); - else if (opt->jo_callback.cb_name != NULL) - func_unref(opt->jo_callback.cb_name); - if (opt->jo_out_cb.cb_partial != NULL) - partial_unref(opt->jo_out_cb.cb_partial); - else if (opt->jo_out_cb.cb_name != NULL) - func_unref(opt->jo_out_cb.cb_name); - if (opt->jo_err_cb.cb_partial != NULL) - partial_unref(opt->jo_err_cb.cb_partial); - else if (opt->jo_err_cb.cb_name != NULL) - func_unref(opt->jo_err_cb.cb_name); - if (opt->jo_close_cb.cb_partial != NULL) - partial_unref(opt->jo_close_cb.cb_partial); - else if (opt->jo_close_cb.cb_name != NULL) - func_unref(opt->jo_close_cb.cb_name); - if (opt->jo_exit_cb.cb_partial != NULL) - partial_unref(opt->jo_exit_cb.cb_partial); - else if (opt->jo_exit_cb.cb_name != NULL) - func_unref(opt->jo_exit_cb.cb_name); - if (opt->jo_env != NULL) - dict_unref(opt->jo_env); -} - -/* - * Get the PART_ number from the first character of an option name. - */ - static int -part_from_char(int c) -{ - return c == 'i' ? PART_IN : c == 'o' ? PART_OUT: PART_ERR; -} - -/* - * Get the option entries from the dict in "tv", parse them and put the result - * in "opt". - * Only accept JO_ options in "supported" and JO2_ options in "supported2". - * If an option value is invalid return FAIL. - */ - int -get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) -{ - typval_T *item; - char_u *val; - dict_T *dict; - int todo; - hashitem_T *hi; - ch_part_T part; - - if (tv->v_type == VAR_UNKNOWN) - return OK; - if (tv->v_type != VAR_DICT) - { - emsg(_(e_dictreq)); - return FAIL; - } - dict = tv->vval.v_dict; - if (dict == NULL) - return OK; - - todo = (int)dict->dv_hashtab.ht_used; - for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi) - if (!HASHITEM_EMPTY(hi)) - { - item = &dict_lookup(hi)->di_tv; - - if (STRCMP(hi->hi_key, "mode") == 0) - { - if (!(supported & JO_MODE)) - break; - if (handle_mode(item, opt, &opt->jo_mode, JO_MODE) == FAIL) - return FAIL; - } - else if (STRCMP(hi->hi_key, "in_mode") == 0) - { - if (!(supported & JO_IN_MODE)) - break; - if (handle_mode(item, opt, &opt->jo_in_mode, JO_IN_MODE) - == FAIL) - return FAIL; - } - else if (STRCMP(hi->hi_key, "out_mode") == 0) - { - if (!(supported & JO_OUT_MODE)) - break; - if (handle_mode(item, opt, &opt->jo_out_mode, JO_OUT_MODE) - == FAIL) - return FAIL; - } - else if (STRCMP(hi->hi_key, "err_mode") == 0) - { - if (!(supported & JO_ERR_MODE)) - break; - if (handle_mode(item, opt, &opt->jo_err_mode, JO_ERR_MODE) - == FAIL) - return FAIL; - } - else if (STRCMP(hi->hi_key, "noblock") == 0) - { - if (!(supported & JO_MODE)) - break; - opt->jo_noblock = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "in_io") == 0 - || STRCMP(hi->hi_key, "out_io") == 0 - || STRCMP(hi->hi_key, "err_io") == 0) - { - if (!(supported & JO_OUT_IO)) - break; - if (handle_io(item, part_from_char(*hi->hi_key), opt) == FAIL) - return FAIL; - } - else if (STRCMP(hi->hi_key, "in_name") == 0 - || STRCMP(hi->hi_key, "out_name") == 0 - || STRCMP(hi->hi_key, "err_name") == 0) - { - part = part_from_char(*hi->hi_key); - - if (!(supported & JO_OUT_IO)) - break; - opt->jo_set |= JO_OUT_NAME << (part - PART_OUT); - opt->jo_io_name[part] = tv_get_string_buf_chk(item, - opt->jo_io_name_buf[part]); - } - else if (STRCMP(hi->hi_key, "pty") == 0) - { - if (!(supported & JO_MODE)) - break; - opt->jo_pty = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "in_buf") == 0 - || STRCMP(hi->hi_key, "out_buf") == 0 - || STRCMP(hi->hi_key, "err_buf") == 0) - { - part = part_from_char(*hi->hi_key); - - if (!(supported & JO_OUT_IO)) - break; - opt->jo_set |= JO_OUT_BUF << (part - PART_OUT); - opt->jo_io_buf[part] = tv_get_number(item); - if (opt->jo_io_buf[part] <= 0) - { - semsg(_(e_invargNval), hi->hi_key, tv_get_string(item)); - return FAIL; - } - if (buflist_findnr(opt->jo_io_buf[part]) == NULL) - { - semsg(_(e_nobufnr), (long)opt->jo_io_buf[part]); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "out_modifiable") == 0 - || STRCMP(hi->hi_key, "err_modifiable") == 0) - { - part = part_from_char(*hi->hi_key); - - if (!(supported & JO_OUT_IO)) - break; - opt->jo_set |= JO_OUT_MODIFIABLE << (part - PART_OUT); - opt->jo_modifiable[part] = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "out_msg") == 0 - || STRCMP(hi->hi_key, "err_msg") == 0) - { - part = part_from_char(*hi->hi_key); - - if (!(supported & JO_OUT_IO)) - break; - opt->jo_set2 |= JO2_OUT_MSG << (part - PART_OUT); - opt->jo_message[part] = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "in_top") == 0 - || STRCMP(hi->hi_key, "in_bot") == 0) - { - linenr_T *lp; - - if (!(supported & JO_OUT_IO)) - break; - if (hi->hi_key[3] == 't') - { - lp = &opt->jo_in_top; - opt->jo_set |= JO_IN_TOP; - } - else - { - lp = &opt->jo_in_bot; - opt->jo_set |= JO_IN_BOT; - } - *lp = tv_get_number(item); - if (*lp < 0) - { - semsg(_(e_invargNval), hi->hi_key, tv_get_string(item)); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "channel") == 0) - { - if (!(supported & JO_OUT_IO)) - break; - opt->jo_set |= JO_CHANNEL; - if (item->v_type != VAR_CHANNEL) - { - semsg(_(e_invargval), "channel"); - return FAIL; - } - opt->jo_channel = item->vval.v_channel; - } - else if (STRCMP(hi->hi_key, "callback") == 0) - { - if (!(supported & JO_CALLBACK)) - break; - opt->jo_set |= JO_CALLBACK; - opt->jo_callback = get_callback(item); - if (opt->jo_callback.cb_name == NULL) - { - semsg(_(e_invargval), "callback"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "out_cb") == 0) - { - if (!(supported & JO_OUT_CALLBACK)) - break; - opt->jo_set |= JO_OUT_CALLBACK; - opt->jo_out_cb = get_callback(item); - if (opt->jo_out_cb.cb_name == NULL) - { - semsg(_(e_invargval), "out_cb"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "err_cb") == 0) - { - if (!(supported & JO_ERR_CALLBACK)) - break; - opt->jo_set |= JO_ERR_CALLBACK; - opt->jo_err_cb = get_callback(item); - if (opt->jo_err_cb.cb_name == NULL) - { - semsg(_(e_invargval), "err_cb"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "close_cb") == 0) - { - if (!(supported & JO_CLOSE_CALLBACK)) - break; - opt->jo_set |= JO_CLOSE_CALLBACK; - opt->jo_close_cb = get_callback(item); - if (opt->jo_close_cb.cb_name == NULL) - { - semsg(_(e_invargval), "close_cb"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "drop") == 0) - { - int never = FALSE; - val = tv_get_string(item); - - if (STRCMP(val, "never") == 0) - never = TRUE; - else if (STRCMP(val, "auto") != 0) - { - semsg(_(e_invargNval), "drop", val); - return FAIL; - } - opt->jo_drop_never = never; - } - else if (STRCMP(hi->hi_key, "exit_cb") == 0) - { - if (!(supported & JO_EXIT_CB)) - break; - opt->jo_set |= JO_EXIT_CB; - opt->jo_exit_cb = get_callback(item); - if (opt->jo_exit_cb.cb_name == NULL) - { - semsg(_(e_invargval), "exit_cb"); - return FAIL; - } - } -#ifdef FEAT_TERMINAL - else if (STRCMP(hi->hi_key, "term_name") == 0) - { - if (!(supported2 & JO2_TERM_NAME)) - break; - opt->jo_set2 |= JO2_TERM_NAME; - opt->jo_term_name = tv_get_string_buf_chk(item, - opt->jo_term_name_buf); - if (opt->jo_term_name == NULL) - { - semsg(_(e_invargval), "term_name"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "term_finish") == 0) - { - if (!(supported2 & JO2_TERM_FINISH)) - break; - val = tv_get_string(item); - if (STRCMP(val, "open") != 0 && STRCMP(val, "close") != 0) - { - semsg(_(e_invargNval), "term_finish", val); - return FAIL; - } - opt->jo_set2 |= JO2_TERM_FINISH; - opt->jo_term_finish = *val; - } - else if (STRCMP(hi->hi_key, "term_opencmd") == 0) - { - char_u *p; - - if (!(supported2 & JO2_TERM_OPENCMD)) - break; - opt->jo_set2 |= JO2_TERM_OPENCMD; - p = opt->jo_term_opencmd = tv_get_string_buf_chk(item, - opt->jo_term_opencmd_buf); - if (p != NULL) - { - // Must have %d and no other %. - p = vim_strchr(p, '%'); - if (p != NULL && (p[1] != 'd' - || vim_strchr(p + 2, '%') != NULL)) - p = NULL; - } - if (p == NULL) - { - semsg(_(e_invargval), "term_opencmd"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "eof_chars") == 0) - { - if (!(supported2 & JO2_EOF_CHARS)) - break; - opt->jo_set2 |= JO2_EOF_CHARS; - opt->jo_eof_chars = tv_get_string_buf_chk(item, - opt->jo_eof_chars_buf); - if (opt->jo_eof_chars == NULL) - { - semsg(_(e_invargval), "eof_chars"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "term_rows") == 0) - { - if (!(supported2 & JO2_TERM_ROWS)) - break; - opt->jo_set2 |= JO2_TERM_ROWS; - opt->jo_term_rows = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "term_cols") == 0) - { - if (!(supported2 & JO2_TERM_COLS)) - break; - opt->jo_set2 |= JO2_TERM_COLS; - opt->jo_term_cols = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "vertical") == 0) - { - if (!(supported2 & JO2_VERTICAL)) - break; - opt->jo_set2 |= JO2_VERTICAL; - opt->jo_vertical = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "curwin") == 0) - { - if (!(supported2 & JO2_CURWIN)) - break; - opt->jo_set2 |= JO2_CURWIN; - opt->jo_curwin = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "bufnr") == 0) - { - int nr; - - if (!(supported2 & JO2_CURWIN)) - break; - opt->jo_set2 |= JO2_BUFNR; - nr = tv_get_number(item); - if (nr <= 0) - { - semsg(_(e_invargNval), hi->hi_key, tv_get_string(item)); - return FAIL; - } - opt->jo_bufnr_buf = buflist_findnr(nr); - if (opt->jo_bufnr_buf == NULL) - { - semsg(_(e_nobufnr), (long)nr); - return FAIL; - } - if (opt->jo_bufnr_buf->b_nwindows == 0 - || opt->jo_bufnr_buf->b_term == NULL) - { - semsg(_(e_invarg2), "bufnr"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "hidden") == 0) - { - if (!(supported2 & JO2_HIDDEN)) - break; - opt->jo_set2 |= JO2_HIDDEN; - opt->jo_hidden = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "norestore") == 0) - { - if (!(supported2 & JO2_NORESTORE)) - break; - opt->jo_set2 |= JO2_NORESTORE; - opt->jo_term_norestore = tv_get_bool(item); - } - else if (STRCMP(hi->hi_key, "term_kill") == 0) - { - if (!(supported2 & JO2_TERM_KILL)) - break; - opt->jo_set2 |= JO2_TERM_KILL; - opt->jo_term_kill = tv_get_string_buf_chk(item, - opt->jo_term_kill_buf); - if (opt->jo_term_kill == NULL) - { - semsg(_(e_invargval), "term_kill"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "tty_type") == 0) - { - char_u *p; - - if (!(supported2 & JO2_TTY_TYPE)) - break; - opt->jo_set2 |= JO2_TTY_TYPE; - p = tv_get_string_chk(item); - if (p == NULL) - { - semsg(_(e_invargval), "tty_type"); - return FAIL; - } - // Allow empty string, "winpty", "conpty". - if (!(*p == NUL || STRCMP(p, "winpty") == 0 - || STRCMP(p, "conpty") == 0)) - { - semsg(_(e_invargval), "tty_type"); - return FAIL; - } - opt->jo_tty_type = p[0]; - } -# if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) - else if (STRCMP(hi->hi_key, "ansi_colors") == 0) - { - int n = 0; - listitem_T *li; - long_u rgb[16]; - - if (!(supported2 & JO2_ANSI_COLORS)) - break; - - if (item == NULL || item->v_type != VAR_LIST - || item->vval.v_list == NULL) - { - semsg(_(e_invargval), "ansi_colors"); - return FAIL; - } - - CHECK_LIST_MATERIALIZE(item->vval.v_list); - li = item->vval.v_list->lv_first; - for (; li != NULL && n < 16; li = li->li_next, n++) - { - char_u *color_name; - guicolor_T guicolor; - int called_emsg_before = called_emsg; - - color_name = tv_get_string_chk(&li->li_tv); - if (color_name == NULL) - return FAIL; - - guicolor = GUI_GET_COLOR(color_name); - if (guicolor == INVALCOLOR) - { - if (called_emsg_before == called_emsg) - // may not get the error if the GUI didn't start - semsg(_(e_alloc_color), color_name); - return FAIL; - } - - rgb[n] = GUI_MCH_GET_RGB(guicolor); - } - - if (n != 16 || li != NULL) - { - semsg(_(e_invargval), "ansi_colors"); - return FAIL; - } - - opt->jo_set2 |= JO2_ANSI_COLORS; - memcpy(opt->jo_ansi_colors, rgb, sizeof(rgb)); - } -# endif - else if (STRCMP(hi->hi_key, "term_highlight") == 0) - { - char_u *p; - - if (!(supported2 & JO2_TERM_HIGHLIGHT)) - break; - opt->jo_set2 |= JO2_TERM_HIGHLIGHT; - p = tv_get_string_buf_chk(item, opt->jo_term_highlight_buf); - if (p == NULL || *p == NUL) - { - semsg(_(e_invargval), "term_highlight"); - return FAIL; - } - opt->jo_term_highlight = p; - } - else if (STRCMP(hi->hi_key, "term_api") == 0) - { - if (!(supported2 & JO2_TERM_API)) - break; - opt->jo_set2 |= JO2_TERM_API; - opt->jo_term_api = tv_get_string_buf_chk(item, - opt->jo_term_api_buf); - if (opt->jo_term_api == NULL) - { - semsg(_(e_invargval), "term_api"); - return FAIL; - } - } -#endif - else if (STRCMP(hi->hi_key, "env") == 0) - { - if (!(supported2 & JO2_ENV)) - break; - if (item->v_type != VAR_DICT) - { - semsg(_(e_invargval), "env"); - return FAIL; - } - opt->jo_set2 |= JO2_ENV; - opt->jo_env = item->vval.v_dict; - if (opt->jo_env != NULL) - ++opt->jo_env->dv_refcount; - } - else if (STRCMP(hi->hi_key, "cwd") == 0) - { - if (!(supported2 & JO2_CWD)) - break; - opt->jo_cwd = tv_get_string_buf_chk(item, opt->jo_cwd_buf); - if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd) -#ifndef MSWIN // Win32 directories don't have the concept of "executable" - || mch_access((char *)opt->jo_cwd, X_OK) != 0 -#endif - ) - { - semsg(_(e_invargval), "cwd"); - return FAIL; - } - opt->jo_set2 |= JO2_CWD; - } - else if (STRCMP(hi->hi_key, "waittime") == 0) - { - if (!(supported & JO_WAITTIME)) - break; - opt->jo_set |= JO_WAITTIME; - opt->jo_waittime = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "timeout") == 0) - { - if (!(supported & JO_TIMEOUT)) - break; - opt->jo_set |= JO_TIMEOUT; - opt->jo_timeout = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "out_timeout") == 0) - { - if (!(supported & JO_OUT_TIMEOUT)) - break; - opt->jo_set |= JO_OUT_TIMEOUT; - opt->jo_out_timeout = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "err_timeout") == 0) - { - if (!(supported & JO_ERR_TIMEOUT)) - break; - opt->jo_set |= JO_ERR_TIMEOUT; - opt->jo_err_timeout = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "part") == 0) - { - if (!(supported & JO_PART)) - break; - opt->jo_set |= JO_PART; - val = tv_get_string(item); - if (STRCMP(val, "err") == 0) - opt->jo_part = PART_ERR; - else if (STRCMP(val, "out") == 0) - opt->jo_part = PART_OUT; - else - { - semsg(_(e_invargNval), "part", val); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "id") == 0) - { - if (!(supported & JO_ID)) - break; - opt->jo_set |= JO_ID; - opt->jo_id = tv_get_number(item); - } - else if (STRCMP(hi->hi_key, "stoponexit") == 0) - { - if (!(supported & JO_STOPONEXIT)) - break; - opt->jo_set |= JO_STOPONEXIT; - opt->jo_stoponexit = tv_get_string_buf_chk(item, - opt->jo_stoponexit_buf); - if (opt->jo_stoponexit == NULL) - { - semsg(_(e_invargval), "stoponexit"); - return FAIL; - } - } - else if (STRCMP(hi->hi_key, "block_write") == 0) - { - if (!(supported & JO_BLOCK_WRITE)) - break; - opt->jo_set |= JO_BLOCK_WRITE; - opt->jo_block_write = tv_get_number(item); - } - else - break; - --todo; - } - if (todo > 0) - { - semsg(_(e_invarg2), hi->hi_key); - return FAIL; - } - - return OK; -} - -static job_T *first_job = NULL; - - static void -job_free_contents(job_T *job) -{ - int i; - - ch_log(job->jv_channel, "Freeing job"); - if (job->jv_channel != NULL) - { - // The link from the channel to the job doesn't count as a reference, - // thus don't decrement the refcount of the job. The reference from - // the job to the channel does count the reference, decrement it and - // NULL the reference. We don't set ch_job_killed, unreferencing the - // job doesn't mean it stops running. - job->jv_channel->ch_job = NULL; - channel_unref(job->jv_channel); - } - mch_clear_job(job); - - vim_free(job->jv_tty_in); - vim_free(job->jv_tty_out); - vim_free(job->jv_stoponexit); -#ifdef UNIX - vim_free(job->jv_termsig); -#endif -#ifdef MSWIN - vim_free(job->jv_tty_type); -#endif - free_callback(&job->jv_exit_cb); - if (job->jv_argv != NULL) - { - for (i = 0; job->jv_argv[i] != NULL; i++) - vim_free(job->jv_argv[i]); - vim_free(job->jv_argv); - } -} - -/* - * Remove "job" from the list of jobs. - */ - static void -job_unlink(job_T *job) -{ - if (job->jv_next != NULL) - job->jv_next->jv_prev = job->jv_prev; - if (job->jv_prev == NULL) - first_job = job->jv_next; - else - job->jv_prev->jv_next = job->jv_next; -} - - static void -job_free_job(job_T *job) -{ - job_unlink(job); - vim_free(job); -} - - static void -job_free(job_T *job) -{ - if (!in_free_unref_items) - { - job_free_contents(job); - job_free_job(job); - } -} - -static job_T *jobs_to_free = NULL; - -/* - * Put "job" in a list to be freed later, when it's no longer referenced. - */ - static void -job_free_later(job_T *job) -{ - job_unlink(job); - job->jv_next = jobs_to_free; - jobs_to_free = job; -} - - static void -free_jobs_to_free_later(void) -{ - job_T *job; - - while (jobs_to_free != NULL) - { - job = jobs_to_free; - jobs_to_free = job->jv_next; - job_free_contents(job); - vim_free(job); - } -} - -#if defined(EXITFREE) || defined(PROTO) - void -job_free_all(void) -{ - while (first_job != NULL) - job_free(first_job); - free_jobs_to_free_later(); - -# ifdef FEAT_TERMINAL - free_unused_terminals(); -# endif -} -#endif - -/* - * Return TRUE if we need to check if the process of "job" has ended. - */ - static int -job_need_end_check(job_T *job) -{ - return job->jv_status == JOB_STARTED - && (job->jv_stoponexit != NULL || job->jv_exit_cb.cb_name != NULL); -} - -/* - * Return TRUE if the channel of "job" is still useful. - */ - static int -job_channel_still_useful(job_T *job) -{ - return job->jv_channel != NULL && channel_still_useful(job->jv_channel); -} - -/* - * Return TRUE if the channel of "job" is closeable. - */ - static int -job_channel_can_close(job_T *job) -{ - return job->jv_channel != NULL && channel_can_close(job->jv_channel); -} - -/* - * Return TRUE if the job should not be freed yet. Do not free the job when - * it has not ended yet and there is a "stoponexit" flag, an exit callback - * or when the associated channel will do something with the job output. - */ - static int -job_still_useful(job_T *job) -{ - return job_need_end_check(job) || job_channel_still_useful(job); -} - -#if defined(GUI_MAY_FORK) || defined(GUI_MAY_SPAWN) || defined(PROTO) -/* - * Return TRUE when there is any running job that we care about. - */ - int -job_any_running() -{ - job_T *job; - - FOR_ALL_JOBS(job) - if (job_still_useful(job)) - { - ch_log(NULL, "GUI not forking because a job is running"); - return TRUE; - } - return FALSE; -} -#endif - -#if !defined(USE_ARGV) || defined(PROTO) -/* - * Escape one argument for an external command. - * Returns the escaped string in allocated memory. NULL when out of memory. - */ - static char_u * -win32_escape_arg(char_u *arg) -{ - int slen, dlen; - int escaping = 0; - int i; - char_u *s, *d; - char_u *escaped_arg; - int has_spaces = FALSE; - - // First count the number of extra bytes required. - slen = (int)STRLEN(arg); - dlen = slen; - for (s = arg; *s != NUL; MB_PTR_ADV(s)) - { - if (*s == '"' || *s == '\\') - ++dlen; - if (*s == ' ' || *s == '\t') - has_spaces = TRUE; - } - - if (has_spaces) - dlen += 2; - - if (dlen == slen) - return vim_strsave(arg); - - // Allocate memory for the result and fill it. - escaped_arg = alloc(dlen + 1); - if (escaped_arg == NULL) - return NULL; - memset(escaped_arg, 0, dlen+1); - - d = escaped_arg; - - if (has_spaces) - *d++ = '"'; - - for (s = arg; *s != NUL;) - { |