comparison src/eval.c @ 667:9090f866cd57 v7.0197

updated for version 7.0197
author vimboss
date Tue, 14 Feb 2006 22:29:30 +0000
parents 0137e7c3d31b
children 83a006f81bac
comparison
equal deleted inserted replaced
666:0137e7c3d31b 667:9090f866cd57
571 static void f_mode __ARGS((typval_T *argvars, typval_T *rettv)); 571 static void f_mode __ARGS((typval_T *argvars, typval_T *rettv));
572 static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv)); 572 static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv));
573 static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv)); 573 static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv));
574 static void f_prevnonblank __ARGS((typval_T *argvars, typval_T *rettv)); 574 static void f_prevnonblank __ARGS((typval_T *argvars, typval_T *rettv));
575 static void f_printf __ARGS((typval_T *argvars, typval_T *rettv)); 575 static void f_printf __ARGS((typval_T *argvars, typval_T *rettv));
576 static void f_pumvisible __ARGS((typval_T *argvars, typval_T *rettv));
576 static void f_range __ARGS((typval_T *argvars, typval_T *rettv)); 577 static void f_range __ARGS((typval_T *argvars, typval_T *rettv));
577 static void f_readfile __ARGS((typval_T *argvars, typval_T *rettv)); 578 static void f_readfile __ARGS((typval_T *argvars, typval_T *rettv));
578 static void f_remote_expr __ARGS((typval_T *argvars, typval_T *rettv)); 579 static void f_remote_expr __ARGS((typval_T *argvars, typval_T *rettv));
579 static void f_remote_foreground __ARGS((typval_T *argvars, typval_T *rettv)); 580 static void f_remote_foreground __ARGS((typval_T *argvars, typval_T *rettv));
580 static void f_remote_peek __ARGS((typval_T *argvars, typval_T *rettv)); 581 static void f_remote_peek __ARGS((typval_T *argvars, typval_T *rettv));
586 static void f_resolve __ARGS((typval_T *argvars, typval_T *rettv)); 587 static void f_resolve __ARGS((typval_T *argvars, typval_T *rettv));
587 static void f_reverse __ARGS((typval_T *argvars, typval_T *rettv)); 588 static void f_reverse __ARGS((typval_T *argvars, typval_T *rettv));
588 static void f_search __ARGS((typval_T *argvars, typval_T *rettv)); 589 static void f_search __ARGS((typval_T *argvars, typval_T *rettv));
589 static void f_searchdecl __ARGS((typval_T *argvars, typval_T *rettv)); 590 static void f_searchdecl __ARGS((typval_T *argvars, typval_T *rettv));
590 static void f_searchpair __ARGS((typval_T *argvars, typval_T *rettv)); 591 static void f_searchpair __ARGS((typval_T *argvars, typval_T *rettv));
592 static void f_searchpairpos __ARGS((typval_T *argvars, typval_T *rettv));
593 static void f_searchpos __ARGS((typval_T *argvars, typval_T *rettv));
591 static void f_server2client __ARGS((typval_T *argvars, typval_T *rettv)); 594 static void f_server2client __ARGS((typval_T *argvars, typval_T *rettv));
592 static void f_serverlist __ARGS((typval_T *argvars, typval_T *rettv)); 595 static void f_serverlist __ARGS((typval_T *argvars, typval_T *rettv));
593 static void f_setbufvar __ARGS((typval_T *argvars, typval_T *rettv)); 596 static void f_setbufvar __ARGS((typval_T *argvars, typval_T *rettv));
594 static void f_setcmdpos __ARGS((typval_T *argvars, typval_T *rettv)); 597 static void f_setcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
595 static void f_setline __ARGS((typval_T *argvars, typval_T *rettv)); 598 static void f_setline __ARGS((typval_T *argvars, typval_T *rettv));
702 static void func_unref __ARGS((char_u *name)); 705 static void func_unref __ARGS((char_u *name));
703 static void func_ref __ARGS((char_u *name)); 706 static void func_ref __ARGS((char_u *name));
704 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict)); 707 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
705 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr)); 708 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
706 static win_T *find_win_by_nr __ARGS((typval_T *vp)); 709 static win_T *find_win_by_nr __ARGS((typval_T *vp));
710 static int searchpair_cmn __ARGS((typval_T *argvars, pos_T *match_pos));
711 static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos));
707 712
708 /* Character used as separated in autoload function/variable names. */ 713 /* Character used as separated in autoload function/variable names. */
709 #define AUTOLOAD_CHAR '#' 714 #define AUTOLOAD_CHAR '#'
710 715
711 /* 716 /*
6928 {"mode", 0, 0, f_mode}, 6933 {"mode", 0, 0, f_mode},
6929 {"nextnonblank", 1, 1, f_nextnonblank}, 6934 {"nextnonblank", 1, 1, f_nextnonblank},
6930 {"nr2char", 1, 1, f_nr2char}, 6935 {"nr2char", 1, 1, f_nr2char},
6931 {"prevnonblank", 1, 1, f_prevnonblank}, 6936 {"prevnonblank", 1, 1, f_prevnonblank},
6932 {"printf", 2, 19, f_printf}, 6937 {"printf", 2, 19, f_printf},
6938 {"pumvisible", 0, 0, f_pumvisible},
6933 {"range", 1, 3, f_range}, 6939 {"range", 1, 3, f_range},
6934 {"readfile", 1, 3, f_readfile}, 6940 {"readfile", 1, 3, f_readfile},
6935 {"remote_expr", 2, 3, f_remote_expr}, 6941 {"remote_expr", 2, 3, f_remote_expr},
6936 {"remote_foreground", 1, 1, f_remote_foreground}, 6942 {"remote_foreground", 1, 1, f_remote_foreground},
6937 {"remote_peek", 1, 2, f_remote_peek}, 6943 {"remote_peek", 1, 2, f_remote_peek},
6943 {"resolve", 1, 1, f_resolve}, 6949 {"resolve", 1, 1, f_resolve},
6944 {"reverse", 1, 1, f_reverse}, 6950 {"reverse", 1, 1, f_reverse},
6945 {"search", 1, 2, f_search}, 6951 {"search", 1, 2, f_search},
6946 {"searchdecl", 1, 3, f_searchdecl}, 6952 {"searchdecl", 1, 3, f_searchdecl},
6947 {"searchpair", 3, 5, f_searchpair}, 6953 {"searchpair", 3, 5, f_searchpair},
6954 {"searchpairpos", 3, 5, f_searchpairpos},
6955 {"searchpos", 1, 2, f_searchpos},
6948 {"server2client", 2, 2, f_server2client}, 6956 {"server2client", 2, 2, f_server2client},
6949 {"serverlist", 0, 0, f_serverlist}, 6957 {"serverlist", 0, 0, f_serverlist},
6950 {"setbufvar", 3, 3, f_setbufvar}, 6958 {"setbufvar", 3, 3, f_setbufvar},
6951 {"setcmdpos", 1, 1, f_setcmdpos}, 6959 {"setcmdpos", 1, 1, f_setcmdpos},
6952 {"setline", 2, 2, f_setline}, 6960 {"setline", 2, 2, f_setline},
12212 } 12220 }
12213 #endif 12221 #endif
12214 } 12222 }
12215 12223
12216 /* 12224 /*
12225 * "pumvisible()" function
12226 */
12227 /*ARGSUSED*/
12228 static void
12229 f_pumvisible(argvars, rettv)
12230 typval_T *argvars;
12231 typval_T *rettv;
12232 {
12233 rettv->vval.v_number = 0;
12234 #ifdef FEAT_INS_EXPAND
12235 if (pum_visible())
12236 rettv->vval.v_number = 1;
12237 #endif
12238 }
12239
12240 /*
12217 * "range()" function 12241 * "range()" function
12218 */ 12242 */
12219 static void 12243 static void
12220 f_range(argvars, rettv) 12244 f_range(argvars, rettv)
12221 typval_T *argvars; 12245 typval_T *argvars;
13133 } 13157 }
13134 return dir; 13158 return dir;
13135 } 13159 }
13136 13160
13137 /* 13161 /*
13138 * "search()" function 13162 * Shared by search() and searchpos() functions
13139 */ 13163 */
13140 static void 13164 static int
13141 f_search(argvars, rettv) 13165 search_cmn(argvars, match_pos)
13142 typval_T *argvars; 13166 typval_T *argvars;
13143 typval_T *rettv; 13167 pos_T *match_pos;
13144 { 13168 {
13145 char_u *pat; 13169 char_u *pat;
13146 pos_T pos; 13170 pos_T pos;
13147 pos_T save_cursor; 13171 pos_T save_cursor;
13148 int save_p_ws = p_ws; 13172 int save_p_ws = p_ws;
13149 int dir; 13173 int dir;
13150 int flags = 0; 13174 int flags = 0;
13151 13175 int retval = 0; /* default: FAIL */
13152 rettv->vval.v_number = 0; /* default: FAIL */
13153 13176
13154 pat = get_tv_string(&argvars[0]); 13177 pat = get_tv_string(&argvars[0]);
13155 dir = get_search_arg(&argvars[1], &flags); /* may set p_ws */ 13178 dir = get_search_arg(&argvars[1], &flags); /* may set p_ws */
13156 if (dir == 0) 13179 if (dir == 0)
13157 goto theend; 13180 goto theend;
13170 13193
13171 pos = save_cursor = curwin->w_cursor; 13194 pos = save_cursor = curwin->w_cursor;
13172 if (searchit(curwin, curbuf, &pos, dir, pat, 1L, 13195 if (searchit(curwin, curbuf, &pos, dir, pat, 1L,
13173 SEARCH_KEEP, RE_SEARCH) != FAIL) 13196 SEARCH_KEEP, RE_SEARCH) != FAIL)
13174 { 13197 {
13175 rettv->vval.v_number = pos.lnum; 13198 retval = pos.lnum;
13176 if (flags & SP_SETPCMARK) 13199 if (flags & SP_SETPCMARK)
13177 setpcmark(); 13200 setpcmark();
13178 curwin->w_cursor = pos; 13201 curwin->w_cursor = pos;
13202 if (match_pos != NULL)
13203 {
13204 /* Store the match cursor position */
13205 match_pos->lnum = pos.lnum;
13206 match_pos->col = pos.col + 1;
13207 }
13179 /* "/$" will put the cursor after the end of the line, may need to 13208 /* "/$" will put the cursor after the end of the line, may need to
13180 * correct that here */ 13209 * correct that here */
13181 check_cursor(); 13210 check_cursor();
13182 } 13211 }
13183 13212
13184 /* If 'n' flag is used: restore cursor position. */ 13213 /* If 'n' flag is used: restore cursor position. */
13185 if (flags & SP_NOMOVE) 13214 if (flags & SP_NOMOVE)
13186 curwin->w_cursor = save_cursor; 13215 curwin->w_cursor = save_cursor;
13187 theend: 13216 theend:
13188 p_ws = save_p_ws; 13217 p_ws = save_p_ws;
13218
13219 return retval;
13220 }
13221
13222 /*
13223 * "search()" function
13224 */
13225 static void
13226 f_search(argvars, rettv)
13227 typval_T *argvars;
13228 typval_T *rettv;
13229 {
13230 rettv->vval.v_number = search_cmn(argvars, NULL);
13189 } 13231 }
13190 13232
13191 /* 13233 /*
13192 * "searchdecl()" function 13234 * "searchdecl()" function
13193 */ 13235 */
13214 rettv->vval.v_number = find_decl(name, (int)STRLEN(name), 13256 rettv->vval.v_number = find_decl(name, (int)STRLEN(name),
13215 locally, thisblock, SEARCH_KEEP) == FAIL; 13257 locally, thisblock, SEARCH_KEEP) == FAIL;
13216 } 13258 }
13217 13259
13218 /* 13260 /*
13219 * "searchpair()" function 13261 * Used by searchpair() and searchpairpos()
13220 */ 13262 */
13221 static void 13263 static int
13222 f_searchpair(argvars, rettv) 13264 searchpair_cmn(argvars, match_pos)
13223 typval_T *argvars; 13265 typval_T *argvars;
13224 typval_T *rettv; 13266 pos_T *match_pos;
13225 { 13267 {
13226 char_u *spat, *mpat, *epat; 13268 char_u *spat, *mpat, *epat;
13227 char_u *skip; 13269 char_u *skip;
13228 int save_p_ws = p_ws; 13270 int save_p_ws = p_ws;
13229 int dir; 13271 int dir;
13230 int flags = 0; 13272 int flags = 0;
13231 char_u nbuf1[NUMBUFLEN]; 13273 char_u nbuf1[NUMBUFLEN];
13232 char_u nbuf2[NUMBUFLEN]; 13274 char_u nbuf2[NUMBUFLEN];
13233 char_u nbuf3[NUMBUFLEN]; 13275 char_u nbuf3[NUMBUFLEN];
13234 13276 int retval = 0; /* default: FAIL */
13235 rettv->vval.v_number = 0; /* default: FAIL */
13236 13277
13237 /* Get the three pattern arguments: start, middle, end. */ 13278 /* Get the three pattern arguments: start, middle, end. */
13238 spat = get_tv_string_chk(&argvars[0]); 13279 spat = get_tv_string_chk(&argvars[0]);
13239 mpat = get_tv_string_buf_chk(&argvars[1], nbuf1); 13280 mpat = get_tv_string_buf_chk(&argvars[1], nbuf1);
13240 epat = get_tv_string_buf_chk(&argvars[2], nbuf2); 13281 epat = get_tv_string_buf_chk(&argvars[2], nbuf2);
13252 { 13293 {
13253 EMSG2(_(e_invarg2), get_tv_string(&argvars[1])); 13294 EMSG2(_(e_invarg2), get_tv_string(&argvars[1]));
13254 goto theend; 13295 goto theend;
13255 } 13296 }
13256 13297
13257 /* Optional fifth argument: skip expresion */ 13298 /* Optional fifth argument: skip expression */
13258 if (argvars[3].v_type == VAR_UNKNOWN 13299 if (argvars[3].v_type == VAR_UNKNOWN
13259 || argvars[4].v_type == VAR_UNKNOWN) 13300 || argvars[4].v_type == VAR_UNKNOWN)
13260 skip = (char_u *)""; 13301 skip = (char_u *)"";
13261 else 13302 else
13262 skip = get_tv_string_buf_chk(&argvars[4], nbuf3); 13303 skip = get_tv_string_buf_chk(&argvars[4], nbuf3);
13263 if (skip == NULL) 13304 if (skip == NULL)
13264 goto theend; /* type error */ 13305 goto theend; /* type error */
13265 13306
13266 rettv->vval.v_number = do_searchpair(spat, mpat, epat, dir, skip, flags); 13307 retval = do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos);
13267 13308
13268 theend: 13309 theend:
13269 p_ws = save_p_ws; 13310 p_ws = save_p_ws;
13311
13312 return retval;
13313 }
13314
13315 /*
13316 * "searchpair()" function
13317 */
13318 static void
13319 f_searchpair(argvars, rettv)
13320 typval_T *argvars;
13321 typval_T *rettv;
13322 {
13323 rettv->vval.v_number = searchpair_cmn(argvars, NULL);
13324 }
13325
13326 /*
13327 * "searchpairpos()" function
13328 */
13329 static void
13330 f_searchpairpos(argvars, rettv)
13331 typval_T *argvars;
13332 typval_T *rettv;
13333 {
13334 list_T *l;
13335 pos_T match_pos;
13336 int lnum = 0;
13337 int col = 0;
13338
13339 rettv->vval.v_number = 0;
13340
13341 l = list_alloc();
13342 if (l == NULL)
13343 return;
13344 rettv->v_type = VAR_LIST;
13345 rettv->vval.v_list = l;
13346 ++l->lv_refcount;
13347
13348 if (searchpair_cmn(argvars, &match_pos) > 0)
13349 {
13350 lnum = match_pos.lnum;
13351 col = match_pos.col;
13352 }
13353
13354 list_append_number(l, (varnumber_T)lnum);
13355 list_append_number(l, (varnumber_T)col);
13270 } 13356 }
13271 13357
13272 /* 13358 /*
13273 * Search for a start/middle/end thing. 13359 * Search for a start/middle/end thing.
13274 * Used by searchpair(), see its documentation for the details. 13360 * Used by searchpair(), see its documentation for the details.
13275 * Returns 0 or -1 for no match, 13361 * Returns 0 or -1 for no match,
13276 */ 13362 */
13277 long 13363 long
13278 do_searchpair(spat, mpat, epat, dir, skip, flags) 13364 do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos)
13279 char_u *spat; /* start pattern */ 13365 char_u *spat; /* start pattern */
13280 char_u *mpat; /* middle pattern */ 13366 char_u *mpat; /* middle pattern */
13281 char_u *epat; /* end pattern */ 13367 char_u *epat; /* end pattern */
13282 int dir; /* BACKWARD or FORWARD */ 13368 int dir; /* BACKWARD or FORWARD */
13283 char_u *skip; /* skip expression */ 13369 char_u *skip; /* skip expression */
13284 int flags; /* SP_RETCOUNT, SP_REPEAT, SP_NOMOVE */ 13370 int flags; /* SP_RETCOUNT, SP_REPEAT, SP_NOMOVE */
13371 pos_T *match_pos;
13285 { 13372 {
13286 char_u *save_cpo; 13373 char_u *save_cpo;
13287 char_u *pat, *pat2 = NULL, *pat3 = NULL; 13374 char_u *pat, *pat2 = NULL, *pat3 = NULL;
13288 long retval = 0; 13375 long retval = 0;
13289 pos_T pos; 13376 pos_T pos;
13387 break; 13474 break;
13388 nest = 1; /* search for next unmatched */ 13475 nest = 1; /* search for next unmatched */
13389 } 13476 }
13390 } 13477 }
13391 13478
13479 if (match_pos != NULL)
13480 {
13481 /* Store the match cursor position */
13482 match_pos->lnum = curwin->w_cursor.lnum;
13483 match_pos->col = curwin->w_cursor.col + 1;
13484 }
13485
13392 /* If 'n' flag is used or search failed: restore cursor position. */ 13486 /* If 'n' flag is used or search failed: restore cursor position. */
13393 if ((flags & SP_NOMOVE) || retval == 0) 13487 if ((flags & SP_NOMOVE) || retval == 0)
13394 curwin->w_cursor = save_cursor; 13488 curwin->w_cursor = save_cursor;
13395 13489
13396 theend: 13490 theend:
13398 vim_free(pat3); 13492 vim_free(pat3);
13399 p_cpo = save_cpo; 13493 p_cpo = save_cpo;
13400 13494
13401 return retval; 13495 return retval;
13402 } 13496 }
13497
13498 /*
13499 * "searchpos()" function
13500 */
13501 static void
13502 f_searchpos(argvars, rettv)
13503 typval_T *argvars;
13504 typval_T *rettv;
13505 {
13506 list_T *l;
13507 pos_T match_pos;
13508 int lnum = 0;
13509 int col = 0;
13510
13511 rettv->vval.v_number = 0;
13512
13513 l = list_alloc();
13514 if (l == NULL)
13515 return;
13516 rettv->v_type = VAR_LIST;
13517 rettv->vval.v_list = l;
13518 ++l->lv_refcount;
13519
13520 if (search_cmn(argvars, &match_pos) > 0)
13521 {
13522 lnum = match_pos.lnum;
13523 col = match_pos.col;
13524 }
13525
13526 list_append_number(l, (varnumber_T)lnum);
13527 list_append_number(l, (varnumber_T)col);
13528
13529 }
13530
13403 13531
13404 /*ARGSUSED*/ 13532 /*ARGSUSED*/
13405 static void 13533 static void
13406 f_server2client(argvars, rettv) 13534 f_server2client(argvars, rettv)
13407 typval_T *argvars; 13535 typval_T *argvars;
14025 f_spellbadword(argvars, rettv) 14153 f_spellbadword(argvars, rettv)
14026 typval_T *argvars; 14154 typval_T *argvars;
14027 typval_T *rettv; 14155 typval_T *rettv;
14028 { 14156 {
14029 char_u *word = (char_u *)""; 14157 char_u *word = (char_u *)"";
14030 #ifdef FEAT_SYN_HL 14158 hlf_T attr = HLF_COUNT;
14031 int len = 0; 14159 int len = 0;
14032 hlf_T attr = HLF_COUNT;
14033 list_T *l; 14160 list_T *l;
14034 #endif
14035 14161
14036 l = list_alloc(); 14162 l = list_alloc();
14037 if (l == NULL) 14163 if (l == NULL)
14038 return; 14164 return;
14039 rettv->v_type = VAR_LIST; 14165 rettv->v_type = VAR_LIST;