comparison src/evalfunc.c @ 20731:ab27db64f1fb v8.2.0918

patch 8.2.0918: duplicate code for evaluating expression argument Commit: https://github.com/vim/vim/commit/a9c010494767e43a51c443cac35ebc80d0831d0b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 7 14:50:50 2020 +0200 patch 8.2.0918: duplicate code for evaluating expression argument Problem: Duplicate code for evaluating expression argument. Solution: Merge the code and make the use more flexible.
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 Jun 2020 15:00:04 +0200
parents f4455c71a8aa
children a672feb8fc4f
comparison
equal deleted inserted replaced
20730:6f44f49988ee 20731:ab27db64f1fb
6397 long time_limit = 0; 6397 long time_limit = 0;
6398 #endif 6398 #endif
6399 int options = SEARCH_KEEP; 6399 int options = SEARCH_KEEP;
6400 int subpatnum; 6400 int subpatnum;
6401 searchit_arg_T sia; 6401 searchit_arg_T sia;
6402 evalarg_T skip; 6402 int use_skip = FALSE;
6403 pos_T firstpos; 6403 pos_T firstpos;
6404
6405 CLEAR_FIELD(skip);
6406 6404
6407 pat = tv_get_string(&argvars[0]); 6405 pat = tv_get_string(&argvars[0]);
6408 dir = get_search_arg(&argvars[1], flagsp); // may set p_ws 6406 dir = get_search_arg(&argvars[1], flagsp); // may set p_ws
6409 if (dir == 0) 6407 if (dir == 0)
6410 goto theend; 6408 goto theend;
6427 #ifdef FEAT_RELTIME 6425 #ifdef FEAT_RELTIME
6428 time_limit = (long)tv_get_number_chk(&argvars[3], NULL); 6426 time_limit = (long)tv_get_number_chk(&argvars[3], NULL);
6429 if (time_limit < 0) 6427 if (time_limit < 0)
6430 goto theend; 6428 goto theend;
6431 #endif 6429 #endif
6432 if (argvars[4].v_type != VAR_UNKNOWN 6430 use_skip = eval_expr_valid_arg(&argvars[4]);
6433 && evalarg_get(&argvars[4], &skip) == FAIL)
6434 goto theend;
6435 } 6431 }
6436 } 6432 }
6437 6433
6438 #ifdef FEAT_RELTIME 6434 #ifdef FEAT_RELTIME
6439 // Set the time limit, if there is one. 6435 // Set the time limit, if there is one.
6469 // finding the first match again means there is no match where {skip} 6465 // finding the first match again means there is no match where {skip}
6470 // evaluates to zero. 6466 // evaluates to zero.
6471 if (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos)) 6467 if (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos))
6472 subpatnum = FAIL; 6468 subpatnum = FAIL;
6473 6469
6474 if (subpatnum == FAIL || !evalarg_valid(&skip)) 6470 if (subpatnum == FAIL || !use_skip)
6475 // didn't find it or no skip argument 6471 // didn't find it or no skip argument
6476 break; 6472 break;
6477 firstpos = pos; 6473 firstpos = pos;
6478 6474
6479 // If the skip pattern matches, ignore this match. 6475 // If the skip expression matches, ignore this match.
6480 { 6476 {
6481 int do_skip; 6477 int do_skip;
6482 int err; 6478 int err;
6483 pos_T save_pos = curwin->w_cursor; 6479 pos_T save_pos = curwin->w_cursor;
6484 6480
6485 curwin->w_cursor = pos; 6481 curwin->w_cursor = pos;
6486 do_skip = evalarg_call_bool(&skip, &err); 6482 err = FALSE;
6483 do_skip = eval_expr_to_bool(&argvars[4], &err);
6487 curwin->w_cursor = save_pos; 6484 curwin->w_cursor = save_pos;
6488 if (err) 6485 if (err)
6489 { 6486 {
6490 // Evaluating {skip} caused an error, break here. 6487 // Evaluating {skip} caused an error, break here.
6491 subpatnum = FAIL; 6488 subpatnum = FAIL;
6521 curwin->w_cursor = save_cursor; 6518 curwin->w_cursor = save_cursor;
6522 else 6519 else
6523 curwin->w_set_curswant = TRUE; 6520 curwin->w_set_curswant = TRUE;
6524 theend: 6521 theend:
6525 p_ws = save_p_ws; 6522 p_ws = save_p_ws;
6526 evalarg_clean(&skip);
6527 6523
6528 return retval; 6524 return retval;
6529 } 6525 }
6530 6526
6531 #ifdef FEAT_FLOAT 6527 #ifdef FEAT_FLOAT
6789 if (argvars[3].v_type == VAR_UNKNOWN 6785 if (argvars[3].v_type == VAR_UNKNOWN
6790 || argvars[4].v_type == VAR_UNKNOWN) 6786 || argvars[4].v_type == VAR_UNKNOWN)
6791 skip = NULL; 6787 skip = NULL;
6792 else 6788 else
6793 { 6789 {
6790 // Type is checked later.
6794 skip = &argvars[4]; 6791 skip = &argvars[4];
6795 if (skip->v_type != VAR_FUNC && skip->v_type != VAR_PARTIAL 6792
6796 && skip->v_type != VAR_STRING)
6797 {
6798 // Type error
6799 semsg(_(e_invarg2), tv_get_string(&argvars[4]));
6800 goto theend;
6801 }
6802 if (argvars[5].v_type != VAR_UNKNOWN) 6793 if (argvars[5].v_type != VAR_UNKNOWN)
6803 { 6794 {
6804 lnum_stop = (long)tv_get_number_chk(&argvars[5], NULL); 6795 lnum_stop = (long)tv_get_number_chk(&argvars[5], NULL);
6805 if (lnum_stop < 0) 6796 if (lnum_stop < 0)
6806 { 6797 {
6920 spat, epat, mpat); 6911 spat, epat, mpat);
6921 if (flags & SP_START) 6912 if (flags & SP_START)
6922 options |= SEARCH_START; 6913 options |= SEARCH_START;
6923 6914
6924 if (skip != NULL) 6915 if (skip != NULL)
6925 { 6916 use_skip = eval_expr_valid_arg(skip);
6926 // Empty string means to not use the skip expression.
6927 if (skip->v_type == VAR_STRING || skip->v_type == VAR_FUNC)
6928 use_skip = skip->vval.v_string != NULL
6929 && *skip->vval.v_string != NUL;
6930 }
6931 6917
6932 save_cursor = curwin->w_cursor; 6918 save_cursor = curwin->w_cursor;
6933 pos = curwin->w_cursor; 6919 pos = curwin->w_cursor;
6934 CLEAR_POS(&firstpos); 6920 CLEAR_POS(&firstpos);
6935 CLEAR_POS(&foundpos); 6921 CLEAR_POS(&foundpos);