summaryrefslogtreecommitdiff
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-07-22 23:03:57 +0200
committerBram Moolenaar <Bram@vim.org>2019-07-22 23:03:57 +0200
commit29b7d7a9aac591f920edb89241c8cde27378e50b (patch)
tree96368a556edd943bec67f303778bc0c864573860 /src/evalfunc.c
parente5e6950193ddf365c6c507ddefcd7f9db939e5ac (diff)
downloadvim-git-29b7d7a9aac591f920edb89241c8cde27378e50b.tar.gz
patch 8.1.1734: the evalfunc.c file is too bigv8.1.1734
Problem: The evalfunc.c file is too big. Solution: Move some functions to other files.
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c309
1 files changed, 1 insertions, 308 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 864b623c5..3fbeec26c 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -24,10 +24,8 @@
# include <time.h> /* for time_t */
#endif
-static char *e_listarg = N_("E686: Argument of %s must be a List");
static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob");
static char *e_stringreq = N_("E928: String required");
-static char *e_invalwindow = N_("E957: Invalid window number");
#ifdef FEAT_FLOAT
static void f_abs(typval_T *argvars, typval_T *rettv);
@@ -164,7 +162,6 @@ static void f_getftype(typval_T *argvars, typval_T *rettv);
static void f_getjumplist(typval_T *argvars, typval_T *rettv);
static void f_getline(typval_T *argvars, typval_T *rettv);
static void f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED);
-static void f_getmatches(typval_T *argvars, typval_T *rettv);
static void f_getpid(typval_T *argvars, typval_T *rettv);
static void f_getcurpos(typval_T *argvars, typval_T *rettv);
static void f_getpos(typval_T *argvars, typval_T *rettv);
@@ -213,10 +210,6 @@ static void f_isnan(typval_T *argvars, typval_T *rettv);
#endif
static void f_items(typval_T *argvars, typval_T *rettv);
static void f_join(typval_T *argvars, typval_T *rettv);
-static void f_js_decode(typval_T *argvars, typval_T *rettv);
-static void f_js_encode(typval_T *argvars, typval_T *rettv);
-static void f_json_decode(typval_T *argvars, typval_T *rettv);
-static void f_json_encode(typval_T *argvars, typval_T *rettv);
static void f_keys(typval_T *argvars, typval_T *rettv);
static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv);
static void f_len(typval_T *argvars, typval_T *rettv);
@@ -238,10 +231,6 @@ static void f_map(typval_T *argvars, typval_T *rettv);
static void f_maparg(typval_T *argvars, typval_T *rettv);
static void f_mapcheck(typval_T *argvars, typval_T *rettv);
static void f_match(typval_T *argvars, typval_T *rettv);
-static void f_matchadd(typval_T *argvars, typval_T *rettv);
-static void f_matchaddpos(typval_T *argvars, typval_T *rettv);
-static void f_matcharg(typval_T *argvars, typval_T *rettv);
-static void f_matchdelete(typval_T *argvars, typval_T *rettv);
static void f_matchend(typval_T *argvars, typval_T *rettv);
static void f_matchlist(typval_T *argvars, typval_T *rettv);
static void f_matchstr(typval_T *argvars, typval_T *rettv);
@@ -2202,7 +2191,7 @@ f_cindent(typval_T *argvars UNUSED, typval_T *rettv)
rettv->vval.v_number = -1;
}
- static win_T *
+ win_T *
get_optional_window(typval_T *argvars, int idx)
{
win_T *win = curwin;
@@ -5285,74 +5274,6 @@ f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
}
/*
- * "getmatches()" function
- */
- static void
-f_getmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
-{
-#ifdef FEAT_SEARCH_EXTRA
- dict_T *dict;
- matchitem_T *cur;
- int i;
- win_T *win = get_optional_window(argvars, 0);
-
- if (rettv_list_alloc(rettv) == FAIL || win == NULL)
- return;
-
- cur = win->w_match_head;
- while (cur != NULL)
- {
- dict = dict_alloc();
- if (dict == NULL)
- return;
- if (cur->match.regprog == NULL)
- {
- /* match added with matchaddpos() */
- for (i = 0; i < MAXPOSMATCH; ++i)
- {
- llpos_T *llpos;
- char buf[30]; // use 30 to avoid compiler warning
- list_T *l;
-
- llpos = &cur->pos.pos[i];
- if (llpos->lnum == 0)
- break;
- l = list_alloc();
- if (l == NULL)
- break;
- list_append_number(l, (varnumber_T)llpos->lnum);
- if (llpos->col > 0)
- {
- list_append_number(l, (varnumber_T)llpos->col);
- list_append_number(l, (varnumber_T)llpos->len);
- }
- sprintf(buf, "pos%d", i + 1);
- dict_add_list(dict, buf, l);
- }
- }
- else
- {
- dict_add_string(dict, "pattern", cur->pattern);
- }
- dict_add_string(dict, "group", syn_id2name(cur->hlg_id));
- dict_add_number(dict, "priority", (long)cur->priority);
- dict_add_number(dict, "id", (long)cur->id);
-# if defined(FEAT_CONCEAL)
- if (cur->conceal_char)
- {
- char_u buf[MB_MAXBYTES + 1];
-
- buf[(*mb_char2bytes)((int)cur->conceal_char, buf)] = NUL;
- dict_add_string(dict, "conceal", (char_u *)&buf);
- }
-# endif
- list_append_dict(rettv->vval.v_list, dict);
- cur = cur->next;
- }
-#endif
-}
-
-/*
* "getpid()" function
*/
static void
@@ -7385,55 +7306,6 @@ f_join(typval_T *argvars, typval_T *rettv)
}
/*
- * "js_decode()" function
- */
- static void
-f_js_decode(typval_T *argvars, typval_T *rettv)
-{
- js_read_T reader;
-
- reader.js_buf = tv_get_string(&argvars[0]);
- reader.js_fill = NULL;
- reader.js_used = 0;
- if (json_decode_all(&reader, rettv, JSON_JS) != OK)
- emsg(_(e_invarg));
-}
-
-/*
- * "js_encode()" function
- */
- static void
-f_js_encode(typval_T *argvars, typval_T *rettv)
-{
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string = json_encode(&argvars[0], JSON_JS);
-}
-
-/*
- * "json_decode()" function
- */
- static void
-f_json_decode(typval_T *argvars, typval_T *rettv)
-{
- js_read_T reader;
-
- reader.js_buf = tv_get_string(&argvars[0]);
- reader.js_fill = NULL;
- reader.js_used = 0;
- json_decode_all(&reader, rettv, 0);
-}
-
-/*
- * "json_encode()" function
- */
- static void
-f_json_encode(typval_T *argvars, typval_T *rettv)
-{
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string = json_encode(&argvars[0], 0);
-}
-
-/*
* "keys()" function
*/
static void
@@ -8071,185 +7943,6 @@ f_match(typval_T *argvars, typval_T *rettv)
find_some_match(argvars, rettv, MATCH_MATCH);
}
-#ifdef FEAT_SEARCH_EXTRA
- static int
-matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win)
-{
- dictitem_T *di;
-
- if (tv->v_type != VAR_DICT)
- {
- emsg(_(e_dictreq));
- return FAIL;
- }
-
- if (dict_find(tv->vval.v_dict, (char_u *)"conceal", -1) != NULL)
- *conceal_char = dict_get_string(tv->vval.v_dict,
- (char_u *)"conceal", FALSE);
-
- if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL)
- {
- *win = find_win_by_nr_or_id(&di->di_tv);
- if (*win == NULL)
- {
- emsg(_(e_invalwindow));
- return FAIL;
- }
- }
-
- return OK;
-}
-#endif
-
-/*
- * "matchadd()" function
- */
- static void
-f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
-{
-#ifdef FEAT_SEARCH_EXTRA
- char_u buf[NUMBUFLEN];
- char_u *grp = tv_get_string_buf_chk(&argvars[0], buf); /* group */
- char_u *pat = tv_get_string_buf_chk(&argvars[1], buf); /* pattern */
- int prio = 10; /* default priority */
- int id = -1;
- int error = FALSE;
- char_u *conceal_char = NULL;
- win_T *win = curwin;
-
- rettv->vval.v_number = -1;
-
- if (grp == NULL || pat == NULL)
- return;
- if (argvars[2].v_type != VAR_UNKNOWN)
- {
- prio = (int)tv_get_number_chk(&argvars[2], &error);
- if (argvars[3].v_type != VAR_UNKNOWN)
- {
- id = (int)tv_get_number_chk(&argvars[3], &error);
- if (argvars[4].v_type != VAR_UNKNOWN
- && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
- return;
- }
- }
- if (error == TRUE)
- return;
- if (id >= 1 && id <= 3)
- {
- semsg(_("E798: ID is reserved for \":match\": %d"), id);
- return;
- }
-
- rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL,
- conceal_char);
-#endif
-}
-
-/*
- * "matchaddpos()" function
- */
- static void
-f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
-{
-#ifdef FEAT_SEARCH_EXTRA
- char_u buf[NUMBUFLEN];
- char_u *group;
- int prio = 10;
- int id = -1;
- int error = FALSE;
- list_T *l;
- char_u *conceal_char = NULL;
- win_T *win = curwin;
-
- rettv->vval.v_number = -1;
-
- group = tv_get_string_buf_chk(&argvars[0], buf);
- if (group == NULL)
- return;
-
- if (argvars[1].v_type != VAR_LIST)
- {
- semsg(_(e_listarg), "matchaddpos()");
- return;
- }
- l = argvars[1].vval.v_list;
- if (l == NULL)
- return;
-
- if (argvars[2].v_type != VAR_UNKNOWN)
- {
- prio = (int)tv_get_number_chk(&argvars[2], &error);
- if (argvars[3].v_type != VAR_UNKNOWN)
- {
- id = (int)tv_get_number_chk(&argvars[3], &error);
-
- if (argvars[4].v_type != VAR_UNKNOWN
- && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
- return;
- }
- }
- if (error == TRUE)
- return;
-
- /* id == 3 is ok because matchaddpos() is supposed to substitute :3match */
- if (id == 1 || id == 2)
- {
- semsg(_("E798: ID is reserved for \":match\": %d"), id);
- return;
- }
-
- rettv->vval.v_number = match_add(win, group, NULL, prio, id, l,
- conceal_char);
-#endif
-}
-
-/*
- * "matcharg()" function
- */
- static void
-f_matcharg(typval_T *argvars UNUSED, typval_T *rettv)
-{
- if (rettv_list_alloc(rettv) == OK)
- {
-#ifdef FEAT_SEARCH_EXTRA
- int id = (int)tv_get_number(&argvars[0]);
- matchitem_T *m;
-
- if (id >= 1 && id <= 3)
- {
- if ((m = (matchitem_T *)get_match(curwin, id)) != NULL)
- {
- list_append_string(rettv->vval.v_list,
- syn_id2name(m->hlg_id), -1);
- list_append_string(rettv->vval.v_list, m->pattern, -1);
- }
- else
- {
- list_append_string(rettv->vval.v_list, NULL, -1);
- list_append_string(rettv->vval.v_list, NULL, -1);
- }
- }
-#endif
- }
-}
-
-/*
- * "matchdelete()" function
- */
- static void
-f_matchdelete(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
-{
-#ifdef FEAT_SEARCH_EXTRA
- win_T *win = get_optional_window(argvars, 1);
-
- if (win == NULL)
- rettv->vval.v_number = -1;
- else
- rettv->vval.v_number = match_delete(win,
- (int)tv_get_number(&argvars[0]), TRUE);
-#endif
-}
-
/*
* "matchend()" function
*/