comparison src/evalfunc.c @ 17472:dfd87ef822aa v8.1.1734

patch 8.1.1734: the evalfunc.c file is too big commit https://github.com/vim/vim/commit/29b7d7a9aac591f920edb89241c8cde27378e50b Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 22 23:03:57 2019 +0200 patch 8.1.1734: the evalfunc.c file is too big Problem: The evalfunc.c file is too big. Solution: Move some functions to other files.
author Bram Moolenaar <Bram@vim.org>
date Mon, 22 Jul 2019 23:15:05 +0200
parents cb008de2a6ec
children f1fd0b0b335c
comparison
equal deleted inserted replaced
17471:c7151df86441 17472:dfd87ef822aa
22 22
23 #ifdef MACOS_X 23 #ifdef MACOS_X
24 # include <time.h> /* for time_t */ 24 # include <time.h> /* for time_t */
25 #endif 25 #endif
26 26
27 static char *e_listarg = N_("E686: Argument of %s must be a List");
28 static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob"); 27 static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob");
29 static char *e_stringreq = N_("E928: String required"); 28 static char *e_stringreq = N_("E928: String required");
30 static char *e_invalwindow = N_("E957: Invalid window number");
31 29
32 #ifdef FEAT_FLOAT 30 #ifdef FEAT_FLOAT
33 static void f_abs(typval_T *argvars, typval_T *rettv); 31 static void f_abs(typval_T *argvars, typval_T *rettv);
34 static void f_acos(typval_T *argvars, typval_T *rettv); 32 static void f_acos(typval_T *argvars, typval_T *rettv);
35 #endif 33 #endif
162 static void f_getftime(typval_T *argvars, typval_T *rettv); 160 static void f_getftime(typval_T *argvars, typval_T *rettv);
163 static void f_getftype(typval_T *argvars, typval_T *rettv); 161 static void f_getftype(typval_T *argvars, typval_T *rettv);
164 static void f_getjumplist(typval_T *argvars, typval_T *rettv); 162 static void f_getjumplist(typval_T *argvars, typval_T *rettv);
165 static void f_getline(typval_T *argvars, typval_T *rettv); 163 static void f_getline(typval_T *argvars, typval_T *rettv);
166 static void f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED); 164 static void f_getloclist(typval_T *argvars UNUSED, typval_T *rettv UNUSED);
167 static void f_getmatches(typval_T *argvars, typval_T *rettv);
168 static void f_getpid(typval_T *argvars, typval_T *rettv); 165 static void f_getpid(typval_T *argvars, typval_T *rettv);
169 static void f_getcurpos(typval_T *argvars, typval_T *rettv); 166 static void f_getcurpos(typval_T *argvars, typval_T *rettv);
170 static void f_getpos(typval_T *argvars, typval_T *rettv); 167 static void f_getpos(typval_T *argvars, typval_T *rettv);
171 static void f_getqflist(typval_T *argvars, typval_T *rettv); 168 static void f_getqflist(typval_T *argvars, typval_T *rettv);
172 static void f_getreg(typval_T *argvars, typval_T *rettv); 169 static void f_getreg(typval_T *argvars, typval_T *rettv);
211 static void f_isinf(typval_T *argvars, typval_T *rettv); 208 static void f_isinf(typval_T *argvars, typval_T *rettv);
212 static void f_isnan(typval_T *argvars, typval_T *rettv); 209 static void f_isnan(typval_T *argvars, typval_T *rettv);
213 #endif 210 #endif
214 static void f_items(typval_T *argvars, typval_T *rettv); 211 static void f_items(typval_T *argvars, typval_T *rettv);
215 static void f_join(typval_T *argvars, typval_T *rettv); 212 static void f_join(typval_T *argvars, typval_T *rettv);
216 static void f_js_decode(typval_T *argvars, typval_T *rettv);
217 static void f_js_encode(typval_T *argvars, typval_T *rettv);
218 static void f_json_decode(typval_T *argvars, typval_T *rettv);
219 static void f_json_encode(typval_T *argvars, typval_T *rettv);
220 static void f_keys(typval_T *argvars, typval_T *rettv); 213 static void f_keys(typval_T *argvars, typval_T *rettv);
221 static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv); 214 static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv);
222 static void f_len(typval_T *argvars, typval_T *rettv); 215 static void f_len(typval_T *argvars, typval_T *rettv);
223 static void f_libcall(typval_T *argvars, typval_T *rettv); 216 static void f_libcall(typval_T *argvars, typval_T *rettv);
224 static void f_libcallnr(typval_T *argvars, typval_T *rettv); 217 static void f_libcallnr(typval_T *argvars, typval_T *rettv);
236 #endif 229 #endif
237 static void f_map(typval_T *argvars, typval_T *rettv); 230 static void f_map(typval_T *argvars, typval_T *rettv);
238 static void f_maparg(typval_T *argvars, typval_T *rettv); 231 static void f_maparg(typval_T *argvars, typval_T *rettv);
239 static void f_mapcheck(typval_T *argvars, typval_T *rettv); 232 static void f_mapcheck(typval_T *argvars, typval_T *rettv);
240 static void f_match(typval_T *argvars, typval_T *rettv); 233 static void f_match(typval_T *argvars, typval_T *rettv);
241 static void f_matchadd(typval_T *argvars, typval_T *rettv);
242 static void f_matchaddpos(typval_T *argvars, typval_T *rettv);
243 static void f_matcharg(typval_T *argvars, typval_T *rettv);
244 static void f_matchdelete(typval_T *argvars, typval_T *rettv);
245 static void f_matchend(typval_T *argvars, typval_T *rettv); 234 static void f_matchend(typval_T *argvars, typval_T *rettv);
246 static void f_matchlist(typval_T *argvars, typval_T *rettv); 235 static void f_matchlist(typval_T *argvars, typval_T *rettv);
247 static void f_matchstr(typval_T *argvars, typval_T *rettv); 236 static void f_matchstr(typval_T *argvars, typval_T *rettv);
248 static void f_matchstrpos(typval_T *argvars, typval_T *rettv); 237 static void f_matchstrpos(typval_T *argvars, typval_T *rettv);
249 static void f_max(typval_T *argvars, typval_T *rettv); 238 static void f_max(typval_T *argvars, typval_T *rettv);
2200 else 2189 else
2201 #endif 2190 #endif
2202 rettv->vval.v_number = -1; 2191 rettv->vval.v_number = -1;
2203 } 2192 }
2204 2193
2205 static win_T * 2194 win_T *
2206 get_optional_window(typval_T *argvars, int idx) 2195 get_optional_window(typval_T *argvars, int idx)
2207 { 2196 {
2208 win_T *win = curwin; 2197 win_T *win = curwin;
2209 2198
2210 if (argvars[idx].v_type != VAR_UNKNOWN) 2199 if (argvars[idx].v_type != VAR_UNKNOWN)
5283 get_qf_loc_list(FALSE, wp, &argvars[1], rettv); 5272 get_qf_loc_list(FALSE, wp, &argvars[1], rettv);
5284 #endif 5273 #endif
5285 } 5274 }
5286 5275
5287 /* 5276 /*
5288 * "getmatches()" function
5289 */
5290 static void
5291 f_getmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
5292 {
5293 #ifdef FEAT_SEARCH_EXTRA
5294 dict_T *dict;
5295 matchitem_T *cur;
5296 int i;
5297 win_T *win = get_optional_window(argvars, 0);
5298
5299 if (rettv_list_alloc(rettv) == FAIL || win == NULL)
5300 return;
5301
5302 cur = win->w_match_head;
5303 while (cur != NULL)
5304 {
5305 dict = dict_alloc();
5306 if (dict == NULL)
5307 return;
5308 if (cur->match.regprog == NULL)
5309 {
5310 /* match added with matchaddpos() */
5311 for (i = 0; i < MAXPOSMATCH; ++i)
5312 {
5313 llpos_T *llpos;
5314 char buf[30]; // use 30 to avoid compiler warning
5315 list_T *l;
5316
5317 llpos = &cur->pos.pos[i];
5318 if (llpos->lnum == 0)
5319 break;
5320 l = list_alloc();
5321 if (l == NULL)
5322 break;
5323 list_append_number(l, (varnumber_T)llpos->lnum);
5324 if (llpos->col > 0)
5325 {
5326 list_append_number(l, (varnumber_T)llpos->col);
5327 list_append_number(l, (varnumber_T)llpos->len);
5328 }
5329 sprintf(buf, "pos%d", i + 1);
5330 dict_add_list(dict, buf, l);
5331 }
5332 }
5333 else
5334 {
5335 dict_add_string(dict, "pattern", cur->pattern);
5336 }
5337 dict_add_string(dict, "group", syn_id2name(cur->hlg_id));
5338 dict_add_number(dict, "priority", (long)cur->priority);
5339 dict_add_number(dict, "id", (long)cur->id);
5340 # if defined(FEAT_CONCEAL)
5341 if (cur->conceal_char)
5342 {
5343 char_u buf[MB_MAXBYTES + 1];
5344
5345 buf[(*mb_char2bytes)((int)cur->conceal_char, buf)] = NUL;
5346 dict_add_string(dict, "conceal", (char_u *)&buf);
5347 }
5348 # endif
5349 list_append_dict(rettv->vval.v_list, dict);
5350 cur = cur->next;
5351 }
5352 #endif
5353 }
5354
5355 /*
5356 * "getpid()" function 5277 * "getpid()" function
5357 */ 5278 */
5358 static void 5279 static void
5359 f_getpid(typval_T *argvars UNUSED, typval_T *rettv) 5280 f_getpid(typval_T *argvars UNUSED, typval_T *rettv)
5360 { 5281 {
7380 ga_append(&ga, NUL); 7301 ga_append(&ga, NUL);
7381 rettv->vval.v_string = (char_u *)ga.ga_data; 7302 rettv->vval.v_string = (char_u *)ga.ga_data;
7382 } 7303 }
7383 else 7304 else
7384 rettv->vval.v_string = NULL; 7305 rettv->vval.v_string = NULL;
7385 }
7386
7387 /*
7388 * "js_decode()" function
7389 */
7390 static void
7391 f_js_decode(typval_T *argvars, typval_T *rettv)
7392 {
7393 js_read_T reader;
7394
7395 reader.js_buf = tv_get_string(&argvars[0]);
7396 reader.js_fill = NULL;
7397 reader.js_used = 0;
7398 if (json_decode_all(&reader, rettv, JSON_JS) != OK)
7399 emsg(_(e_invarg));
7400 }
7401
7402 /*
7403 * "js_encode()" function
7404 */
7405 static void
7406 f_js_encode(typval_T *argvars, typval_T *rettv)
7407 {
7408 rettv->v_type = VAR_STRING;
7409 rettv->vval.v_string = json_encode(&argvars[0], JSON_JS);
7410 }
7411
7412 /*
7413 * "json_decode()" function
7414 */
7415 static void
7416 f_json_decode(typval_T *argvars, typval_T *rettv)
7417 {
7418 js_read_T reader;
7419
7420 reader.js_buf = tv_get_string(&argvars[0]);
7421 reader.js_fill = NULL;
7422 reader.js_used = 0;
7423 json_decode_all(&reader, rettv, 0);
7424 }
7425
7426 /*
7427 * "json_encode()" function
7428 */
7429 static void
7430 f_json_encode(typval_T *argvars, typval_T *rettv)
7431 {
7432 rettv->v_type = VAR_STRING;
7433 rettv->vval.v_string = json_encode(&argvars[0], 0);
7434 } 7306 }
7435 7307
7436 /* 7308 /*
7437 * "keys()" function 7309 * "keys()" function
7438 */ 7310 */
8069 f_match(typval_T *argvars, typval_T *rettv) 7941 f_match(typval_T *argvars, typval_T *rettv)
8070 { 7942 {
8071 find_some_match(argvars, rettv, MATCH_MATCH); 7943 find_some_match(argvars, rettv, MATCH_MATCH);
8072 } 7944 }
8073 7945
8074 #ifdef FEAT_SEARCH_EXTRA
8075 static int
8076 matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win)
8077 {
8078 dictitem_T *di;
8079
8080 if (tv->v_type != VAR_DICT)
8081 {
8082 emsg(_(e_dictreq));
8083 return FAIL;
8084 }
8085
8086 if (dict_find(tv->vval.v_dict, (char_u *)"conceal", -1) != NULL)
8087 *conceal_char = dict_get_string(tv->vval.v_dict,
8088 (char_u *)"conceal", FALSE);
8089
8090 if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL)
8091 {
8092 *win = find_win_by_nr_or_id(&di->di_tv);
8093 if (*win == NULL)
8094 {
8095 emsg(_(e_invalwindow));
8096 return FAIL;
8097 }
8098 }
8099
8100 return OK;
8101 }
8102 #endif
8103
8104 /*
8105 * "matchadd()" function
8106 */
8107 static void
8108 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
8109 {
8110 #ifdef FEAT_SEARCH_EXTRA
8111 char_u buf[NUMBUFLEN];
8112 char_u *grp = tv_get_string_buf_chk(&argvars[0], buf); /* group */
8113 char_u *pat = tv_get_string_buf_chk(&argvars[1], buf); /* pattern */
8114 int prio = 10; /* default priority */
8115 int id = -1;
8116 int error = FALSE;
8117 char_u *conceal_char = NULL;
8118 win_T *win = curwin;
8119
8120 rettv->vval.v_number = -1;
8121
8122 if (grp == NULL || pat == NULL)
8123 return;
8124 if (argvars[2].v_type != VAR_UNKNOWN)
8125 {
8126 prio = (int)tv_get_number_chk(&argvars[2], &error);
8127 if (argvars[3].v_type != VAR_UNKNOWN)
8128 {
8129 id = (int)tv_get_number_chk(&argvars[3], &error);
8130 if (argvars[4].v_type != VAR_UNKNOWN
8131 && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
8132 return;
8133 }
8134 }
8135 if (error == TRUE)
8136 return;
8137 if (id >= 1 && id <= 3)
8138 {
8139 semsg(_("E798: ID is reserved for \":match\": %d"), id);
8140 return;
8141 }
8142
8143 rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL,
8144 conceal_char);
8145 #endif
8146 }
8147
8148 /*
8149 * "matchaddpos()" function
8150 */
8151 static void
8152 f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
8153 {
8154 #ifdef FEAT_SEARCH_EXTRA
8155 char_u buf[NUMBUFLEN];
8156 char_u *group;
8157 int prio = 10;
8158 int id = -1;
8159 int error = FALSE;
8160 list_T *l;
8161 char_u *conceal_char = NULL;
8162 win_T *win = curwin;
8163
8164 rettv->vval.v_number = -1;
8165
8166 group = tv_get_string_buf_chk(&argvars[0], buf);
8167 if (group == NULL)
8168 return;
8169
8170 if (argvars[1].v_type != VAR_LIST)
8171 {
8172 semsg(_(e_listarg), "matchaddpos()");
8173 return;
8174 }
8175 l = argvars[1].vval.v_list;
8176 if (l == NULL)
8177 return;
8178
8179 if (argvars[2].v_type != VAR_UNKNOWN)
8180 {
8181 prio = (int)tv_get_number_chk(&argvars[2], &error);
8182 if (argvars[3].v_type != VAR_UNKNOWN)
8183 {
8184 id = (int)tv_get_number_chk(&argvars[3], &error);
8185
8186 if (argvars[4].v_type != VAR_UNKNOWN
8187 && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
8188 return;
8189 }
8190 }
8191 if (error == TRUE)
8192 return;
8193
8194 /* id == 3 is ok because matchaddpos() is supposed to substitute :3match */
8195 if (id == 1 || id == 2)
8196 {
8197 semsg(_("E798: ID is reserved for \":match\": %d"), id);
8198 return;
8199 }
8200
8201 rettv->vval.v_number = match_add(win, group, NULL, prio, id, l,
8202 conceal_char);
8203 #endif
8204 }
8205
8206 /*
8207 * "matcharg()" function
8208 */
8209 static void
8210 f_matcharg(typval_T *argvars UNUSED, typval_T *rettv)
8211 {
8212 if (rettv_list_alloc(rettv) == OK)
8213 {
8214 #ifdef FEAT_SEARCH_EXTRA
8215 int id = (int)tv_get_number(&argvars[0]);
8216 matchitem_T *m;
8217
8218 if (id >= 1 && id <= 3)
8219 {
8220 if ((m = (matchitem_T *)get_match(curwin, id)) != NULL)
8221 {
8222 list_append_string(rettv->vval.v_list,
8223 syn_id2name(m->hlg_id), -1);
8224 list_append_string(rettv->vval.v_list, m->pattern, -1);
8225 }
8226 else
8227 {
8228 list_append_string(rettv->vval.v_list, NULL, -1);
8229 list_append_string(rettv->vval.v_list, NULL, -1);
8230 }
8231 }
8232 #endif
8233 }
8234 }
8235
8236 /*
8237 * "matchdelete()" function
8238 */
8239 static void
8240 f_matchdelete(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
8241 {
8242 #ifdef FEAT_SEARCH_EXTRA
8243 win_T *win = get_optional_window(argvars, 1);
8244
8245 if (win == NULL)
8246 rettv->vval.v_number = -1;
8247 else
8248 rettv->vval.v_number = match_delete(win,
8249 (int)tv_get_number(&argvars[0]), TRUE);
8250 #endif
8251 }
8252
8253 /* 7946 /*
8254 * "matchend()" function 7947 * "matchend()" function
8255 */ 7948 */
8256 static void 7949 static void
8257 f_matchend(typval_T *argvars, typval_T *rettv) 7950 f_matchend(typval_T *argvars, typval_T *rettv)