Mercurial > vim
comparison src/eval.c @ 8267:108d30ed34ba v7.4.1426
commit https://github.com/vim/vim/commit/187db50d0499aecf4cfd42fb4db0a1bebf61c8cd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 27 14:44:26 2016 +0100
patch 7.4.1426
Problem: The "out-io" option for jobs is not implemented yet.
Solution: Implement the "buffer" value: append job output to a buffer.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 27 Feb 2016 14:45:05 +0100 |
parents | 99a70c3b902f |
children | 74b15ed0a259 |
comparison
equal
deleted
inserted
replaced
8266:62545a8dec53 | 8267:108d30ed34ba |
---|---|
9974 return FAIL; | 9974 return FAIL; |
9975 } | 9975 } |
9976 return OK; | 9976 return OK; |
9977 } | 9977 } |
9978 | 9978 |
9979 static int | |
9980 handle_io(typval_T *item, int part, jobopt_T *opt) | |
9981 { | |
9982 char_u *val = get_tv_string(item); | |
9983 | |
9984 opt->jo_set |= JO_OUT_IO << (part - PART_OUT); | |
9985 if (STRCMP(val, "null") == 0) | |
9986 opt->jo_io[part] = JIO_NULL; | |
9987 else if (STRCMP(val, "pipe") == 0) | |
9988 opt->jo_io[part] = JIO_PIPE; | |
9989 else if (STRCMP(val, "file") == 0) | |
9990 opt->jo_io[part] = JIO_FILE; | |
9991 else if (STRCMP(val, "buffer") == 0) | |
9992 opt->jo_io[part] = JIO_BUFFER; | |
9993 else if (STRCMP(val, "out") == 0 && part == PART_ERR) | |
9994 opt->jo_io[part] = JIO_OUT; | |
9995 else | |
9996 { | |
9997 EMSG2(_(e_invarg2), val); | |
9998 return FAIL; | |
9999 } | |
10000 return OK; | |
10001 } | |
10002 | |
9979 static void | 10003 static void |
9980 clear_job_options(jobopt_T *opt) | 10004 clear_job_options(jobopt_T *opt) |
9981 { | 10005 { |
9982 vim_memset(opt, 0, sizeof(jobopt_T)); | 10006 vim_memset(opt, 0, sizeof(jobopt_T)); |
10007 } | |
10008 | |
10009 /* | |
10010 * Get the PART_ number from the first character of an option name. | |
10011 */ | |
10012 static int | |
10013 part_from_char(int c) | |
10014 { | |
10015 return c == 'i' ? PART_IN : c == 'o' ? PART_OUT: PART_ERR; | |
9983 } | 10016 } |
9984 | 10017 |
9985 /* | 10018 /* |
9986 * Get the option entries from the dict in "tv", parse them and put the result | 10019 * Get the option entries from the dict in "tv", parse them and put the result |
9987 * in "opt". | 10020 * in "opt". |
9994 typval_T *item; | 10027 typval_T *item; |
9995 char_u *val; | 10028 char_u *val; |
9996 dict_T *dict; | 10029 dict_T *dict; |
9997 int todo; | 10030 int todo; |
9998 hashitem_T *hi; | 10031 hashitem_T *hi; |
10032 int part; | |
9999 | 10033 |
10000 opt->jo_set = 0; | 10034 opt->jo_set = 0; |
10001 if (tv->v_type == VAR_UNKNOWN) | 10035 if (tv->v_type == VAR_UNKNOWN) |
10002 return OK; | 10036 return OK; |
10003 if (tv->v_type != VAR_DICT) | 10037 if (tv->v_type != VAR_DICT) |
10043 if (!(supported & JO_ERR_MODE)) | 10077 if (!(supported & JO_ERR_MODE)) |
10044 break; | 10078 break; |
10045 if (handle_mode(item, opt, &opt->jo_err_mode, JO_ERR_MODE) | 10079 if (handle_mode(item, opt, &opt->jo_err_mode, JO_ERR_MODE) |
10046 == FAIL) | 10080 == FAIL) |
10047 return FAIL; | 10081 return FAIL; |
10082 } | |
10083 else if (STRCMP(hi->hi_key, "in-io") == 0 | |
10084 || STRCMP(hi->hi_key, "out-io") == 0 | |
10085 || STRCMP(hi->hi_key, "err-io") == 0) | |
10086 { | |
10087 if (!(supported & JO_OUT_IO)) | |
10088 break; | |
10089 if (handle_io(item, part_from_char(*hi->hi_key), opt) == FAIL) | |
10090 return FAIL; | |
10091 } | |
10092 else if (STRCMP(hi->hi_key, "in-name") == 0 | |
10093 || STRCMP(hi->hi_key, "out-name") == 0 | |
10094 || STRCMP(hi->hi_key, "err-name") == 0) | |
10095 { | |
10096 part = part_from_char(*hi->hi_key); | |
10097 | |
10098 if (!(supported & JO_OUT_IO)) | |
10099 break; | |
10100 opt->jo_set |= JO_OUT_NAME << (part - PART_OUT); | |
10101 opt->jo_io_name[part] = | |
10102 get_tv_string_buf_chk(item, opt->jo_io_name_buf[part]); | |
10048 } | 10103 } |
10049 else if (STRCMP(hi->hi_key, "callback") == 0) | 10104 else if (STRCMP(hi->hi_key, "callback") == 0) |
10050 { | 10105 { |
10051 if (!(supported & JO_CALLBACK)) | 10106 if (!(supported & JO_CALLBACK)) |
10052 break; | 10107 break; |
10176 { | 10231 { |
10177 EMSG2(_(e_invarg2), hi->hi_key); | 10232 EMSG2(_(e_invarg2), hi->hi_key); |
10178 return FAIL; | 10233 return FAIL; |
10179 } | 10234 } |
10180 | 10235 |
10236 for (part = PART_OUT; part <= PART_IN; ++part) | |
10237 if (opt->jo_io[part] == JIO_BUFFER && opt->jo_io_name[part] == NULL) | |
10238 { | |
10239 EMSG(_("E915: Missing name for buffer")); | |
10240 return FAIL; | |
10241 } | |
10242 | |
10181 return OK; | 10243 return OK; |
10182 } | 10244 } |
10183 #endif | 10245 #endif |
10184 | 10246 |
10185 #ifdef FEAT_CHANNEL | 10247 #ifdef FEAT_CHANNEL |
10214 f_ch_close(typval_T *argvars, typval_T *rettv UNUSED) | 10276 f_ch_close(typval_T *argvars, typval_T *rettv UNUSED) |
10215 { | 10277 { |
10216 channel_T *channel = get_channel_arg(&argvars[0]); | 10278 channel_T *channel = get_channel_arg(&argvars[0]); |
10217 | 10279 |
10218 if (channel != NULL) | 10280 if (channel != NULL) |
10281 { | |
10219 channel_close(channel, FALSE); | 10282 channel_close(channel, FALSE); |
10283 channel_clear(channel); | |
10284 } | |
10220 } | 10285 } |
10221 | 10286 |
10222 # ifdef FEAT_JOB | 10287 # ifdef FEAT_JOB |
10223 /* | 10288 /* |
10224 * "ch_getjob()" function | 10289 * "ch_getjob()" function |
14946 /* Default mode is NL. */ | 15011 /* Default mode is NL. */ |
14947 clear_job_options(&opt); | 15012 clear_job_options(&opt); |
14948 opt.jo_mode = MODE_NL; | 15013 opt.jo_mode = MODE_NL; |
14949 if (get_job_options(&argvars[1], &opt, | 15014 if (get_job_options(&argvars[1], &opt, |
14950 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL | 15015 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL |
14951 + JO_STOPONEXIT + JO_EXIT_CB) == FAIL) | 15016 + JO_STOPONEXIT + JO_EXIT_CB + JO_OUT_IO) == FAIL) |
14952 return; | 15017 return; |
14953 job_set_options(job, &opt); | 15018 job_set_options(job, &opt); |
14954 | 15019 |
14955 #ifndef USE_ARGV | 15020 #ifndef USE_ARGV |
14956 ga_init2(&ga, (int)sizeof(char*), 20); | 15021 ga_init2(&ga, (int)sizeof(char*), 20); |