diff options
author | ZyX <kp-pav@yandex.ru> | 2014-10-26 14:35:33 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:43:43 +0300 |
commit | 5674546580643fab33f0d10babacbc8e7792e287 (patch) | |
tree | 015f97fc70388309c8c345c1e28cf65cf81983f9 | |
parent | c0bab19cf5aeb2533e0995a44283088b95a5a531 (diff) | |
download | rneovim-5674546580643fab33f0d10babacbc8e7792e287.tar.gz rneovim-5674546580643fab33f0d10babacbc8e7792e287.tar.bz2 rneovim-5674546580643fab33f0d10babacbc8e7792e287.zip |
ex_getln: Make get_histtype accept length argument
-rw-r--r-- | src/nvim/eval.c | 12 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 19 |
2 files changed, 14 insertions, 17 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 1c76847037..a193c82f9d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -11152,7 +11152,7 @@ static void f_histadd(typval_T *argvars, typval_T *rettv) if (check_restricted() || check_secure()) return; str = get_tv_string_chk(&argvars[0]); /* NULL on type error */ - histype = str != NULL ? get_histtype(str) : -1; + histype = str != NULL ? get_histtype(str, STRLEN(str)) : -1; if (histype >= 0) { str = get_tv_string_buf(&argvars[1], buf); if (*str != NUL) { @@ -11178,14 +11178,14 @@ static void f_histdel(typval_T *argvars, typval_T *rettv) n = 0; else if (argvars[1].v_type == VAR_UNKNOWN) /* only one argument: clear entire history */ - n = clr_history(get_histtype(str)); + n = clr_history(get_histtype(str, STRLEN(str))); else if (argvars[1].v_type == VAR_NUMBER) /* index given: remove that entry */ - n = del_history_idx(get_histtype(str), + n = del_history_idx(get_histtype(str, STRLEN(str)), (int)get_tv_number(&argvars[1])); else /* string given: remove all matching entries */ - n = del_history_entry(get_histtype(str), + n = del_history_entry(get_histtype(str, STRLEN(str)), get_tv_string_buf(&argvars[1], buf)); rettv->vval.v_number = n; } @@ -11203,7 +11203,7 @@ static void f_histget(typval_T *argvars, typval_T *rettv) if (str == NULL) rettv->vval.v_string = NULL; else { - type = get_histtype(str); + type = get_histtype(str, STRLEN(str)); if (argvars[1].v_type == VAR_UNKNOWN) idx = get_history_idx(type); else @@ -11223,7 +11223,7 @@ static void f_histnr(typval_T *argvars, typval_T *rettv) char_u *history = get_tv_string_chk(&argvars[0]); - i = history == NULL ? HIST_CMD - 1 : get_histtype(history); + i = history == NULL ? HIST_CMD - 1 : get_histtype(history, STRLEN(history)); if (i >= HIST_CMD && i < HIST_COUNT) i = get_history_idx(i); else diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index cffda1ca55..0c2848da98 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4459,10 +4459,9 @@ in_history ( * When "name" is empty, return "cmd" history. * Returns -1 for unknown history name. */ -int get_histtype(char_u *name) +int get_histtype(char_u *name, size_t len) { int i; - int len = (int)STRLEN(name); /* No argument: use current history. */ if (len == 0) @@ -4472,8 +4471,9 @@ int get_histtype(char_u *name) if (STRNICMP(name, history_names[i], len) == 0) return i; - if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) + if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && len == 1) { return hist_char2type(name[0]); + } return -1; } @@ -4847,23 +4847,20 @@ void ex_history(exarg_T *eap) while (ASCII_ISALPHA(*end) || vim_strchr((char_u *)":=@>/?", *end) != NULL) end++; - i = *end; - *end = NUL; - histype1 = get_histtype(arg); - if (histype1 == -1) { - if (STRNICMP(arg, "all", STRLEN(arg)) == 0) { + histype1 = get_histtype(arg, end - arg); + if (histype1 == HIST_INVALID) { + if (STRNICMP(arg, "all", end - arg) == 0) { histype1 = 0; histype2 = HIST_COUNT-1; } else { - *end = i; EMSG(_(e_trailing)); return; } } else histype2 = histype1; - *end = i; - } else + } else { end = arg; + } if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) { EMSG(_(e_trailing)); return; |