Mercurial > vim
comparison src/eval.c @ 8086:04ed31f9ef70 v7.4.1337
commit https://github.com/vim/vim/commit/ba093bc0002ac60aebd0f2d8a458e2fdac38f1ed
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 16 19:37:29 2016 +0100
patch 7.4.1337
Problem: Part of the change is missing.
Solution: Add changes to eval.c
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 16 Feb 2016 19:45:05 +0100 |
parents | b6cb94ad97a4 |
children | 18a3f0f05244 |
comparison
equal
deleted
inserted
replaced
8085:b335c6cc87b4 | 8086:04ed31f9ef70 |
---|---|
7533 return s; | 7533 return s; |
7534 } | 7534 } |
7535 | 7535 |
7536 /* | 7536 /* |
7537 * Get a number item from a dictionary. | 7537 * Get a number item from a dictionary. |
7538 * Returns 0 if the entry doesn't exist or out of memory. | 7538 * Returns 0 if the entry doesn't exist. |
7539 */ | 7539 */ |
7540 long | 7540 long |
7541 get_dict_number(dict_T *d, char_u *key) | 7541 get_dict_number(dict_T *d, char_u *key) |
7542 { | 7542 { |
7543 dictitem_T *di; | 7543 dictitem_T *di; |
9928 } | 9928 } |
9929 ch_logfile(file); | 9929 ch_logfile(file); |
9930 } | 9930 } |
9931 | 9931 |
9932 /* | 9932 /* |
9933 * Get the "mode" entry from "dict", if it exists, and parse the mode name. | |
9934 * If the mode is invalide return FAIL. | |
9935 */ | |
9936 static int | |
9937 get_mode_arg(dict_T *dict, jobopt_T *opt) | |
9938 { | |
9939 dictitem_T *item; | |
9940 char_u *mode; | |
9941 | |
9942 if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL) | |
9943 { | |
9944 mode = get_tv_string(&item->di_tv); | |
9945 if (STRCMP(mode, "nl") == 0) | |
9946 opt->jo_mode = MODE_NL; | |
9947 else if (STRCMP(mode, "raw") == 0) | |
9948 opt->jo_mode = MODE_RAW; | |
9949 else if (STRCMP(mode, "js") == 0) | |
9950 opt->jo_mode = MODE_JS; | |
9951 else if (STRCMP(mode, "json") == 0) | |
9952 opt->jo_mode = MODE_JSON; | |
9953 else | |
9954 { | |
9955 EMSG2(_(e_invarg2), mode); | |
9956 return FAIL; | |
9957 } | |
9958 } | |
9959 return OK; | |
9960 } | |
9961 | |
9962 /* | |
9933 * "ch_open()" function | 9963 * "ch_open()" function |
9934 */ | 9964 */ |
9935 static void | 9965 static void |
9936 f_ch_open(typval_T *argvars, typval_T *rettv) | 9966 f_ch_open(typval_T *argvars, typval_T *rettv) |
9937 { | 9967 { |
9938 char_u *address; | 9968 char_u *address; |
9939 char_u *mode; | |
9940 char_u *callback = NULL; | 9969 char_u *callback = NULL; |
9941 char_u *p; | 9970 char_u *p; |
9942 char *rest; | 9971 char *rest; |
9943 int port; | 9972 int port; |
9944 int waittime = 0; | 9973 int waittime = 0; |
9945 int timeout = 2000; | 9974 int timeout = 2000; |
9946 ch_mode_T ch_mode = MODE_JSON; | 9975 jobopt_T options; |
9947 channel_T *channel; | 9976 channel_T *channel; |
9948 | 9977 |
9949 /* default: fail */ | 9978 /* default: fail */ |
9950 rettv->v_type = VAR_CHANNEL; | 9979 rettv->v_type = VAR_CHANNEL; |
9951 rettv->vval.v_channel = NULL; | 9980 rettv->vval.v_channel = NULL; |
9972 p[-1] = ':'; | 10001 p[-1] = ':'; |
9973 EMSG2(_(e_invarg2), address); | 10002 EMSG2(_(e_invarg2), address); |
9974 return; | 10003 return; |
9975 } | 10004 } |
9976 | 10005 |
10006 options.jo_mode = MODE_JSON; | |
9977 if (argvars[1].v_type == VAR_DICT) | 10007 if (argvars[1].v_type == VAR_DICT) |
9978 { | 10008 { |
9979 dict_T *dict = argvars[1].vval.v_dict; | 10009 dict_T *dict = argvars[1].vval.v_dict; |
9980 dictitem_T *item; | 10010 dictitem_T *item; |
9981 | 10011 |
9982 /* parse argdict */ | 10012 /* parse argdict */ |
9983 if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL) | 10013 if (get_mode_arg(dict, &options) == FAIL) |
9984 { | 10014 return; |
9985 mode = get_tv_string(&item->di_tv); | |
9986 if (STRCMP(mode, "raw") == 0) | |
9987 ch_mode = MODE_RAW; | |
9988 else if (STRCMP(mode, "js") == 0) | |
9989 ch_mode = MODE_JS; | |
9990 else if (STRCMP(mode, "json") == 0) | |
9991 ch_mode = MODE_JSON; | |
9992 else | |
9993 { | |
9994 EMSG2(_(e_invarg2), mode); | |
9995 return; | |
9996 } | |
9997 } | |
9998 if ((item = dict_find(dict, (char_u *)"waittime", -1)) != NULL) | 10015 if ((item = dict_find(dict, (char_u *)"waittime", -1)) != NULL) |
9999 waittime = get_tv_number(&item->di_tv); | 10016 waittime = get_tv_number(&item->di_tv); |
10000 if ((item = dict_find(dict, (char_u *)"timeout", -1)) != NULL) | 10017 if ((item = dict_find(dict, (char_u *)"timeout", -1)) != NULL) |
10001 timeout = get_tv_number(&item->di_tv); | 10018 timeout = get_tv_number(&item->di_tv); |
10002 if ((item = dict_find(dict, (char_u *)"callback", -1)) != NULL) | 10019 if ((item = dict_find(dict, (char_u *)"callback", -1)) != NULL) |
10010 | 10027 |
10011 channel = channel_open((char *)address, port, waittime, NULL); | 10028 channel = channel_open((char *)address, port, waittime, NULL); |
10012 if (channel != NULL) | 10029 if (channel != NULL) |
10013 { | 10030 { |
10014 rettv->vval.v_channel = channel; | 10031 rettv->vval.v_channel = channel; |
10015 channel_set_json_mode(channel, ch_mode); | 10032 channel_set_mode(channel, options.jo_mode); |
10016 channel_set_timeout(channel, timeout); | 10033 channel_set_timeout(channel, timeout); |
10017 if (callback != NULL && *callback != NUL) | 10034 if (callback != NULL && *callback != NUL) |
10018 channel_set_callback(channel, callback); | 10035 channel_set_callback(channel, callback); |
10019 } | 10036 } |
10020 } | 10037 } |
14471 * "job_start()" function | 14488 * "job_start()" function |
14472 */ | 14489 */ |
14473 static void | 14490 static void |
14474 f_job_start(typval_T *argvars UNUSED, typval_T *rettv) | 14491 f_job_start(typval_T *argvars UNUSED, typval_T *rettv) |
14475 { | 14492 { |
14476 job_T *job; | 14493 job_T *job; |
14477 char_u *cmd = NULL; | 14494 char_u *cmd = NULL; |
14478 #if defined(UNIX) | 14495 #if defined(UNIX) |
14479 # define USE_ARGV | 14496 # define USE_ARGV |
14480 char **argv = NULL; | 14497 char **argv = NULL; |
14481 int argc = 0; | 14498 int argc = 0; |
14482 #else | 14499 #else |
14483 garray_T ga; | 14500 garray_T ga; |
14484 #endif | 14501 #endif |
14502 jobopt_T options; | |
14485 | 14503 |
14486 rettv->v_type = VAR_JOB; | 14504 rettv->v_type = VAR_JOB; |
14487 job = job_alloc(); | 14505 job = job_alloc(); |
14488 rettv->vval.v_job = job; | 14506 rettv->vval.v_job = job; |
14489 if (job == NULL) | 14507 if (job == NULL) |
14490 return; | 14508 return; |
14491 | 14509 |
14492 rettv->vval.v_job->jv_status = JOB_FAILED; | 14510 rettv->vval.v_job->jv_status = JOB_FAILED; |
14511 | |
14512 /* Default mode is NL. */ | |
14513 options.jo_mode = MODE_NL; | |
14514 if (argvars[1].v_type != VAR_UNKNOWN) | |
14515 { | |
14516 dict_T *dict; | |
14517 | |
14518 if (argvars[1].v_type != VAR_DICT) | |
14519 { | |
14520 EMSG(_(e_invarg)); | |
14521 return; | |
14522 } | |
14523 dict = argvars[1].vval.v_dict; | |
14524 if (get_mode_arg(dict, &options) == FAIL) | |
14525 return; | |
14526 } | |
14527 | |
14493 #ifndef USE_ARGV | 14528 #ifndef USE_ARGV |
14494 ga_init2(&ga, (int)sizeof(char*), 20); | 14529 ga_init2(&ga, (int)sizeof(char*), 20); |
14495 #endif | 14530 #endif |
14496 | 14531 |
14497 if (argvars[0].v_type == VAR_STRING) | 14532 if (argvars[0].v_type == VAR_STRING) |
14550 #else | 14585 #else |
14551 cmd = ga.ga_data; | 14586 cmd = ga.ga_data; |
14552 #endif | 14587 #endif |
14553 } | 14588 } |
14554 #ifdef USE_ARGV | 14589 #ifdef USE_ARGV |
14555 mch_start_job(argv, job); | 14590 mch_start_job(argv, job, &options); |
14556 #else | 14591 #else |
14557 mch_start_job((char *)cmd, job); | 14592 mch_start_job((char *)cmd, job, &options); |
14558 #endif | 14593 #endif |
14559 | 14594 |
14560 theend: | 14595 theend: |
14561 #ifdef USE_ARGV | 14596 #ifdef USE_ARGV |
14562 vim_free(argv); | 14597 vim_free(argv); |